Skip to content

Commit

Permalink
rework the build pipeline:
Browse files Browse the repository at this point in the history
- we now build prebuild and test jobs separately to run the tests against all versions of node with a single set of prebuilt artifacts.
  • Loading branch information
mceachen committed Dec 18, 2024
1 parent 877e24e commit 5cbd9cd
Showing 1 changed file with 128 additions and 49 deletions.
177 changes: 128 additions & 49 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,134 @@ on:
default: "minor"

jobs:
test-matrix:
prebuild-macos:
strategy:
fail-fast: false
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
cache: "npm"
- run: npm ci
- run: npm run prebuild
- uses: actions/upload-artifact@v4
with:
name: prebuilds-${{ matrix.os }}
path: prebuilds/

prebuild-windows:
strategy:
fail-fast: false
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
cache: "npm"
- run: npm ci
- run: npm run prebuild
- uses: actions/upload-artifact@v4
with:
name: prebuilds-${{ matrix.os }}
path: prebuilds/

prebuild-ubuntu:
strategy:
fail-fast: false
matrix:
# my eyes can't discern arm64 from amd64
arch: [x64, arm64]
runs-on: ubuntu-22.04 # < build on older Ubuntu
steps:
- name: Setup QEMU
if: ${{ matrix.arch == 'arm64' }}
uses: docker/setup-qemu-action@v3
with:
platforms: linux/arm64
- run: sudo apt-get update
- run: sudo apt-get install -y build-essential libglib2.0-dev libblkid-dev uuid-dev
- uses: actions/setup-node@v4
with:
node-version: 18
- uses: actions/checkout@v4
- run: npm ci
- run: npm run prebuild
- uses: actions/upload-artifact@v4
with:
name: prebuilds-linux-${{ matrix.arch }}-glibc
path: prebuilds/

prebuild-alpine:
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-14]
# my eyes can't discern arm64 from amd64
arch: [x64, arm64]
node-version: [18, 20, 22, 23]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
if: ${{ matrix.arch == 'arm64' }}
with:
platforms: linux/arm64
- run: |
docker run --rm -v $(pwd):/tmp/project --entrypoint /bin/sh --platform linux/${{ matrix.arch == 'x64' && 'amd64' || 'arm64' }} node:${{ matrix.node-version }}-alpine -c "\
apk add build-base git python3 py3-setuptools util-linux-dev --update-cache && \
cd /tmp/project && \
npm ci && \
npm run prebuild"
runs-on: ${{ matrix.os }}
- uses: actions/upload-artifact@v4
with:
name: prebuilds-linux-${{ matrix.arch }}-musl
path: prebuilds/

test-macos:
needs: [prebuild-macos]
strategy:
fail-fast: false
matrix:
node-version: [18, 20, 22, 23]
runs-on: macos-14
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: ./prebuilds
merge-multiple: true
- run: npm ci
- run: npm run tests

- name: Install dependencies
run: npm ci

- name: Compile native code
run: npm run prebuild

- name: Run tests
run: npm run tests

- name: Upload prebuilds
if: ${{ matrix.node-version == 18 && github.event_name == 'workflow_dispatch' }}
uses: actions/upload-artifact@v4
test-windows:
needs: [prebuild-windows]
strategy:
fail-fast: false
matrix:
node-version: [18, 20, 22, 23]
runs-on: windows-latest
steps:
- uses: actions/setup-node@v4
with:
name: prebuilds-${{ matrix.os }}
path: prebuilds/
node-version: ${{ matrix.node-version }}
cache: "npm"
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: ./prebuilds
merge-multiple: true
- run: npm ci
- run: npm run tests

test-ubuntu:
needs: [prebuild-ubuntu]
strategy:
fail-fast: false
matrix:
Expand All @@ -72,17 +164,15 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: ./prebuilds
merge-multiple: true
- run: npm ci
- run: npm run prebuild
- run: npm run tests
- name: Upload prebuilds
if: ${{ matrix.node-version == 18 && github.event_name == 'workflow_dispatch' }}
uses: actions/upload-artifact@v4
with:
name: prebuilds-linux-${{ matrix.arch }}-glibc
path: prebuilds/

test-alpine:
needs: [prebuild-alpine]
strategy:
fail-fast: false
matrix:
Expand All @@ -92,6 +182,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: ./prebuilds
merge-multiple: true
- uses: docker/setup-qemu-action@v3
if: ${{ matrix.arch == 'arm64' }}
with:
Expand All @@ -104,36 +198,21 @@ jobs:
npm run prebuild && \
npm run tests"
- name: Upload prebuilds
if: ${{ matrix.node-version == 18 && github.event_name == 'workflow_dispatch' }}
uses: actions/upload-artifact@v4
with:
name: prebuilds-linux-${{ matrix.arch }}-musl
path: prebuilds/

publish:
if: ${{ github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-22.04
needs: [test-matrix, test-ubuntu, test-alpine]
needs: [test-macos, test-windows, test-ubuntu, test-alpine]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18

# We need to download the prebuilds **before** installing dependencies,
# or `npm ci` will recompile the native code.
- name: Download all artifacts
uses: actions/download-artifact@v4
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: ./prebuilds
merge-multiple: true

- name: Install dependencies
run: npm ci

- name: List ./prebuilds/
run: ls -laR ./prebuilds
- run: ls -laR ./prebuilds
- run: npm ci

# https://github.com/actions/checkout?tab=readme-ov-file#push-a-commit-using-the-built-in-token
# https://chatgpt.com/share/6761e017-9950-800e-ba1e-94d575010f2d
Expand Down

0 comments on commit 5cbd9cd

Please sign in to comment.