Skip to content

docs(changelog): fix changelog headers #100

docs(changelog): fix changelog headers

docs(changelog): fix changelog headers #100

Workflow file for this run

# Publishes to npm over one of two auth paths, picked per run by probing the
# registry. A package that already exists publishes via OIDC trusted
# publishing, and must list this repo and this workflow file as a Trusted
# Publisher on npmjs.org or the publish step fails to authenticate. A package
# that does not exist yet publishes with the NPM_TOKEN secret, because a
# Trusted Publisher can only be registered against a package the registry
# already knows. Register it right after the first publish; every later
# version then takes the OIDC path.
name: Publish Release
on:
pull_request:
types: [closed]
branches: [main, beta]
# Escape hatch: re-run a publish that failed mid-flow (e.g. after a fix to
# this workflow). Reads the version from the package.json on the chosen ref.
workflow_dispatch:
inputs:
package:
description: "Package to (re)publish"
required: true
type: choice
options:
- compact-builder
- compact-cli
- compact-deployer
- compact-linter
- compact-simulator
jobs:
# Detection is its own job so the binary matrix and the publish both read the
# same answer.
detect:
name: Detect released package
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event.pull_request.merged == true &&
contains(github.event.pull_request.labels.*.name, 'release'))
runs-on: ubuntu-24.04
permissions:
contents: read
outputs:
dir: ${{ steps.pkg.outputs.dir }}
name: ${{ steps.pkg.outputs.name }}
version: ${{ steps.pkg.outputs.version }}
dist_tag: ${{ steps.pkg.outputs.dist_tag }}
sha: ${{ steps.pkg.outputs.sha }}
steps:
# For pull_request runs: checkout the merge commit (deterministic view of
# what was just merged). For manual dispatch: checkout the dispatched ref
# (defaults to main but can be any branch — hotfix, release-prep, etc.).
# The compact-npm-prod environment approval is the security gate, not the
# branch ref.
- name: Check out target ref
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.merge_commit_sha || github.ref }}
- name: Detect released package
id: pkg
env:
EVENT: ${{ github.event_name }}
MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }}
INPUT_PACKAGE: ${{ inputs.package }}
BASE_REF: ${{ github.event.pull_request.base.ref }}
run: |
if [[ "$EVENT" == "workflow_dispatch" ]]; then
PKG="$INPUT_PACKAGE"
case "$PKG" in
compact-builder) DIR="builder" ;;
compact-cli) DIR="cli" ;;
compact-deployer) DIR="deployer" ;;
compact-linter) DIR="linter" ;;
compact-simulator) DIR="simulator" ;;
*)
echo "::error::unknown package: $PKG"
exit 1
;;
esac
else
mapfile -t CHANGED < <(git diff --name-only "$MERGE_SHA^" "$MERGE_SHA" -- 'packages/*/package.json')
COUNT=${#CHANGED[@]}
if [[ "$COUNT" -ne 1 ]]; then
echo "::error::expected exactly one packages/*/package.json change, found $COUNT"
printf '%s\n' "${CHANGED[@]}" >&2
exit 1
fi
DIR=$(echo "${CHANGED[0]}" | awk -F/ '{print $2}')
case "$DIR" in
builder) PKG="compact-builder" ;;
cli) PKG="compact-cli" ;;
deployer) PKG="compact-deployer" ;;
linter) PKG="compact-linter" ;;
simulator) PKG="compact-simulator" ;;
*)
echo "::error::unknown package directory: $DIR"
exit 1
;;
esac
fi
VERSION=$(node -p "require('./packages/$DIR/package.json').version")
# The dist-tag comes from the version alone, so a prerelease can never
# take over `latest` regardless of which ref dispatched the run.
PRERELEASE="${VERSION#*-}"
if [[ "$PRERELEASE" == "$VERSION" ]]; then
DIST_TAG=latest
elif [[ "$PRERELEASE" == beta.* ]]; then
DIST_TAG=beta
else
echo "::error::unsupported prerelease identifier in $VERSION; expected beta.N"
exit 1
fi
# On the merge path the base branch is known, so hold the two channels
# apart: beta ships prereleases, main ships stable.
if [[ "$EVENT" == "pull_request" ]]; then
case "$BASE_REF:$DIST_TAG" in
beta:beta|main:latest) ;;
*)
echo "::error::$VERSION (dist-tag $DIST_TAG) cannot be released from '$BASE_REF'"
exit 1
;;
esac
fi
{
echo "dir=$DIR"
echo "name=$PKG"
echo "version=$VERSION"
echo "dist_tag=$DIST_TAG"
echo "sha=$(git rev-parse HEAD)"
} >> $GITHUB_OUTPUT
{
echo "### Publishing"
echo "- Package: $PKG"
echo "- Version: $VERSION"
echo "- npm dist-tag: $DIST_TAG"
echo "- Trigger: $EVENT"
} >> $GITHUB_STEP_SUMMARY
# A re-run from a later commit must not publish or attach assets under a tag
# that names another commit. An annotated tag is compared by its peeled commit.
- name: Check an existing tag
env:
TAG: ${{ steps.pkg.outputs.name }}/v${{ steps.pkg.outputs.version }}
run: |
PEELED=$(git ls-remote origin "refs/tags/$TAG^{}" | cut -f1)
DIRECT=$(git ls-remote origin "refs/tags/$TAG" | cut -f1)
TAGGED=${PEELED:-$DIRECT}
HEAD_SHA=$(git rev-parse HEAD)
if [[ -n "$TAGGED" && "$TAGGED" != "$HEAD_SHA" ]]; then
echo "::error::tag $TAG points to $TAGGED, not $HEAD_SHA; dispatch the run from the tag"
exit 1
fi
# compact-linter ships a native binary per target, built on its own runner. The
# npm package downloads them, so they must reach the GitHub release first.
binaries:
name: Build compact-lint for ${{ matrix.target }}
needs: detect
if: needs.detect.outputs.name == 'compact-linter'
runs-on: ${{ matrix.runner }}
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
runner: ubuntu-24.04
- target: aarch64-unknown-linux-gnu
runner: ubuntu-24.04-arm
- target: x86_64-apple-darwin
runner: macos-15-intel
- target: aarch64-apple-darwin
runner: macos-15
steps:
- name: Harden Runner
uses: step-security/harden-runner@05e31511f85b41b11d1cf0ef85d0992719546e2c # v2.21.0
with:
egress-policy: audit
# Cargo runs build scripts, so no token stays in .git/config.
- name: Check out target ref
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.merge_commit_sha || github.ref }}
persist-credentials: false
# A dispatched branch can move after detect ran; build only the commit it checked.
- name: Check the commit
env:
DETECTED: ${{ needs.detect.outputs.sha }}
run: |
HEAD_SHA=$(git rev-parse HEAD)
if [[ "$HEAD_SHA" != "$DETECTED" ]]; then
echo "::error::checked out $HEAD_SHA, but detect checked $DETECTED; re-run all jobs"
exit 1
fi
- name: Install the pinned toolchain
run: |
CHANNEL=$(grep -m1 '^channel' rust-toolchain.toml | cut -d'"' -f2)
rustup toolchain install "$CHANNEL" --profile minimal
rustup target add ${{ matrix.target }}
rustup show active-toolchain
- name: Build
run: cargo build --release -p compact-lint --target ${{ matrix.target }}
# Every target is built on its own native runner, so the binary runs here.
- name: Smoke test
run: target/${{ matrix.target }}/release/compact-lint --version
- name: Stage the release asset
run: |
mkdir -p dist
cp target/${{ matrix.target }}/release/compact-lint dist/compact-lint-${{ matrix.target }}
- name: Upload the release asset
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: compact-lint-${{ matrix.target }}
path: dist/compact-lint-${{ matrix.target }}
if-no-files-found: error
publish:
name: Publish merged release
needs: [detect, binaries]
# `binaries` is skipped for every package but compact-linter, and a skipped
# dependency must not skip the publish.
if: >-
always() &&
needs.detect.result == 'success' &&
(needs.binaries.result == 'success' || needs.binaries.result == 'skipped')
runs-on: ubuntu-24.04
environment: compact-npm-prod # Final approval gate before npm publish
permissions:
contents: write # push the version tag and create the GitHub release
id-token: write # mint the npm OIDC credential (existing packages) and the provenance statement (both paths)
steps:
- name: Get github app token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
id: gh-app-token
with:
app-id: ${{ vars.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
- name: Check out target ref
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.merge_commit_sha || github.ref }}
token: ${{ steps.gh-app-token.outputs.token }}
# A dispatched branch can move after detect ran; build only the commit it checked.
- name: Check the commit
env:
DETECTED: ${{ needs.detect.outputs.sha }}
run: |
HEAD_SHA=$(git rev-parse HEAD)
if [[ "$HEAD_SHA" != "$DETECTED" ]]; then
echo "::error::checked out $HEAD_SHA, but detect checked $DETECTED; re-run all jobs"
exit 1
fi
- name: Setup Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: ".nvmrc"
package-manager-cache: false # Prevent cache poisoning issues
- name: Enable corepack
run: corepack enable
- name: Install dependencies
run: yarn install --immutable
- name: Build package
run: yarn build --filter=@openzeppelin/${{ needs.detect.outputs.name }}
- name: Create and push tag
env:
TAG: ${{ needs.detect.outputs.name }}/v${{ needs.detect.outputs.version }}
run: |
if git ls-remote --tags --exit-code origin "refs/tags/$TAG" >/dev/null; then
echo "tag $TAG already on origin, leaving it in place"
else
git tag "$TAG"
git push origin "$TAG"
fi
- name: Download the release binaries
if: needs.detect.outputs.name == 'compact-linter'
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
path: dist
pattern: compact-lint-*
merge-multiple: true
# Asset names only: the installed package looks each digest up by the name
# it downloads.
- name: Write the checksums
if: needs.detect.outputs.name == 'compact-linter'
working-directory: dist
run: |
sha256sum compact-lint-* > checksums.txt
cat checksums.txt
# The npm package downloads these assets on first run, so the release has
# to carry them before the package reaches npm.
- name: Create the GitHub release
if: needs.detect.outputs.name == 'compact-linter'
env:
GH_TOKEN: ${{ steps.gh-app-token.outputs.token }}
TAG: ${{ needs.detect.outputs.name }}/v${{ needs.detect.outputs.version }}
VERSION: ${{ needs.detect.outputs.version }}
DIST_TAG: ${{ needs.detect.outputs.dist_tag }}
run: |
NOTES=$(awk -v v="$VERSION" '
$0 ~ "^## " v "( |$)" { found = 1; next }
found && /^## / { exit }
found { print }
' packages/linter/CHANGELOG.md)
if [[ -z "${NOTES//[[:space:]]/}" ]]; then
NOTES="$TAG"
fi
if gh release view "$TAG" >/dev/null 2>&1; then
# A re-run keeps the published assets and ships their checksums.
ASSETS=$(gh release view "$TAG" --json assets --jq '.assets[].name')
for NAME in checksums.txt $(cd dist && ls compact-lint-*); do
if ! grep -qx "$NAME" <<< "$ASSETS"; then
echo "::error::release $TAG has no $NAME; delete the release and re-run"
exit 1
fi
done
gh release download "$TAG" --pattern checksums.txt --dir dist --clobber
else
ARGS=()
if [[ "$DIST_TAG" == "beta" ]]; then
ARGS+=(--prerelease)
fi
gh release create "$TAG" dist/* \
--title "compact-linter v$VERSION" \
--notes "$NOTES" \
"${ARGS[@]}"
fi
# The launcher verifies a download against the digests it was published with,
# so a release asset replaced later fails the check.
- name: Add the checksums to the package
if: needs.detect.outputs.name == 'compact-linter'
run: cp dist/checksums.txt packages/linter/checksums.txt
# Anything but a clean 200 or 404 fails the run, so a flaky registry can
# never read as "new package" and quietly downgrade an existing package
# from OIDC to token auth.
- name: Check whether the package is already on npm
id: registry
env:
PKG: ${{ needs.detect.outputs.name }}
run: |
if ! STATUS=$(curl -sS -o /dev/null -w '%{http_code}' \
--retry 3 --retry-all-errors --max-time 30 \
"https://registry.npmjs.org/@openzeppelin%2f$PKG"); then
echo "::error::could not reach the npm registry to look up @openzeppelin/$PKG"
exit 1
fi
case "$STATUS" in
200) FIRST_PUBLISH=false ;;
404) FIRST_PUBLISH=true ;;
*)
echo "::error::unexpected HTTP $STATUS from the npm registry for @openzeppelin/$PKG"
exit 1
;;
esac
echo "first_publish=$FIRST_PUBLISH" >> $GITHUB_OUTPUT
# The token is exported into the publish process only, never written to a
# .yarnrc.yml or an .npmrc that could be committed or cached.
- name: Publish to npm
env:
PKG: ${{ needs.detect.outputs.name }}
DIR: ${{ needs.detect.outputs.dir }}
DIST_TAG: ${{ needs.detect.outputs.dist_tag }}
FIRST_PUBLISH: ${{ steps.registry.outputs.first_publish }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
cd "packages/$DIR"
if [[ "$FIRST_PUBLISH" == "true" ]]; then
if [[ -z "$NPM_TOKEN" ]]; then
echo "::error::first publish of @openzeppelin/$PKG needs the NPM_TOKEN secret in the compact-npm-prod environment"
exit 1
fi
echo "first publish of @openzeppelin/$PKG: using NPM_TOKEN"
export YARN_NPM_AUTH_TOKEN="$NPM_TOKEN"
else
echo "existing package @openzeppelin/$PKG: OIDC"
fi
yarn npm publish --access public --provenance --tag "$DIST_TAG"