Skip to content

Commit

Permalink
feat: change building system to rollup, compiling linter into a binary
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
- Renamed `bin/dclint.js` to `bin/dclint.cjs`.
- Docker entrypoint changed to use the compiled binary over the Node.js implementation.
  • Loading branch information
zavoloklom committed Nov 14, 2024
1 parent cafb4d0 commit c563a93
Show file tree
Hide file tree
Showing 75 changed files with 4,164 additions and 879 deletions.
49 changes: 49 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# OS
.DS_Store

# Git
.git/
.gitignore

# Github
.github/

# Docker
Dockerfile

# Documentation
/documentation
/docs

# Dependencies
/node_modules

# Compiled output and runtime
/dist
/bin
/pkg
/.tsimp
/sea-prep.blob
/dclint

# Tests
/coverage

# Other
Makefile
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ module.exports = {
'unicorn/switch-case-braces': [2, 'avoid'],
'unicorn/import-style': [2, {"styles": {"node:path": {"named": true, "default": false}}}]
},
'ignorePatterns': ['node_modules', 'dist', '.tsimp', 'coverage', 'bin'],
'ignorePatterns': ['node_modules', 'dist', '.tsimp', 'coverage', 'bin', 'rollup*config*js'],
};
27 changes: 27 additions & 0 deletions .github/actions/install-dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "Install Node.js dependencies with Cache"
description: "Sets up Node.js, caches dependencies, and installs them"
inputs:
node-version:
description: "Node.js version"
required: true
default: "20.18.0"

runs:
using: "composite"
steps:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}

- name: Cache Node.js modules
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
shell: bash
199 changes: 158 additions & 41 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,23 @@ on:
push:
branches:
- main
- beta
pull_request:
branches:
- '**'

jobs:
build:
tests:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v3
- name: Set up Node.js with Cache and Install
uses: ./.github/actions/install-dependencies
with:
node-version: '20.17.0'

- name: Install dependencies
run: npm ci

- name: Build the project
run: npm run build
node-version: '20.18.0'

- name: Run linter
run: npm run lint
Expand All @@ -39,35 +34,146 @@ jobs:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
run: wget -qO - https://coverage.codacy.com/get.sh | bash -s -- report -r ./coverage/cobertura-coverage.xml

- name: Build the project
run: npm run build:cli

- name: Upload tests artifacts
uses: actions/upload-artifact@v4
with:
name: tests-artifacts
path: |
./dist
./bin
retention-days: 1

debug:
runs-on: ubuntu-latest
needs: tests
if: github.event_name == 'pull_request' || github.ref != 'refs/heads/main'
strategy:
matrix:
node-version: [18, 20, 22, 23]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: tests-artifacts
path: ./

- name: Set up Node.js with Cache and Install
uses: ./.github/actions/install-dependencies
with:
node-version: '20.18.0'

- name: Run debug:bin
run: npm run debug:bin

build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js with Cache and Install
uses: ./.github/actions/install-dependencies
with:
node-version: '20.18.0'

- name: Generate new version
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release --dry-run --no-ci

- name: Build the project
run: |
export VERSION=$(cat .VERSION)
npm run build
- name: Upload build artifacts
uses: actions/upload-artifact@v4
if: github.ref == 'refs/heads/main'
with:
name: build-artifacts
path: ./dist
path: |
./dist
./bin
./pkg
retention-days: 7

build_sea:
runs-on: ubuntu-latest
needs:
- build
strategy:
matrix:
arch: [amd64, arm64]
os: [alpine, bullseye]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: ./

- name: Set up QEMU for multi-arch
uses: docker/setup-qemu-action@v3
with:
platforms: linux/arm64

- name: Build SEA
run: |
docker run --rm --platform linux/${{ matrix.arch }} -v "$PWD":/app -w /app node:20.18.0-${{ matrix.os }} ./scripts/generate-sea.sh ./sea/dclint-${{ matrix.os }}-${{ matrix.arch }}
- name: Upload build SEA artifacts
uses: actions/upload-artifact@v4
with:
name: build-sea-artifacts
path: |
./sea
retention-days: 7

release:
runs-on: ubuntu-latest
needs: build
needs:
- tests
- debug
- build
- build_sea
if: github.ref == 'refs/heads/main'

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: ./dist
path: ./

- name: Set up Node.js
uses: actions/setup-node@v3
- name: Download SEA build artifacts
uses: actions/download-artifact@v4
with:
node-version: '20.17.0'
name: build-sea-artifacts
path: ./

- name: Install dependencies
run: npm ci
# ----------
# Create npm release, tag, github release
# ----------

- name: Set up Node.js with Cache and Install
uses: ./.github/actions/install-dependencies
with:
node-version: '20.18.0'

- name: Run semantic-release
env:
Expand All @@ -83,23 +189,11 @@ jobs:
./package.json
./package-lock.json
./CHANGELOG.md
retention-days: 1

docker:
runs-on: ubuntu-latest
needs: release
if: github.ref == 'refs/heads/main'

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Download release artifacts
uses: actions/download-artifact@v4
with:
name: release-artifacts
path: ./
overwrite: true

# ----------
# Publishing Docker images
# ----------
- name: Get build arguments
id: vars
run: |
Expand All @@ -111,18 +205,38 @@ jobs:
echo "BUILD_REVISION=$BUILD_REVISION" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
with:
install: true

- name: Log in to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
# Build and push the Alpine version
- name: Build and push Alpine version
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/dclint:alpine
${{ secrets.DOCKERHUB_USERNAME }}/dclint:latest-alpine
${{ secrets.DOCKERHUB_USERNAME }}/dclint:${{ env.BUILD_VERSION }}-alpine
build-args: |
BUILD_DATE=${{ env.BUILD_DATE }}
BUILD_VERSION=${{ env.BUILD_VERSION }}
BUILD_REVISION=${{ env.BUILD_REVISION }}
target: alpine-version
cache-from: type=gha
cache-to: type=gha,mode=max

# Build and push the Scratch version
- name: Build and push Scratch version
uses: docker/build-push-action@v6
with:
context: .
push: true
Expand All @@ -134,3 +248,6 @@ jobs:
BUILD_DATE=${{ env.BUILD_DATE }}
BUILD_VERSION=${{ env.BUILD_VERSION }}
BUILD_REVISION=${{ env.BUILD_REVISION }}
target: scratch-version
cache-from: type=gha
cache-to: type=gha,mode=max
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@

# Build
/dist
/bin
/pkg

# Runtime
/.tsimp

# Generated files
/sea-prep.blob
/sea
/.VERSION
11 changes: 9 additions & 2 deletions .markdownlint.cjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
module.exports = {
'default': true,
'no-hard-tabs': false,
'whitespace': false,
'MD003': {
'style': 'atx',
},
'MD004': {
'style': 'dash',
},
'MD007': {
'indent': 2,
},
'MD013': {
'line_length': 120,
'ignore_code_blocks': true,
'ignore_urls': true,
'code_blocks': false,
'tables': false,
},
'MD024': {
Expand Down
Loading

0 comments on commit c563a93

Please sign in to comment.