add secrets for git user name and email #94
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
workflow_dispatch: | |
inputs: | |
version: | |
description: "Version bump type" | |
required: true | |
type: choice | |
options: | |
- patch | |
- minor | |
- major | |
default: "minor" | |
jobs: | |
test-matrix: | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [windows-latest, macos-14] | |
node-version: [18, 20, 22, 23] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: "npm" | |
- 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 | |
with: | |
name: prebuilds-${{ matrix.os }} | |
path: prebuilds/ | |
test-ubuntu: | |
strategy: | |
fail-fast: false | |
matrix: | |
arch: [x64, arm64] | |
node-version: [18, 20, 22, 23] | |
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: ${{ matrix.node-version }} | |
- uses: actions/checkout@v4 | |
- 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: | |
strategy: | |
fail-fast: false | |
matrix: | |
# 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 && \ | |
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] | |
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 | |
with: | |
path: ./prebuilds | |
merge-multiple: true | |
- name: Install dependencies | |
run: npm ci | |
- name: List ./prebuilds/ | |
run: ls -laR ./prebuilds | |
# 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 | |
- name: Set up GPG | |
uses: crazy-max/ghaction-import-gpg@v6 | |
with: | |
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} | |
passphrase: ${{ secrets.GPG_PASSPHRASE }} | |
fingerprint: ${{ secrets.GPG_FINGERPRINT }} | |
git_config_global: true | |
git_user_signingkey: true | |
git_commit_gpgsign: true | |
git_tag_gpgsign: true | |
- name: Configure git for publishing | |
run: | | |
git config user.name "${secrets.GIT_USER_NAME}" | |
git config user.email "${secrets.GIT_USER_EMAIL}" | |
- name: Configure npm for publishing | |
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
- name: Publish to npm | |
run: npm run release -- --ci ${{ github.event.inputs.version }} | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Cleanup GPG keys | |
if: always() | |
run: | | |
gpg --batch --yes --delete-secret-keys ${{ secrets.GPG_KEY_ID }} | |
gpg --batch --yes --delete-keys ${{ secrets.GPG_KEY_ID }} | |
rm -rf ~/.gnupg/ | |
- name: Remove npm token | |
if: always() | |
run: rm -f ~/.npmrc |