Repository navigation
114 lines (101 loc) · 4.13 KB
/
Copy pathrelease.yml
File metadata and controls
114 lines (101 loc) · 4.13 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
name: Release
# Publishes @diffbot/pi to npm via trusted publishing (OIDC; no NPM_TOKEN).
# Triggered by pushing a version tag (e.g. v0.4.0). workflow_dispatch runs the
# gates and `npm publish --dry-run` only; the publish job runs for tag pushes.
on:
push:
tags: ["v*"]
workflow_dispatch:
# Never cancel an in-flight run: cancelling a publish midway could leave npm
# and the GitHub Release out of sync. Runs for the same ref queue instead.
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
verify:
name: Verify and dry-run
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: 22
cache: npm
# The tag must match package.json so the GitHub Release can never
# disagree with the version published to npm. (No VERSION constant in
# this repo's sources.)
- name: Check tag matches package version
if: startsWith(github.ref, 'refs/tags/')
run: |
pkg=$(node -p "require('./package.json').version")
tag="${GITHUB_REF_NAME#v}"
if [ "$pkg" != "$tag" ]; then
echo "::error::Tag ${GITHUB_REF_NAME} does not match package.json version ${pkg}. Bump package.json and re-tag."
exit 1
fi
echo "Tag and package version agree: ${pkg}"
# Same gates as ci.yml (typecheck is the only one; the repo has no
# lint or test scripts and no live tests).
- run: npm ci
- run: npm run typecheck
# The package ships TypeScript sources (extensions/, skills/), so there
# is no build step.
- name: Publish dry run
run: npm publish --dry-run --access public
publish:
name: Publish to npm and GitHub
needs: verify
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
# Required for npm trusted publishing and provenance attestation.
id-token: write
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: 22
registry-url: "https://registry.npmjs.org"
# Trusted publishing needs npm >= 11.5.1; Node 22 ships older.
- name: Update npm
run: |
npm install -g npm@latest
npm --version
# No token: npm authenticates via the trusted publisher configured on
# npmjs.com (org diffbot, repo diffbot-pi, workflow release.yml).
- name: Publish to npm
run: npm publish --access public --provenance
# A final release also moves `next`, so `next` is never behind `latest`.
# Uses npm trusted publishing (OIDC) for `npm dist-tag`, which needs npm
# >= 11.21.0 / 12.2.0 and "Allow npm dist-tag" enabled on this package's
# trusted publisher at npmjs.com (off by default). The version is already
# published at this point, so a failure only warns and never fails the run.
- name: Point next at final release
if: github.event_name == 'push' && github.ref_type == 'tag'
run: |
set -uo pipefail
name=$(node -p 'require("./package.json").name')
version=$(node -p 'require("./package.json").version')
case "$version" in
*-*) echo "Prerelease ${version}: next was set by publish."; exit 0 ;;
esac
if npm dist-tag add "${name}@${version}" next; then
echo "next -> ${name}@${version}"
else
echo "::warning::Could not point next at ${name}@${version}. Enable 'Allow npm dist-tag' on the trusted publisher for ${name} at npmjs.com, or run: npm dist-tag add ${name}@${version} next"
fi
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then
echo "Release $GITHUB_REF_NAME already exists; skipping."
else
gh release create "$GITHUB_REF_NAME" --title "$GITHUB_REF_NAME" --generate-notes --verify-tag
fi