Files
hyperframes/.github/workflows/publish.yml
T

740 lines
34 KiB
YAML

name: Publish to npm
permissions: {}
# Explicit bash enables pipefail, including digest-generation pipelines.
defaults:
run:
shell: bash
on:
push:
tags:
# Stable tags are created only by a merged, reviewed release PR. Direct
# tag pushes are reserved for prerelease channels.
- "v*-*"
pull_request:
types: [closed]
branches: [main]
env:
# Every package a release publishes, in publish order. The CLI is packed from
# @hyperframes/cli and published as the unscoped "hyperframes" package.
NPM_PACKAGES: >-
@hyperframes/share @hyperframes/parsers @hyperframes/lint @hyperframes/studio-server
@hyperframes/core @hyperframes/inspector @hyperframes/sdk @hyperframes/engine
@hyperframes/player @hyperframes/producer @hyperframes/shader-transitions
@hyperframes/studio @hyperframes/aws-lambda @hyperframes/gcp-cloud-run hyperframes
concurrency:
group: publish-${{ github.event.pull_request.head.ref || github.ref }}
cancel-in-progress: false
jobs:
lambda-arm64-ffmpeg:
name: Lambda arm64 ffmpeg
runs-on: ubuntu-24.04-arm
# A cache miss compiles ffmpeg natively, 15-20 minutes.
timeout-minutes: 60
permissions:
contents: read
env:
EXPECTED_RELEASE_SHA: >-
${{ github.event_name == 'pull_request'
&& github.event.pull_request.merge_commit_sha
|| github.sha }}
if: >-
github.event_name == 'push' ||
(github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.head.ref, 'release/v'))
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ env.EXPECTED_RELEASE_SHA }}
# lambda-arm64-image.yml saves this key on main; a release run's own saves reach only its re-runs.
- id: cache
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
path: out/
key: hf-media-linux-aarch64-${{ hashFiles('packages/aws-lambda/image/**') }}
- if: steps.cache.outputs.cache-hit != 'true'
run: >-
docker buildx build --progress=plain --platform linux/arm64 --target artifact
--output type=local,dest=out packages/aws-lambda/image
# The reviewed digest of the build; a tarball from the cache or this run that differs fails here.
- name: Check the tarball against its committed digest
working-directory: out
run: sha256sum hf-media-linux-aarch64.tar.gz && sha256sum --strict -c ../packages/aws-lambda/hf-media-linux-aarch64.sha256
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: hf-media-linux-aarch64
overwrite: true
path: out/hf-media-linux-aarch64.tar.gz
if-no-files-found: error
lambda-handler-zip:
name: Lambda handler zip
runs-on: ubuntu-latest
timeout-minutes: 30
# Runs apart from the publish job: read-only token, no secrets, no stored git credentials.
permissions:
contents: read
env:
EXPECTED_RELEASE_SHA: >-
${{ github.event_name == 'pull_request'
&& github.event.pull_request.merge_commit_sha
|| github.sha }}
if: >-
github.event_name == 'push' ||
(github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.head.ref, 'release/v'))
outputs:
sha256: ${{ steps.zip.outputs.sha256 }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
ref: ${{ env.EXPECTED_RELEASE_SHA }}
persist-credentials: false
- name: Verify immutable release checkout
run: |
ACTUAL_SHA="$(git rev-parse HEAD)"
EXPECTED_COMMIT_SHA="$(git rev-parse "${EXPECTED_RELEASE_SHA}^{commit}")"
if [ "$ACTUAL_SHA" != "$EXPECTED_COMMIT_SHA" ]; then
echo "::error::Expected release commit $EXPECTED_COMMIT_SHA, checked out $ACTUAL_SHA"
exit 1
fi
# The release installs the bun it downloads, never one restored from the shared cache.
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
no-cache: true
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 24
- run: bun install --frozen-lockfile
- run: bun run build
- name: Build Lambda handler zip
id: zip
run: |
bun run --cwd packages/aws-lambda build:zip
echo "sha256=$(sha256sum packages/aws-lambda/dist/handler.zip | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: hyperframes-lambda-handler-zip
overwrite: true
path: packages/aws-lambda/dist/handler.zip
if-no-files-found: error
pack:
name: Build and pack
outputs:
bundle_id: ${{ steps.previous_bundle.outputs.artifact || steps.bundle.outputs.artifact-id }}
needs: [lambda-arm64-ffmpeg, lambda-handler-zip]
runs-on: ubuntu-latest
timeout-minutes: 30
# Every build and lifecycle script of the release commit runs here, with a
# read-only token and no secrets. The publish job gets only what this job packs.
permissions:
contents: read
actions: read
env:
EXPECTED_RELEASE_SHA: >-
${{ github.event_name == 'pull_request'
&& github.event.pull_request.merge_commit_sha
|| github.sha }}
if: >-
github.event_name == 'push' ||
(github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.head.ref, 'release/v'))
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0
# Pin every release to an immutable ref. In particular, a merged
# release PR event exposes main as github.ref, which may advance
# before this job starts; use the event's exact merge commit instead.
ref: ${{ env.EXPECTED_RELEASE_SHA }}
persist-credentials: false
- name: Verify immutable release checkout
run: |
ACTUAL_SHA="$(git rev-parse HEAD)"
EXPECTED_COMMIT_SHA="$(git rev-parse "${EXPECTED_RELEASE_SHA}^{commit}")"
if [ "$ACTUAL_SHA" != "$EXPECTED_COMMIT_SHA" ]; then
echo "::error::Expected release commit $EXPECTED_COMMIT_SHA, checked out $ACTUAL_SHA"
exit 1
fi
- name: Find previous release bundle
id: previous_bundle
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
RUN_ID: ${{ github.run_id }}
run: |
gh api --paginate "repos/$REPO/actions/runs/$RUN_ID/artifacts?per_page=100" > "$RUNNER_TEMP/previous_bundle-pages.json"
FOUND="$(jq -sre '[.[].artifacts[] | select(.name == "release-bundle")] | if length == 0 then "" elif length == 1 and .[0].expired == false then .[0].id | tostring else error("Missing valid unique release-bundle") end' "$RUNNER_TEMP/previous_bundle-pages.json")"
echo "artifact=${FOUND}" >> "$GITHUB_OUTPUT"
- name: Restore previous release bundle
if: steps.previous_bundle.outputs.artifact != ''
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
artifact-ids: ${{ steps.previous_bundle.outputs.artifact }}
path: release-bundle
merge-multiple: true
- name: Resolve version
if: steps.previous_bundle.outputs.artifact == ''
id: version
env:
EVENT_NAME: ${{ github.event_name }}
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
run: |
if [ "$EVENT_NAME" = "push" ]; then
VERSION="${GITHUB_REF_NAME#v}"
else
BRANCH="${PR_HEAD_REF}"
VERSION="${BRANCH#release/v}"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
# Detect pre-release tag (e.g. 0.1.16-alpha.1 → alpha, 0.1.16-beta.2 → beta)
if [[ "$VERSION" =~ -([a-zA-Z]+) ]]; then
DIST_TAG="${BASH_REMATCH[1]}"
echo "prerelease=true" >> "$GITHUB_OUTPUT"
else
DIST_TAG="latest"
echo "prerelease=false" >> "$GITHUB_OUTPUT"
fi
echo "dist_tag=${DIST_TAG}" >> "$GITHUB_OUTPUT"
echo "Resolved version=${VERSION} dist_tag=${DIST_TAG}"
- name: Validate release channel
if: steps.previous_bundle.outputs.artifact == ''
env:
VERSION: ${{ steps.version.outputs.version }}
DIST_TAG: ${{ steps.version.outputs.dist_tag }}
EVENT_NAME: ${{ github.event_name }}
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
run: node scripts/validate-release-channel.mjs
# The release installs the bun it downloads, never one restored from the shared cache.
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
if: steps.previous_bundle.outputs.artifact == ''
with:
no-cache: true
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
if: steps.previous_bundle.outputs.artifact == ''
with:
node-version: 24
- run: corepack enable
if: steps.previous_bundle.outputs.artifact == ''
- run: corepack prepare pnpm@10.17.1 --activate
if: steps.previous_bundle.outputs.artifact == ''
- run: bun install --frozen-lockfile
if: steps.previous_bundle.outputs.artifact == ''
- run: bun run build
if: steps.previous_bundle.outputs.artifact == ''
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
if: steps.previous_bundle.outputs.artifact == ''
with:
name: hyperframes-lambda-handler-zip
path: dist/lambda-handler-build
# Before packing, so @hyperframes/aws-lambda pins this exact zip.
- name: Pin Lambda handler zip
if: steps.previous_bundle.outputs.artifact == ''
id: lambda_zip
env:
EXPECTED_SHA256: ${{ needs.lambda-handler-zip.outputs.sha256 }}
run: |
ACTUAL_SHA256="$(sha256sum dist/lambda-handler-build/handler.zip | cut -d' ' -f1)"
if [ -z "$EXPECTED_SHA256" ] || [ "$ACTUAL_SHA256" != "$EXPECTED_SHA256" ]; then
echo "::error::Lambda handler zip sha256 $ACTUAL_SHA256 does not match the build job's $EXPECTED_SHA256"
exit 1
fi
mv dist/lambda-handler-build/handler.zip dist/hyperframes-lambda-handler.zip
rm -rf dist/lambda-handler-build
bun packages/aws-lambda/scripts/pin-handler-zip.ts
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
if: steps.previous_bundle.outputs.artifact == ''
with:
name: hf-media-linux-aarch64
path: dist/hf-media
# Built from the zip pinned above. The video stage only copies files, so no emulation is needed.
- name: Build Lambda video image
if: steps.previous_bundle.outputs.artifact == ''
id: lambda_video_image
run: |
bun packages/aws-lambda/scripts/stage-arm64-image.ts --zip=dist/hyperframes-lambda-handler.zip \
--ffmpeg=dist/hf-media/hf-media-linux-aarch64.tar.gz --out=dist/arm64-image
# OCI export needs a docker-container builder; no attestations, so index.json lists one image.
docker buildx create --use
docker buildx build --progress=plain --platform linux/arm64 --target video \
--provenance=false --sbom=false --build-context task=dist/arm64-image/task \
--output type=oci,dest=dist/hyperframes-lambda-video-arm64.oci.tar packages/aws-lambda/image
bun packages/aws-lambda/scripts/pin-handler-zip.ts --video-image
- run: bun run verify:packed-manifests
if: steps.previous_bundle.outputs.artifact == ''
# pnpm pack writes the same tarball pnpm publish uploads: publishConfig
# applied and workspace: ranges replaced with versions.
- name: Pack packages
if: steps.previous_bundle.outputs.artifact == ''
run: |
OUT="$PWD/release-bundle/npm"
mkdir -p "$OUT"
for name in $NPM_PACKAGES; do
[ "$name" = "hyperframes" ] && continue
pnpm --filter "$name" pack --pack-destination "$OUT"
done
# pnpm --filter cannot match the rewritten name, so npm packs the CLI.
node -e "
const fs = require('fs');
const p = 'packages/cli/package.json';
const pkg = JSON.parse(fs.readFileSync(p, 'utf8'));
pkg.name = 'hyperframes';
fs.writeFileSync(p, JSON.stringify(pkg, null, 2) + '\n');
"
(cd packages/cli && npm pack --pack-destination "$OUT")
- name: Build portable agent plugin
if: steps.previous_bundle.outputs.artifact == ''
run: node scripts/package-agent-plugin.mjs
# Keep the original bytes for all retries, including partially uploaded pairs.
- name: Collect release bundle
if: steps.previous_bundle.outputs.artifact == ''
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
mkdir -p release-bundle/assets release-bundle/plugin
mv dist/hyperframes-lambda-handler.zip dist/hyperframes-lambda-handler.sha256 release-bundle/assets/
mv dist/hyperframes-lambda-video-arm64.oci.tar dist/hyperframes-lambda-video-arm64.sha256 release-bundle/assets/
mv dist/hyperframes-agent-plugin.zip dist/hyperframes-agent-plugin.sha256 dist/hyperframes-agent-plugin.json release-bundle/plugin/
if [ -f "releases/v${VERSION}.md" ]; then
cp "releases/v${VERSION}.md" release-bundle/notes.md
fi
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
id: bundle
if: steps.previous_bundle.outputs.artifact == ''
with:
name: release-bundle
path: release-bundle/
if-no-files-found: error
compression-level: 1
overwrite: false
retention-days: 7
publish:
name: Publish
needs: [pack]
runs-on: ubuntu-latest
timeout-minutes: 30
# npm-publish requires a maintainer's approval. That approval is the only
# review a prerelease tag gets, because prerelease branches have no PR review.
# npm's trusted publishers name this environment, so every trigger uses it.
environment: npm-publish
# This job holds the release credentials, so it runs no code from the
# release commit: no install, no build, no repo scripts. It checks the
# pack job's tarballs and uploads them.
permissions:
contents: write
actions: read
id-token: write
env:
EXPECTED_RELEASE_SHA: >-
${{ github.event_name == 'pull_request'
&& github.event.pull_request.merge_commit_sha
|| github.sha }}
# Stable releases come only from reviewed release PRs. Tag pushes are
# prerelease-only because the trigger pattern requires a hyphenated version.
if: >-
github.event_name == 'push' ||
(github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.head.ref, 'release/v'))
steps:
# Only git reads this checkout, for the release tag.
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0
ref: ${{ env.EXPECTED_RELEASE_SHA }}
# Keep the write token out of .git/config. Only "Create release tag"
# pushes, and it authenticates its own git calls.
persist-credentials: false
- name: Verify immutable release checkout
run: |
ACTUAL_SHA="$(git rev-parse HEAD)"
EXPECTED_COMMIT_SHA="$(git rev-parse "${EXPECTED_RELEASE_SHA}^{commit}")"
if [ "$ACTUAL_SHA" != "$EXPECTED_COMMIT_SHA" ]; then
echo "::error::Expected release commit $EXPECTED_COMMIT_SHA, checked out $ACTUAL_SHA"
exit 1
fi
# Resolved again from the event: the pack job ran release-commit code, so its outputs are not trusted here.
- name: Resolve version
id: version
env:
EVENT_NAME: ${{ github.event_name }}
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
run: |
if [ "$EVENT_NAME" = "push" ]; then
VERSION="${GITHUB_REF_NAME#v}"
else
BRANCH="${PR_HEAD_REF}"
VERSION="${BRANCH#release/v}"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
# Detect pre-release tag (e.g. 0.1.16-alpha.1 → alpha, 0.1.16-beta.2 → beta)
if [[ "$VERSION" =~ -([a-zA-Z]+) ]]; then
DIST_TAG="${BASH_REMATCH[1]}"
echo "prerelease=true" >> "$GITHUB_OUTPUT"
else
DIST_TAG="latest"
echo "prerelease=false" >> "$GITHUB_OUTPUT"
fi
echo "dist_tag=${DIST_TAG}" >> "$GITHUB_OUTPUT"
echo "Resolved version=${VERSION} dist_tag=${DIST_TAG}"
# The event rules of scripts/validate-release-channel.mjs, inline so they
# hold even when the release commit changes that script.
- name: Check release channel
env:
EVENT_NAME: ${{ github.event_name }}
VERSION: ${{ steps.version.outputs.version }}
PRERELEASE: ${{ steps.version.outputs.prerelease }}
DIST_TAG: ${{ steps.version.outputs.dist_tag }}
run: |
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z][0-9A-Za-z-]*(\.[0-9A-Za-z-]+)*)?$ ]]; then
echo "::error::Invalid release version \"$VERSION\". Expected x.y.z or x.y.z-channel.N."
exit 1
fi
if [ "$EVENT_NAME" = "push" ] && [ "$PRERELEASE" != "true" ]; then
echo "::error::Tag pushes publish prereleases only; v$VERSION is a stable version."
exit 1
fi
if [ "$EVENT_NAME" = "pull_request" ] && [ "$PRERELEASE" != "false" ]; then
echo "::error::Merged release PRs publish stable releases only; v$VERSION is a prerelease."
exit 1
fi
if [ "$PRERELEASE" = "true" ] && [ "$DIST_TAG" = "latest" ]; then
echo "::error::v$VERSION is a prerelease and cannot publish to the latest dist-tag."
exit 1
fi
- name: Create release tag
if: github.event_name == 'pull_request'
env:
VERSION: ${{ steps.version.outputs.version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
: "${GITHUB_TOKEN:?}"
BASIC_AUTH="$(printf 'x-access-token:%s' "$GITHUB_TOKEN" | base64 -w0)"
echo "::add-mask::$BASIC_AUTH"
export GIT_CONFIG_COUNT=1
export GIT_CONFIG_KEY_0="http.https://github.com/.extraheader"
export GIT_CONFIG_VALUE_0="AUTHORIZATION: basic $BASIC_AUTH"
TAG="v$VERSION"
EXPECTED_TAG_SHA="$(git rev-parse HEAD)"
verify_remote_tag() {
git fetch --force --no-tags origin "+refs/tags/$TAG:refs/tags/$TAG"
ACTUAL_TAG_SHA="$(git rev-parse "refs/tags/$TAG^{commit}")"
if [ "$ACTUAL_TAG_SHA" != "$EXPECTED_TAG_SHA" ]; then
echo "::error::Release tag $TAG points to $ACTUAL_TAG_SHA, expected $EXPECTED_TAG_SHA"
exit 1
fi
echo "Release tag $TAG already exists at the expected commit — skipping"
}
if [ -n "$(git ls-remote --refs origin "refs/tags/$TAG")" ]; then
verify_remote_tag
else
git tag --no-sign "$TAG" "$EXPECTED_TAG_SHA"
if ! git push origin "refs/tags/$TAG"; then
# A concurrent retry may have created the tag after ls-remote.
git tag -d "$TAG"
verify_remote_tag
fi
fi
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: 24
registry-url: "https://registry.npmjs.org"
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
artifact-ids: ${{ needs.pack.outputs.bundle_id }}
merge-multiple: true
path: ${{ runner.temp }}/release-bundle
- name: Check packed tarballs
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
FOUND="$RUNNER_TEMP/packed.tsv"
ORDER="$RUNNER_TEMP/publish-order.tsv"
: > "$FOUND"
: > "$ORDER"
for tarball in "$RUNNER_TEMP"/release-bundle/npm/*; do
file="$(basename "$tarball")"
if ! [[ "$file" =~ ^[A-Za-z0-9._-]+\.tgz$ ]]; then
echo "::error::Unexpected file in the packed tarballs: $file"
exit 1
fi
# npm unpacks every entry one level down, so anything but plain files under package/ could hand npm a
# different package.json than the one checked here.
entries="$(tar -tzf "$tarball")"
types="$(tar -tvzf "$tarball" | cut -c1 | sort -u)"
if grep -q -v '^package/' <<<"$entries" \
|| grep -q -E '(^|/)\.\.?(/|$)|//|\\' <<<"$entries" \
|| [ "$(grep -cx 'package/package.json' <<<"$entries")" -ne 1 ] \
|| grep -q -v -E '^[-d]$' <<<"$types"; then
echo "::error::$file must hold one package/package.json and only plain files under package/"
exit 1
fi
manifest="$(tar -xzOf "$tarball" package/package.json)"
# Publishing applies publishConfig, so it may only carry what our packages set.
if ! jq -e '(.publishConfig // {}) | type == "object"
and (keys - ["access", "registry", "exports", "main", "types"] | length == 0)
and ((.access // "public") == "public")
and ((.registry // "https://registry.npmjs.org/") == "https://registry.npmjs.org/")' \
<<<"$manifest" >/dev/null; then
echo "::error::$file has a publishConfig this release does not allow"
exit 1
fi
name="$(jq -r '.name' <<<"$manifest")"
version="$(jq -r '.version' <<<"$manifest")"
if ! [[ "$name" =~ ^(@[a-z0-9-]+/)?[a-z0-9._-]+$ ]]; then
echo "::error::$file has an invalid package name"
exit 1
fi
if [ "$version" != "$VERSION" ]; then
echo "::error::$file packs $name@$version, but this release is $VERSION"
exit 1
fi
printf '%s\t%s\n' "$name" "$tarball" >> "$FOUND"
done
DUPLICATES="$(cut -f1 "$FOUND" | sort | uniq -d)"
if [ -n "$DUPLICATES" ]; then
echo "::error::Packed more than once: $DUPLICATES"
exit 1
fi
for name in $NPM_PACKAGES; do
line="$(awk -F'\t' -v name="$name" '$1 == name' "$FOUND")"
if [ -z "$line" ]; then
echo "::error::No packed tarball for $name"
exit 1
fi
printf '%s\n' "$line" >> "$ORDER"
done
if [ "$(wc -l < "$FOUND")" -ne "$(wc -l < "$ORDER")" ]; then
EXTRA="$(cut -f1 "$FOUND" | grep -vxF -f <(cut -f1 "$ORDER") | tr '\n' ' ')"
echo "::error::Packed tarballs for packages this workflow does not publish: $EXTRA"
exit 1
fi
cat "$ORDER"
- name: Check published Lambda pins
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
META="$RUNNER_TEMP/aws-lambda-version.json"
PUBLISHED="$RUNNER_TEMP/aws-lambda-published.tgz"
STATUS="$(curl -sS -o "$META" -w '%{http_code}' "https://registry.npmjs.org/@hyperframes%2faws-lambda/${VERSION}")"
if [ "$STATUS" = "404" ]; then
exit 0
fi
if [ "$STATUS" != "200" ]; then
echo "::error::The npm registry answered $STATUS for @hyperframes/aws-lambda@${VERSION}"
exit 1
fi
curl -fsSL -o "$PUBLISHED" "$(jq -r '.dist.tarball' "$META")"
INTEGRITY="sha512-$(openssl dgst -sha512 -binary "$PUBLISHED" | base64 -w0)"
if [ "$INTEGRITY" != "$(jq -r '.dist.integrity' "$META")" ]; then
echo "::error::The @hyperframes/aws-lambda@${VERSION} tarball does not match its npm integrity"
exit 1
fi
check_pin() {
local asset="$1" manifest="$2" pinned built
pinned="$(tar -xzOf "$PUBLISHED" "package/prebuilt/$manifest" | jq -r '.sha256')"
built="$(sha256sum "$RUNNER_TEMP/release-bundle/assets/$asset" | cut -d' ' -f1)"
if [ "$pinned" != "$built" ]; then
echo "::error::@hyperframes/aws-lambda@${VERSION} on npm pins $asset at $pinned, but this run's original bundle has $built"
exit 1
fi
}
check_pin hyperframes-lambda-handler.zip handler-zip.json
check_pin hyperframes-lambda-video-arm64.oci.tar video-image.json
- name: Find previous release receipt
id: previous_receipt
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
RUN_ID: ${{ github.run_id }}
run: |
gh api --paginate "repos/$REPO/actions/runs/$RUN_ID/artifacts?per_page=100" > "$RUNNER_TEMP/previous_receipt-pages.json"
FOUND="$(jq -sre '[.[].artifacts[] | select(.name == "lambda-release-receipt")] | if length == 0 then "" elif length == 1 and .[0].expired == false then .[0].id | tostring else error("Missing valid unique lambda-release-receipt") end' "$RUNNER_TEMP/previous_receipt-pages.json")"
echo "artifact=${FOUND}" >> "$GITHUB_OUTPUT"
- name: Restore previous release receipt
if: steps.previous_receipt.outputs.artifact != ''
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
artifact-ids: ${{ steps.previous_receipt.outputs.artifact }}
path: ${{ runner.temp }}/release-receipt
merge-multiple: true
# This receipt is stored in this run's immutable Actions artifact, never on the mutable release.
- name: Create GitHub Release
id: release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ steps.version.outputs.version }}
PRERELEASE: ${{ steps.version.outputs.prerelease }}
REPO: ${{ github.repository }}
RUN_ID: ${{ github.run_id }}
run: |
RECEIPT="$RUNNER_TEMP/release-receipt/receipt.json"
ASSETS="$RUNNER_TEMP/release-bundle/assets"
mkdir -p "$RUNNER_TEMP/release-receipt"
DIGESTS="$RUNNER_TEMP/lambda-digests.json"
for name in hyperframes-lambda-handler.zip hyperframes-lambda-handler.sha256 hyperframes-lambda-video-arm64.oci.tar hyperframes-lambda-video-arm64.sha256; do
digest="$(sha256sum "$ASSETS/$name" | cut -d' ' -f1)"
jq -n --arg name "$name" --arg digest "$digest" '{key: $name, value: $digest}'
done | jq -s 'from_entries' > "$DIGESTS"
if [ -f "$RECEIPT" ]; then
jq -e --arg repo "$REPO" --arg run "$RUN_ID" --arg tag "v$VERSION" --arg sha "$EXPECTED_RELEASE_SHA" --slurpfile assets "$DIGESTS" '
.repo == $repo and .run == $run and .tag == $tag and .sha == $sha and
(.release_id | type == "number" and . > 0 and floor == .) and .assets == $assets[0]
' "$RECEIPT" > /dev/null
RELEASE_ID="$(jq -r .release_id "$RECEIPT")"
gh api "repos/$REPO/releases/tags/v$VERSION" > "$RUNNER_TEMP/release.json"
jq -e --argjson id "$RELEASE_ID" '.id == $id' "$RUNNER_TEMP/release.json" > /dev/null
else
# Create-only: an existing release or a concurrent creator fails, never becomes ours.
NOTES_FILE="$RUNNER_TEMP/release-bundle/notes.md"
if [ ! -f "$NOTES_FILE" ]; then
gh api --method POST "repos/$REPO/releases/generate-notes" -f tag_name="v$VERSION" --jq .body > "$RUNNER_TEMP/generated-notes.md"
NOTES_FILE="$RUNNER_TEMP/generated-notes.md"
fi
jq -n --arg tag "v$VERSION" --arg sha "$EXPECTED_RELEASE_SHA" --argjson prerelease "$PRERELEASE" --rawfile body "$NOTES_FILE" \
'{tag_name:$tag, target_commitish:$sha, name:$tag, prerelease:$prerelease, body:$body}' > "$RUNNER_TEMP/create-release.json"
gh api --method POST "repos/$REPO/releases" --input "$RUNNER_TEMP/create-release.json" > "$RUNNER_TEMP/release.json"
RELEASE_ID="$(jq -er '.id | select(type == "number" and . > 0 and floor == .)' "$RUNNER_TEMP/release.json")"
jq -n --arg repo "$REPO" --arg run "$RUN_ID" --arg tag "v$VERSION" --arg sha "$EXPECTED_RELEASE_SHA" --argjson id "$RELEASE_ID" --slurpfile assets "$DIGESTS" \
'{repo:$repo,run:$run,tag:$tag,sha:$sha,release_id:$id,assets:$assets[0]}' > "$RECEIPT"
fi
echo "id=$RELEASE_ID" >> "$GITHUB_OUTPUT"
- name: Save release receipt
if: steps.previous_receipt.outputs.artifact == ''
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: lambda-release-receipt
path: ${{ runner.temp }}/release-receipt/receipt.json
if-no-files-found: error
overwrite: false
retention-days: 7
- name: Attach Lambda assets to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
VERSION: ${{ steps.version.outputs.version }}
RELEASE_ID: ${{ steps.release.outputs.id }}
run: |
ASSETS="$RUNNER_TEMP/release-bundle/assets"
for name in hyperframes-lambda-handler.zip hyperframes-lambda-handler.sha256 hyperframes-lambda-video-arm64.oci.tar hyperframes-lambda-video-arm64.sha256; do
digest="$(sha256sum "$ASSETS/$name" | cut -d' ' -f1)"
gh api --paginate "repos/$REPO/releases/$RELEASE_ID/assets?per_page=100" > "$RUNNER_TEMP/assets-pages.json"
existing="$(jq -sc --arg name "$name" '[.[][] | select(.name == $name)]' "$RUNNER_TEMP/assets-pages.json")"
if [ "$(jq length <<< "$existing")" != 0 ]; then
jq -e --arg digest "sha256:$digest" 'length == 1 and .[0].state == "uploaded" and .[0].digest == $digest' <<< "$existing" > /dev/null
else
# Upload by the recorded ID; a replacement release at the tag cannot receive these bytes.
gh api --method POST "https://uploads.github.com/repos/$REPO/releases/$RELEASE_ID/assets?name=$name" \
-H 'Content-Type: application/octet-stream' --input "$ASSETS/$name" > "$RUNNER_TEMP/uploaded-asset.json"
jq -e --arg digest "sha256:$digest" '.state == "uploaded" and .digest == $digest' "$RUNNER_TEMP/uploaded-asset.json" > /dev/null
fi
done
- name: Verify Lambda release before npm publication
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
VERSION: ${{ steps.version.outputs.version }}
RELEASE_ID: ${{ steps.release.outputs.id }}
run: |
gh api "repos/$REPO/releases/tags/v$VERSION" > "$RUNNER_TEMP/release.json"
jq -e --argjson id "$RELEASE_ID" '.id == $id' "$RUNNER_TEMP/release.json" > /dev/null
gh api --paginate "repos/$REPO/releases/$RELEASE_ID/assets?per_page=100" > "$RUNNER_TEMP/assets-pages.json"
jq -se --slurpfile receipt "$RUNNER_TEMP/release-receipt/receipt.json" '
[.[][]] as $assets | $receipt[0].assets | to_entries | all(.[];
. as $expected | [$assets[] | select(.name == $expected.key)] |
length == 1 and .[0].state == "uploaded" and .[0].digest == ("sha256:" + $expected.value))
' "$RUNNER_TEMP/assets-pages.json" > /dev/null
# Runs outside the checkout so no project .npmrc applies, and with
# --ignore-scripts so no lifecycle script runs next to the npm token.
- name: Publish packages
working-directory: ${{ runner.temp }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
VERSION: ${{ steps.version.outputs.version }}
DIST_TAG: ${{ steps.version.outputs.dist_tag }}
run: |
FAILED=0
publish_tarball() {
local name="$1"
local tarball="$2"
local integrity published
integrity="sha512-$(openssl dgst -sha512 -binary "$tarball" | base64 -w0)"
if published="$(npm view "${name}@${VERSION}" dist.integrity 2>/dev/null)" && [ -n "$published" ]; then
if [ "$published" = "$integrity" ]; then
echo "⏭️ ${name}@${VERSION} already published with these contents — skipping"
else
echo "::error::${name}@${VERSION} is already on npm, and this run did not publish it. Find out who did before releasing this version."
FAILED=1
fi
return 0
fi
echo "📦 Publishing ${name}@${VERSION}..."
if npm publish "$tarball" --access public --tag "$DIST_TAG" --registry https://registry.npmjs.org/ --ignore-scripts; then
echo "✅ ${name}@${VERSION} published"
else
echo "❌ ${name}@${VERSION} failed to publish"
FAILED=1
fi
}
while IFS=$'\t' read -r name tarball; do
publish_tarball "$name" "$tarball"
done < publish-order.tsv
if [ "$FAILED" -ne 0 ]; then
echo "::error::One or more packages failed to publish"
exit 1
fi
- name: Attach portable plugin to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ steps.version.outputs.version }}
REPO: ${{ github.repository }}
working-directory: ${{ runner.temp }}/release-bundle/plugin
run: gh release upload "v${VERSION}" hyperframes-agent-plugin.zip hyperframes-agent-plugin.sha256 hyperframes-agent-plugin.json --repo "$REPO" --clobber