Repository navigation
111 lines (96 loc) · 4.01 KB
/
Copy pathpublish.yml
File metadata and controls
111 lines (96 loc) · 4.01 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
name: Publish
# Publish to npm from CI with no long-lived token. Auth is npm "trusted
# publishing" (OIDC): npmjs.com is configured to trust this repo + workflow, so
# GitHub's short-lived OIDC identity authenticates the publish and `--provenance`
# attaches a verifiable provenance attestation. No NPM_TOKEN secret is stored.
#
# Release flow: bump version + CHANGELOG on main, then push a matching tag:
# git tag v0.8.2 && git push origin v0.8.2
# The tag must equal "v<version from package.json>" or the job fails before
# publishing. `workflow_dispatch` publishes the current package.json version.
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
permissions:
# contents: write so the tag also gets a GitHub Release - npm was being
# published while the repo's Releases page sat 8 versions behind (0.11.0),
# so anyone browsing GitHub saw a stale "latest".
contents: write
id-token: write
jobs:
verify-platforms:
uses: ./.github/workflows/ci.yml
permissions:
contents: read
publish:
name: publish to npm
needs: verify-platforms
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org
cache: npm
- name: Install system dependencies
run: |
if command -v rg >/dev/null 2>&1; then
echo "ripgrep already present: $(rg --version | head -1)"
exit 0
fi
for attempt in 1 2 3; do
timeout 300 sudo apt-get update || echo "apt-get update timed out; trying the install anyway"
if timeout 300 sudo apt-get install -y ripgrep; then break; fi
[ "$attempt" = 3 ] && exit 1
echo "ripgrep install failed (attempt $attempt); retrying in $((20 * attempt))s"
sleep $((20 * attempt))
done
- name: Upgrade npm for trusted publishing (OIDC)
# Pinned to the 11.x line: OIDC trusted publishing needs npm >= 11.5.1,
# and npm@latest bit us when 12.0.0 shipped with a broken provenance
# path (publish --dry-run dies with MODULE_NOT_FOUND: sigstore) and a
# changed `pack --json` shape. Bump deliberately, not implicitly.
run: npm install -g npm@11
- name: Install dependencies
run: npm ci
- name: Verify tag matches package.json version
if: startsWith(github.ref, 'refs/tags/')
run: |
pkg_version="$(node -p "require('./package.json').version")"
tag_version="${GITHUB_REF_NAME#v}"
if [ "$pkg_version" != "$tag_version" ]; then
echo "Tag $GITHUB_REF_NAME does not match package.json version $pkg_version" >&2
exit 1
fi
- name: Build
run: npm run build
- name: Run release metadata check
run: npm run release:check -- --metadata-only
- name: Release verification
run: npm run release:verify
- name: Publish (provenance, trusted publishing)
run: npm publish --provenance --access public --ignore-scripts
- name: GitHub Release from CHANGELOG
if: startsWith(github.ref, 'refs/tags/')
env:
GH_TOKEN: ${{ github.token }}
run: |
version="${GITHUB_REF_NAME#v}"
# Take the section for this version out of CHANGELOG.md; fall back to
# a pointer rather than failing the publish that already succeeded.
notes="$(awk -v v="$version" '
$0 == "## " v || $0 == "## [" v "]" || index($0, "## [" v "] - ") == 1 { on = 1; next }
on && /^## / { exit }
on { print }
' CHANGELOG.md)"
if [ -z "$(printf "%s" "$notes" | tr -d "[:space:]")" ]; then
notes="See CHANGELOG.md for $version."
fi
printf "%s\n" "$notes" > /tmp/release-notes.md
gh release create "$GITHUB_REF_NAME" --title "prodex $version" --notes-file /tmp/release-notes.md