- darwin-x64/darwin-arm64 move to macos-15-intel/macos-15: `macos-13` is retired, which left the v0.1.6 `darwin-x64` leg queued for 21h+ so `checksums` never ran and no tarballs or SHA256SUMS were attached. - assert the exact six platform assets instead of a literal line count, which passed while a dropped leg was silently missing. - `workflow_dispatch` with a `tag` input rebuilds assets for an existing release without touching npm, Homebrew or the AUR (publish/packaging stay on the tag-push path); `TAG` replaces `github.ref_name` throughout. - `actions/attest-build-provenance` over the tarballs, so `pi2 update` can verify provenance with `gh attestation verify` rather than trusting a checksum shipped in the same release.
395 lines
15 KiB
YAML
395 lines
15 KiB
YAML
name: release
|
|
|
|
on:
|
|
push:
|
|
tags: ["v*"]
|
|
# Backfill (or rebuild) the release assets for a tag that already exists,
|
|
# without touching npm, Homebrew or the AUR: `gh workflow run release.yml -f
|
|
# tag=v0.1.6`. Publishing stays a tag-push-only operation (see the `publish`
|
|
# job's `if`).
|
|
workflow_dispatch:
|
|
inputs:
|
|
tag:
|
|
description: "Existing release tag to build assets for (e.g. v0.1.6)"
|
|
required: true
|
|
type: string
|
|
|
|
# Authentication is npm Trusted Publishing (OIDC): the npm CLI picks up the
|
|
# GitHub Actions OIDC token and exchanges it for a short-lived publish token.
|
|
# The publish step deliberately gets no NPM_TOKEN / NODE_AUTH_TOKEN env.
|
|
# See docs/releasing.md.
|
|
permissions:
|
|
contents: write # create GitHub release and upload binary assets
|
|
id-token: write # mint the OIDC token npm exchanges for publish rights, and the one `attest-build-provenance` signs with
|
|
attestations: write # SLSA build provenance for the binary tarballs
|
|
|
|
# `github.event.inputs` (not `inputs`) so this also evaluates on `push`, where
|
|
# the `inputs` context is not populated.
|
|
env:
|
|
TAG: ${{ github.event.inputs.tag || github.ref_name }}
|
|
|
|
jobs:
|
|
publish:
|
|
# A dispatch run only (re)builds assets for an existing tag; npm publishing
|
|
# must stay on the tag-push path so it never re-publishes a version.
|
|
if: github.event_name == 'push'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ env.TAG }}
|
|
|
|
- uses: pnpm/action-setup@v4
|
|
with:
|
|
version: 10
|
|
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 22
|
|
registry-url: https://registry.npmjs.org
|
|
cache: pnpm
|
|
cache-dependency-path: |
|
|
pnpm-lock.yaml
|
|
web/pnpm-lock.yaml
|
|
|
|
- name: Tag must match package.json version
|
|
run: |
|
|
tag="${TAG#v}"
|
|
pkg="$(node -p 'require("./package.json").version')"
|
|
if [ "$tag" != "$pkg" ]; then
|
|
echo "tag $TAG does not match package.json $pkg" >&2
|
|
exit 1
|
|
fi
|
|
|
|
- name: Install deps
|
|
run: |
|
|
pnpm install --frozen-lockfile
|
|
pnpm --dir web install --frozen-lockfile
|
|
|
|
- name: Test
|
|
run: |
|
|
pnpm typecheck
|
|
pnpm test
|
|
pnpm --dir web exec vitest run
|
|
|
|
# A leftover automation token would silently win over OIDC and hide a
|
|
# broken trusted-publisher configuration, so fail loudly instead.
|
|
# Repository secrets are NOT exported as environment variables on their
|
|
# own, so they are mapped into THIS step's env explicitly: otherwise the
|
|
# guard would see nothing and pass while the publish step (which gets no
|
|
# env at all) would be the first place a stale token could leak in.
|
|
- name: Refuse token-based publishing
|
|
env:
|
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
|
|
run: |
|
|
for var in NODE_AUTH_TOKEN NPM_TOKEN; do
|
|
if [ -n "${!var:-}" ]; then
|
|
echo "::error::env var $var is set. This workflow publishes with npm Trusted Publishing (OIDC) and must run without a token. Delete the repository secret and re-run."
|
|
exit 1
|
|
fi
|
|
done
|
|
echo "no publish token present — OIDC trusted publishing only"
|
|
|
|
# actions/setup-node's node 22 ships npm 10.x, which cannot do trusted
|
|
# publishing (needs >= 11.5.1).
|
|
- name: Upgrade npm
|
|
run: npm install -g npm@11
|
|
|
|
- name: Preflight — npm/node support trusted publishing
|
|
run: |
|
|
node <<'EOF'
|
|
const { execSync } = require("node:child_process");
|
|
|
|
const atLeast = (have, want) => {
|
|
const a = have.split(".").map(Number);
|
|
const b = want.split(".").map(Number);
|
|
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
const x = a[i] || 0;
|
|
const y = b[i] || 0;
|
|
if (x !== y) return x > y;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
const fail = [];
|
|
const npm = execSync("npm --version").toString().trim();
|
|
const node = process.version.replace(/^v/, "");
|
|
console.log(`npm ${npm} / node ${node}`);
|
|
|
|
if (!atLeast(npm, "11.5.1")) {
|
|
fail.push(`npm ${npm} is too old for trusted publishing (need >= 11.5.1); did 'npm install -g npm@11' run?`);
|
|
}
|
|
if (!atLeast(node, "22.14.0")) {
|
|
fail.push(`node ${node} is too old for trusted publishing (need >= 22.14.0)`);
|
|
}
|
|
if (!process.env.ACTIONS_ID_TOKEN_REQUEST_URL) {
|
|
fail.push("no OIDC token endpoint in the environment; 'permissions: id-token: write' is missing or the job is not running on GitHub Actions");
|
|
}
|
|
|
|
if (fail.length) {
|
|
for (const f of fail) console.error(`::error::${f}`);
|
|
process.exit(1);
|
|
}
|
|
console.log("trusted publishing preflight ok (OIDC endpoint present)");
|
|
EOF
|
|
|
|
# `prepack` builds dist/ and web/dist/ as part of pack+publish, so the
|
|
# published tarball is always built from the tagged source; no separate
|
|
# build step is needed here. No --provenance: provenance is automatic for
|
|
# a public package published from a public repo via OIDC.
|
|
# Deliberately no `env:` on this step — OIDC only.
|
|
- name: Publish to npm (trusted publishing, no token)
|
|
run: npm publish --access public
|
|
|
|
- name: Create GitHub release
|
|
uses: softprops/action-gh-release@v2
|
|
with:
|
|
generate_release_notes: true
|
|
tag_name: ${{ env.TAG }}
|
|
body: |
|
|
`npm i -g @yuez/pi2d@${{ env.TAG }}`
|
|
|
|
Compatible pi2.nvim: protocol v1 (see `docs/protocol.md`).
|
|
|
|
binaries:
|
|
runs-on: ${{ matrix.runner }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
# ubuntu-24.04-arm is GA for public repositories. Running linux-arm64 and
|
|
# linux-arm64-musl on native ARM64 runners lets us actually execute and
|
|
# boot-check the artifact before publishing it (all six legs are host-native).
|
|
#
|
|
# macOS labels are pinned to images that are neither retired nor
|
|
# deprecated (`macos-13` was retired and left `darwin-x64` queued for
|
|
# 21h+; `macos-14` is deprecated). `macos-15-intel` is the x64 image and
|
|
# `macos-15` the arm64 one — see actions/runner-images#README.
|
|
include:
|
|
- target: linux-x64
|
|
runner: ubuntu-latest
|
|
- target: linux-arm64
|
|
runner: ubuntu-24.04-arm
|
|
- target: linux-x64-musl
|
|
runner: ubuntu-latest
|
|
- target: linux-arm64-musl
|
|
runner: ubuntu-24.04-arm
|
|
- target: darwin-x64
|
|
runner: macos-15-intel
|
|
- target: darwin-arm64
|
|
runner: macos-15
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ env.TAG }}
|
|
|
|
- uses: pnpm/action-setup@v4
|
|
with:
|
|
version: 10
|
|
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 22
|
|
cache: pnpm
|
|
cache-dependency-path: |
|
|
pnpm-lock.yaml
|
|
web/pnpm-lock.yaml
|
|
|
|
- uses: oven-sh/setup-bun@v2
|
|
|
|
- name: Install deps
|
|
run: |
|
|
pnpm install --frozen-lockfile
|
|
pnpm --dir web install --frozen-lockfile
|
|
|
|
- name: Build binary tarball
|
|
run: bash scripts/build-binary.sh --target ${{ matrix.target }}
|
|
|
|
- name: Boot check (host-native)
|
|
if: ${{ !contains(matrix.target, 'musl') }}
|
|
run: sh scripts/boot-check.sh dist-bin/bin/pi2 "${TAG#v}"
|
|
|
|
- name: Boot check (Alpine, musl artifact)
|
|
# Bun's musl binaries link against musl's libstdc++; the glibc runner
|
|
# cannot load them ("symbol not found" for std:: symbols), so musl
|
|
# artifacts are executed on the libc they are built for.
|
|
if: ${{ contains(matrix.target, 'musl') }}
|
|
run: |
|
|
docker run --rm \
|
|
-v "${{ github.workspace }}/scripts:/s:ro" \
|
|
-v "${{ github.workspace }}/dist-bin:/b:ro" \
|
|
alpine:3.20 sh -c 'apk add --no-cache libstdc++ curl >/dev/null 2>&1 && sh /s/boot-check.sh /b/bin/pi2 "${TAG#v}"'
|
|
|
|
- name: Upload binary tarball artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: pi2d-${{ matrix.target }}
|
|
path: dist-bin/pi2d-*.tar.gz
|
|
if-no-files-found: error
|
|
|
|
checksums:
|
|
needs: [publish, binaries]
|
|
# `always()` keeps a dispatch run alive after the skipped `publish` job; the
|
|
# upload itself still requires a fully green `binaries` matrix.
|
|
if: always() && needs.binaries.result == 'success' && (needs.publish.result == 'success' || needs.publish.result == 'skipped')
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
ref: ${{ env.TAG }}
|
|
|
|
- name: Download all binary artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
pattern: pi2d-*
|
|
path: dist-bin
|
|
merge-multiple: true
|
|
|
|
- name: Generate SHA256SUMS
|
|
run: |
|
|
cd dist-bin
|
|
sha256sum pi2d-*.tar.gz > SHA256SUMS
|
|
echo "Generated SHA256SUMS:"
|
|
cat SHA256SUMS
|
|
sha256sum -c SHA256SUMS
|
|
# Assert the exact platform set instead of a line count: a bare `-ne 6`
|
|
# passed while a dropped leg (say darwin-x64) was silently missing.
|
|
version="${TAG#v}"
|
|
missing=0
|
|
for target in linux-x64 linux-arm64 linux-x64-musl linux-arm64-musl darwin-x64 darwin-arm64; do
|
|
asset="pi2d-${version}-${target}.tar.gz"
|
|
if ! grep -q " ${asset}$" SHA256SUMS; then
|
|
echo "::error::missing asset for ${target}: ${asset}"
|
|
missing=1
|
|
fi
|
|
done
|
|
if [ "$missing" -ne 0 ]; then
|
|
exit 1
|
|
fi
|
|
echo "all 6 platform assets present"
|
|
|
|
- name: Attest build provenance (SLSA)
|
|
# `pi2 update` verifies these with `gh attestation verify`; a checksum
|
|
# shipped in the same release only proves the download was intact.
|
|
uses: actions/attest-build-provenance@v2
|
|
with:
|
|
subject-path: dist-bin/*.tar.gz
|
|
|
|
- name: Upload SHA256SUMS artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: checksums
|
|
path: dist-bin/SHA256SUMS
|
|
if-no-files-found: error
|
|
|
|
- name: Append artifacts to GitHub release
|
|
uses: softprops/action-gh-release@v2
|
|
with:
|
|
tag_name: ${{ env.TAG }}
|
|
files: |
|
|
dist-bin/*.tar.gz
|
|
dist-bin/SHA256SUMS
|
|
|
|
packaging:
|
|
needs: checksums
|
|
# Homebrew/AUR point at the assets this run just uploaded, so they stay on
|
|
# the tag-push path; a dispatch backfill must not bump a tap formula.
|
|
if: github.event_name == 'push'
|
|
runs-on: ubuntu-latest
|
|
# The two release credentials live in job-level env because GitHub does not
|
|
# expose the `secrets` context inside `if:` expressions (a step-level
|
|
# `if: secrets.X != ''` fails workflow parsing with "Unrecognized
|
|
# named-value: 'secrets'"). `env` *is* available in a step-level `if`, so
|
|
# the guards below test the mapped env vars instead.
|
|
env:
|
|
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
|
|
AUR_SSH_KEY: ${{ secrets.AUR_SSH_KEY }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Download checksums artifact
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: checksums
|
|
|
|
- name: Render packaging manifests
|
|
run: |
|
|
tag="${GITHUB_REF_NAME#v}"
|
|
bash scripts/update-packaging.sh \
|
|
--version "$tag" \
|
|
--checksums SHA256SUMS \
|
|
--out build/packaging \
|
|
--no-download
|
|
|
|
- name: Upload rendered packaging files
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: packaging
|
|
path: build/packaging/
|
|
if-no-files-found: error
|
|
|
|
- name: Update Homebrew tap formula
|
|
if: env.HOMEBREW_TAP_TOKEN != ''
|
|
run: |
|
|
version="${GITHUB_REF_NAME#v}"
|
|
echo "HOMEBREW_TAP_TOKEN is present; pushing formula to zgs225/homebrew-tap..."
|
|
git clone "https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/zgs225/homebrew-tap.git" tap-repo
|
|
mkdir -p tap-repo/Formula
|
|
cp build/packaging/pi2d.rb tap-repo/Formula/pi2d.rb
|
|
cd tap-repo
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
git add Formula/pi2d.rb
|
|
if git diff --staged --quiet; then
|
|
echo "Formula/pi2d.rb is already up to date"
|
|
else
|
|
git commit -m "pi2d ${version}"
|
|
git push origin HEAD
|
|
echo "Successfully pushed Formula/pi2d.rb to zgs225/homebrew-tap"
|
|
fi
|
|
|
|
- name: Update Arch Linux AUR package
|
|
if: env.AUR_SSH_KEY != ''
|
|
run: |
|
|
version="${GITHUB_REF_NAME#v}"
|
|
echo "AUR_SSH_KEY is present; pushing to aur@aur.archlinux.org/pi2d-bin.git..."
|
|
mkdir -p ~/.ssh
|
|
echo "$AUR_SSH_KEY" > ~/.ssh/aur_ed25519
|
|
chmod 600 ~/.ssh/aur_ed25519
|
|
ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts 2>/dev/null || true
|
|
export GIT_SSH_COMMAND="ssh -i ~/.ssh/aur_ed25519 -o StrictHostKeyChecking=accept-new"
|
|
git clone ssh://aur@aur.archlinux.org/pi2d-bin.git aur-repo
|
|
cp build/packaging/PKGBUILD build/packaging/.SRCINFO aur-repo/
|
|
cd aur-repo
|
|
git config user.name "github-actions[bot]"
|
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
git add PKGBUILD .SRCINFO
|
|
if git diff --staged --quiet; then
|
|
echo "AUR package is already up to date"
|
|
else
|
|
git commit -m "pi2d ${version}"
|
|
git push origin master
|
|
echo "Successfully pushed to AUR pi2d-bin"
|
|
fi
|
|
|
|
- name: Manual packaging instructions
|
|
env:
|
|
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
|
|
AUR_SSH_KEY: ${{ secrets.AUR_SSH_KEY }}
|
|
run: |
|
|
version="${GITHUB_REF_NAME#v}"
|
|
if [ -z "${HOMEBREW_TAP_TOKEN:-}" ]; then
|
|
echo "HOMEBREW_TAP_TOKEN not set; skipping automated Homebrew tap update."
|
|
echo "To update manually:"
|
|
echo " git clone https://github.com/zgs225/homebrew-tap.git"
|
|
echo " cp <downloaded-artifact>/pi2d.rb homebrew-tap/Formula/pi2d.rb"
|
|
echo " cd homebrew-tap && git add Formula/pi2d.rb && git commit -m 'pi2d ${version}' && git push origin main"
|
|
fi
|
|
if [ -z "${AUR_SSH_KEY:-}" ]; then
|
|
echo "AUR_SSH_KEY not set; skipping automated AUR update."
|
|
echo "To update manually:"
|
|
echo " git clone ssh://aur@aur.archlinux.org/pi2d-bin.git"
|
|
echo " cp <downloaded-artifact>/PKGBUILD <downloaded-artifact>/.SRCINFO pi2d-bin/"
|
|
echo " cd pi2d-bin && git add PKGBUILD .SRCINFO && git commit -m 'pi2d ${version}' && git push origin master"
|
|
fi
|