Skip to content

prebuilt-binaries

prebuilt-binaries #4

name: prebuilt-binaries
on:
workflow_dispatch:
inputs:
version:
description: "Override the semver used for the release tag (defaults to package.json or published release tag)"
required: false
type: string
publish:
description: "Upload generated binaries to a GitHub release"
required: false
default: true
type: boolean
push:
tags:
- "*"
permissions:
contents: write
actions: read
env:
PREBUILT_DIR: prebuilt-artifacts
jobs:
metadata:
name: Resolve Version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.versions.outputs.version }}
tag: ${{ steps.versions.outputs.tag }}
should_publish: ${{ steps.versions.outputs.should_publish }}
steps:
- uses: actions/checkout@v4
- id: versions
env:
EVENT_NAME: ${{ github.event_name }}
INPUT_VERSION: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version || '' }}
PUBLISH_INPUT: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.publish || 'true' }}
RELEASE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || '' }}
run: |
set -euo pipefail
VERSION="${INPUT_VERSION}"
TAG=""
if [ -z "$VERSION" ]; then
if [ "$EVENT_NAME" = "release" ]; then
TAG="$RELEASE_TAG"
if [ -z "$TAG" ]; then
TAG="$GITHUB_REF_NAME"
fi
TAG="${TAG#refs/tags/}"
if [[ "$TAG" != v* ]]; then
TAG="v${TAG}"
fi
VERSION="${TAG#v}"
else
VERSION=$(node -p "require('./package.json').version")
TAG="v${VERSION}"
fi
else
if [[ "$VERSION" == v* ]]; then
TAG="$VERSION"
VERSION="${VERSION#v}"
else
TAG="v${VERSION}"
fi
fi
if [ -z "$VERSION" ]; then
echo "Unable to determine version" >&2
exit 1
fi
SHOULD_PUBLISH="false"
if [ "$EVENT_NAME" = "release" ]; then
SHOULD_PUBLISH="true"
else
case "${PUBLISH_INPUT,,}" in
true|1|yes)
SHOULD_PUBLISH="true"
;;
esac
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "should_publish=${SHOULD_PUBLISH}" >> "$GITHUB_OUTPUT"
linux:
name: Linux (${{ matrix.slug }})
needs: metadata
runs-on: ubuntu-22.04
container:
image: ${{ matrix.image }}
strategy:
fail-fast: false
matrix:
include:
- slug: x64
npm_arch: x64
image: vscodium/vscodium-linux-build-agent:focal-x64
- slug: arm64
npm_arch: arm64
image: vscodium/vscodium-linux-build-agent:focal-arm64
- slug: armhf
npm_arch: arm
image: vscodium/vscodium-linux-build-agent:focal-armhf
- slug: riscv64
npm_arch: riscv64
image: vscodium/vscodium-linux-build-agent:focal-riscv64
- slug: loong64
npm_arch: loong64
image: vscodium/vscodium-linux-build-agent:beige-loong64
- slug: ppc64le
npm_arch: ppc64
image: vscodium/vscodium-linux-build-agent:focal-ppc64le
- slug: s390x
npm_arch: s390x
image: vscodium/vscodium-linux-build-agent:jammy-s390x
env:
TARGET_PLATFORM: linux
PACKAGE_VERSION: ${{ needs.metadata.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install system dependencies
run: |
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
build-essential \
python3 \
libx11-dev \
libxkbfile-dev
- name: Install npm dependencies
run: npm install --no-fund --no-audit --ignore-scripts
- name: Build native module
env:
npm_config_build_from_source: true
npm_config_arch: ${{ matrix.npm_arch }}
npm_config_target_arch: ${{ matrix.npm_arch }}
run: npx node-gyp rebuild
- name: Package artifact
run: |
set -euo pipefail
mkdir -p "${PREBUILT_DIR}/${TARGET_PLATFORM}-${{ matrix.slug }}"
cp build/Release/keymapping.node "${PREBUILT_DIR}/${TARGET_PLATFORM}-${{ matrix.slug }}/keymapping.node"
tar -czf "${PREBUILT_DIR}/native-keymap-${PACKAGE_VERSION}-${TARGET_PLATFORM}-${{ matrix.slug }}.tar.gz" -C "${PREBUILT_DIR}/${TARGET_PLATFORM}-${{ matrix.slug }}" keymapping.node
(cd "${PREBUILT_DIR}" && sha256sum "native-keymap-${PACKAGE_VERSION}-${TARGET_PLATFORM}-${{ matrix.slug }}.tar.gz" > "native-keymap-${PACKAGE_VERSION}-${TARGET_PLATFORM}-${{ matrix.slug }}.tar.gz.sha256")
- uses: actions/upload-artifact@v4
with:
name: native-keymap-${{ env.TARGET_PLATFORM }}-${{ matrix.slug }}
path: |
${{ env.PREBUILT_DIR }}/native-keymap-${{ env.PACKAGE_VERSION }}-${{ env.TARGET_PLATFORM }}-${{ matrix.slug }}.tar.gz
${{ env.PREBUILT_DIR }}/native-keymap-${{ env.PACKAGE_VERSION }}-${{ env.TARGET_PLATFORM }}-${{ matrix.slug }}.tar.gz.sha256
macos:
name: macOS (${{ matrix.vscode_arch }})
needs: metadata
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- runner: macos-13
vscode_arch: x64
- runner: [self-hosted, macOS, ARM64]
vscode_arch: arm64
env:
TARGET_PLATFORM: darwin
PACKAGE_VERSION: ${{ needs.metadata.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install npm dependencies
run: npm install --no-fund --no-audit --ignore-scripts
- name: Build native module
env:
npm_config_build_from_source: true
npm_config_arch: ${{ matrix.vscode_arch }}
run: npx node-gyp rebuild
- name: Package artifact
run: |
set -euo pipefail
mkdir -p "${PREBUILT_DIR}/${TARGET_PLATFORM}-${{ matrix.vscode_arch }}"
cp build/Release/keymapping.node "${PREBUILT_DIR}/${TARGET_PLATFORM}-${{ matrix.vscode_arch }}/keymapping.node"
tar -czf "${PREBUILT_DIR}/native-keymap-${PACKAGE_VERSION}-${TARGET_PLATFORM}-${{ matrix.vscode_arch }}.tar.gz" -C "${PREBUILT_DIR}/${TARGET_PLATFORM}-${{ matrix.vscode_arch }}" keymapping.node
(cd "${PREBUILT_DIR}" && shasum -a 256 "native-keymap-${PACKAGE_VERSION}-${TARGET_PLATFORM}-${{ matrix.vscode_arch }}.tar.gz" > "native-keymap-${PACKAGE_VERSION}-${TARGET_PLATFORM}-${{ matrix.vscode_arch }}.tar.gz.sha256")
- uses: actions/upload-artifact@v4
with:
name: native-keymap-${{ env.TARGET_PLATFORM }}-${{ matrix.vscode_arch }}
path: |
${{ env.PREBUILT_DIR }}/native-keymap-${{ env.PACKAGE_VERSION }}-${{ env.TARGET_PLATFORM }}-${{ matrix.vscode_arch }}.tar.gz
${{ env.PREBUILT_DIR }}/native-keymap-${{ env.PACKAGE_VERSION }}-${{ env.TARGET_PLATFORM }}-${{ matrix.vscode_arch }}.tar.gz.sha256
windows:
name: Windows (${{ matrix.arch }})
needs: metadata
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
arch: [x64, arm64]
env:
TARGET_PLATFORM: win32
PACKAGE_VERSION: ${{ needs.metadata.outputs.version }}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install npm dependencies
run: npm install --no-fund --no-audit --ignore-scripts
- name: Build native module
env:
npm_config_build_from_source: true
npm_config_arch: ${{ matrix.arch }}
npm_config_target_arch: ${{ matrix.arch }}
run: npx node-gyp rebuild
- name: Package artifact
run: |
set -euo pipefail
mkdir -p "${PREBUILT_DIR}/${TARGET_PLATFORM}-${{ matrix.arch }}"
cp build/Release/keymapping.node "${PREBUILT_DIR}/${TARGET_PLATFORM}-${{ matrix.arch }}/keymapping.node"
tar -czf "${PREBUILT_DIR}/native-keymap-${PACKAGE_VERSION}-${TARGET_PLATFORM}-${{ matrix.arch }}.tar.gz" -C "${PREBUILT_DIR}/${TARGET_PLATFORM}-${{ matrix.arch }}" keymapping.node
- name: Generate checksums
shell: pwsh
run: |
$target = "${env:PREBUILT_DIR}\native-keymap-${env:PACKAGE_VERSION}-${env:TARGET_PLATFORM}-${{ matrix.arch }}.tar.gz"
$hash = (Get-FileHash -Path $target -Algorithm SHA256).Hash
Set-Content -Path "$target.sha256" -Value "$hash $(Split-Path -Leaf $target)"
- uses: actions/upload-artifact@v4
with:
name: native-keymap-${{ env.TARGET_PLATFORM }}-${{ matrix.arch }}
path: |
${{ env.PREBUILT_DIR }}/native-keymap-${{ env.PACKAGE_VERSION }}-${{ env.TARGET_PLATFORM }}-${{ matrix.arch }}.tar.gz
${{ env.PREBUILT_DIR }}/native-keymap-${{ env.PACKAGE_VERSION }}-${{ env.TARGET_PLATFORM }}-${{ matrix.arch }}.tar.gz.sha256
publish:
name: Publish Release
needs:
- metadata
- linux
- macos
- windows
if: needs.metadata.outputs.should_publish == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js for npm publish
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: https://registry.npmjs.org
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: collected-artifacts
- name: Flatten artifact structure
run: |
set -euo pipefail
mkdir -p release
find collected-artifacts -type f -name '*.tar.gz*' -exec cp {} release/ \;
- name: Publish package to npm
run: |
if [ -n "$NODE_AUTH_TOKEN" ]; then
npm publish --access public
else
echo "NPM token not present, skipping publish"
fi
- name: Publish release assets
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.metadata.outputs.tag }}
name: native-keymap ${{ needs.metadata.outputs.tag }}
files: release/*
draft: false
prerelease: false