Repository navigation
executable file
·102 lines (91 loc) · 3.55 KB
/
Copy pathrelease.yml
File metadata and controls
executable file
·102 lines (91 loc) · 3.55 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
name: Release
on:
workflow_dispatch:
push:
tags: ['v*']
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # npm trusted publishing (OIDC); no long-lived NPM_TOKEN
steps:
- uses: actions/checkout@v7
- uses: pnpm/action-setup@v6
with:
version: 11.7.0
- uses: actions/setup-node@v7
with:
node-version: 24
cache: pnpm
# No `registry-url` on purpose: it writes
# `//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}` into a local
# .npmrc, and with no long-lived token that line is an EMPTY bearer
# token - the registry then answers 404 on PUT instead of letting npm
# perform the OIDC trusted-publishing exchange.
- name: Install
run: pnpm install --frozen-lockfile
- name: Gate
run: |
pnpm typecheck
pnpm test
pnpm run lint
pnpm build
pnpm run verify:self-contained
pnpm run verify:artifacts
pnpm run check:readmes
- name: Verify the changelog names this version
run: |
VERSION="${GITHUB_REF_NAME#v}"
grep -q "## \[${VERSION}\]" CHANGELOG.md || { echo "CHANGELOG.md has no section for ${VERSION}"; exit 1; }
# Trusted publishing: the OIDC token (id-token: write above) replaces a
# long-lived NPM_TOKEN. npm >= 11.5.1 is required for the exchange.
- name: Upgrade npm and show what the publish will authenticate with
run: |
npm install -g npm@^11.5.1
echo "npm: $(npm --version)"
echo "registry: $(npm config get registry)"
if [ -f .npmrc ]; then echo "--- workspace .npmrc ---"; cat .npmrc; else echo "no workspace .npmrc"; fi
if [ -n "${ACTIONS_ID_TOKEN_REQUEST_TOKEN:-}" ]; then echo "OIDC request TOKEN: present"; else echo "OIDC request TOKEN: MISSING"; fi
- name: Publish to npm
env:
# npm's OIDC exchange never throws: a failure is only visible at verbose
# level, otherwise the step just fails with ENEEDAUTH and no reason.
NPM_CONFIG_LOGLEVEL: verbose
run: |
version="$(node -p "require('./package.json').version")"
if npm view "dsh-github-bot@${version}" version >/dev/null 2>&1; then
echo "dsh-github-bot@${version} is already published; skipping npm publish"
else
# The registry read side can lag a successful publish, so a re-pushed tag
# can hit E409 ("Cannot publish over previously staged version"). That
# means the version already exists, so report it as done.
set +e
out="$(npm publish --access public --provenance 2>&1)"
status=$?
set -e
printf '%s\n' "$out"
if [ "$status" -ne 0 ]; then
if printf '%s' "$out" | grep -q 'E409'; then
echo "already on the registry (E409); treating the publish as done"
else
exit "$status"
fi
fi
fi
release:
needs: publish
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v7
- name: Release
env:
GH_TOKEN: ${{ github.token }}
run: |
if gh release view "${{ github.ref_name }}" >/dev/null 2>&1; then
echo "release ${{ github.ref_name }} already exists; skipping"
exit 0
fi
gh release create "${{ github.ref_name }}" --generate-notes