forked from defi-wonderland/aztec-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (120 loc) · 6.53 KB
/
Copy pathrelease.yml
File metadata and controls
134 lines (120 loc) · 6.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Release
# Tag-driven releases publish the tagged version. Every publish — prerelease and
# stable alike — runs in the reviewer-gated `Production` environment. npm supports
# only one trusted publisher per package with one optional environment claim, so
# pinning that publisher to `Production` requires every publishing job to run there.
# It also makes the `rc` a faithful rehearsal: it exercises the same environment and
# credential path the stable release will use, instead of a parallel one that can
# drift out from under it.
on:
push:
tags:
- 'v*'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# ══════════════════════════════════════════════════════════════════════════════
# PUBLISH JOB
# ══════════════════════════════════════════════════════════════════════════════
release:
name: Publish
# Single environment for every tag — see the note at the top of this file.
# Prereleases pay one approval click; that is the cost of the npm-side pin.
environment: Production
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: read # checkout (the tag already exists)
id-token: write # OIDC token for npm Trusted Publishing
env:
PROJECT_NAME: '@aztec-foundation/aztec-standards'
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
fetch-depth: 0
# Toolchain is pinned via package.json `config.aztecVersion`: this action
# reads that field and installs the matching Aztec version.
- name: Setup Aztec environment
id: setup-aztec
uses: AztecProtocol/aztec-ci-actions/actions/setup-aztec@431859e477234b8690eb1f80d1305d2e34f10f1b # v0.1.1
with:
start-pxe: 'false'
run-codegen: 'true'
# Validate that the tag (v5.0.0) matches package.json and derive the npm
# dist-tag: `latest` for a final release, or the prerelease identifier
# (rc / beta / nightly) so consumers can `npm i pkg@rc`.
- name: Resolve release metadata
id: meta
run: |
VERSION="${GITHUB_REF_NAME#v}"
PKG_VERSION=$(node -p "require('./package.json').version")
echo "Tag version: $VERSION"
echo "package.json version: $PKG_VERSION"
if [ "$VERSION" != "$PKG_VERSION" ]; then
echo "::error::Tag ${GITHUB_REF_NAME} (version $VERSION) does not match package.json version ($PKG_VERSION)."
exit 1
fi
if [[ "$VERSION" == *-* ]]; then
PRERELEASE="${VERSION#*-}" # e.g. "rc.2"
DIST_TAG="${PRERELEASE%%.*}" # e.g. "rc"
else
DIST_TAG="latest"
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "dist_tag=$DIST_TAG" >> "$GITHUB_OUTPUT"
echo "Resolved npm dist-tag: $DIST_TAG"
- name: Build package
run: yarn build
- name: Setup Node.js for NPM publish
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
# npm Trusted Publishing requires Node >=22.14.0 and npm >=11.5.1.
node-version: '22.14.0'
registry-url: 'https://registry.npmjs.org'
- name: Install OIDC-capable npm
run: npm install --global npm@11.5.1
# npm versions are immutable. OIDC supports publish but not dist-tag mutation,
# so reruns verify the existing dist-tag rather than trying to repair it.
- name: Publish to NPM with OIDC
run: |
cd "export/${PROJECT_NAME}"
VERSION="${{ steps.meta.outputs.version }}"
DIST_TAG="${{ steps.meta.outputs.dist_tag }}"
if npm view "${PROJECT_NAME}@${VERSION}" version >/dev/null 2>&1; then
TAGGED_VERSION=$(npm view "${PROJECT_NAME}@${DIST_TAG}" version 2>/dev/null || true)
if [ "$TAGGED_VERSION" != "$VERSION" ]; then
echo "::error::${PROJECT_NAME}@${VERSION} is already published, but dist-tag '${DIST_TAG}' points to '${TAGGED_VERSION:-nothing}'. OIDC cannot mutate dist-tags; repair it manually with an authorized npm account."
exit 1
fi
echo "::notice::${PROJECT_NAME}@${VERSION} already published and dist-tag '${DIST_TAG}' is correct — skipping publish."
else
# Trusted Publishing generates provenance automatically for public packages.
npm publish --access public --tag "${DIST_TAG}"
fi
# Post-publish smoke test: install the just-published package from the registry (clean dir)
# and confirm it resolves to the expected version. Catches "published but unusable"
# (bad files/exports/version). The publish already succeeded and npm is immutable, so a
# persistent miss here is a WARNING (registry propagation lag — common on a first publish),
# NOT a release failure. A version MISMATCH after install still hard-fails.
- name: Smoke-test published package
run: |
VERSION="${{ steps.meta.outputs.version }}"
DIST_TAG="${{ steps.meta.outputs.dist_tag }}"
workdir="$(mktemp -d)"
cd "$workdir"
npm init -y >/dev/null
# First publishes propagate slowly; --prefer-online bypasses the negative cache. Back off ~2min.
installed=false
for attempt in 1 2 3 4 5 6 7 8; do
if npm install --prefer-online "${PROJECT_NAME}@${VERSION}"; then installed=true; break; fi
echo "install attempt ${attempt} failed; waiting 15s for registry propagation..."
sleep 15
done
if [ "$installed" = true ]; then
node -e "const p = require('${PROJECT_NAME}/package.json'); if (p.version !== '${VERSION}') { throw new Error('installed ' + p.version + ', expected ${VERSION}'); } console.log('smoke ok:', p.name, p.version);"
echo "::notice::Smoke test passed: ${PROJECT_NAME}@${VERSION} installs and resolves (dist-tag ${DIST_TAG})."
else
echo "::warning::${PROJECT_NAME}@${VERSION} published successfully but did not resolve from the registry within the wait window (propagation lag — common on a first publish). Verify manually: npm view ${PROJECT_NAME}@${VERSION} --prefer-online"
fi