Make Prebuilds #6
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
# Triggering prebuilds: | |
# 1. Create a draft release manually using the GitHub UI. | |
# 2. Set the `jobs.*.strategy.matrix.node` arrays to the set of Node.js versions | |
# to build for. | |
# 3. Set the `jobs.*.strategy.matrix.canvas_tag` arrays to the set of Canvas | |
# tags to build. (Usually this is a single tag, but can be an array when a | |
# new version of Node.js is released and older versions of Canvas need to be | |
# built.) | |
# 4. Commit and push this file to master. | |
# 5. In the Actions tab, navigate to the "Make Prebuilds" workflow and click | |
# "Run workflow". | |
# 6. Once the builds succeed, promote the draft release to a full release. | |
name: Make Prebuilds | |
on: workflow_dispatch | |
# UPLOAD_TO can be specified to upload the release assets under a different tag | |
# name (e.g. for testing). If omitted, the assets are published under the same | |
# release tag as the canvas version being built. | |
# env: | |
# UPLOAD_TO: "v0.0.1" | |
jobs: | |
macOS: | |
strategy: | |
matrix: | |
node: [18.12.0, 20.9.0] | |
canvas_tag: ["m1-testing"] # e.g. "v2.6.1" | |
os: | |
- runner: macos-latest | |
arch: x64 | |
- runner: macos-latest-xlarge # GitHub's Apple Silicon runner | |
arch: arm64 | |
name: ${{ matrix.canvas_tag}}, Node.js ${{ matrix.node }}, macOS ${{ matrix.os.arch }} | |
runs-on: ${{ matrix.os.runner }} | |
env: | |
CANVAS_VERSION_TO_BUILD: ${{ matrix.canvas_tag }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ matrix.canvas_tag }} | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node }} | |
- name: Build | |
run: | | |
npm install -g node-gyp | |
npm install --ignore-scripts | |
. prebuild/macOS/preinstall.sh | |
cp prebuild/macOS/binding.gyp binding.gyp | |
node-gyp rebuild -j 2 | |
. prebuild/macOS/bundle.sh | |
- name: Test binary | |
run: | | |
brew uninstall --force cairo pango librsvg giflib harfbuzz | |
npm test | |
- name: Make bundle | |
id: make_bundle | |
run: . prebuild/tarball.sh | |
- name: Upload | |
uses: actions/github-script@0.9.0 | |
with: | |
script: | | |
const fs = require("fs"); | |
const assetName = "${{ steps.make_bundle.outputs.asset_name }}"; | |
const tagName = process.env.UPLOAD_TO || process.env.CANVAS_VERSION_TO_BUILD; | |
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/"); | |
const releases = await github.repos.listReleases({owner, repo}); | |
const release = releases.data.find(r => r.tag_name === tagName); | |
if (!release) | |
throw new Error(`Tag ${tagName} not found. Did you make the GitHub release?`); | |
const oldAsset = release.assets.find(a => a.name === assetName); | |
if (oldAsset) | |
await github.repos.deleteReleaseAsset({owner, repo, asset_id: oldAsset.id}); | |
// (This is equivalent to actions/upload-release-asset. We're | |
// already in a script, so might as well do it here.) | |
const r = await github.repos.uploadReleaseAsset({ | |
url: release.upload_url, | |
headers: { | |
"content-type": "application/x-gzip", | |
"content-length": `${fs.statSync(assetName).size}` | |
}, | |
name: assetName, | |
data: fs.readFileSync(assetName) | |
}); |