Repository navigation
96 lines (85 loc) · 3.94 KB
/
Copy pathrelease-cli.yml
File metadata and controls
96 lines (85 loc) · 3.94 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
name: Release CLI
# Releases the `spoolsync` npm package straight from main:
# After CI passes on main with releasable CLI changes, release-it bumps packages/spoolsync-cli/package.json,
# updates the changelog and bun.lock, commits to main, tags, creates the GitHub release and publishes to npm.
# Pushing to the protected main branch needs a token that may bypass branch protection, so the workflow
# uses the RELEASE_TOKEN secret instead of GITHUB_TOKEN:
# - Fine-grained PAT (or a GitHub App token) with Contents: read/write on this repository.
# - Add the token's owner (or the app) to the main ruleset's bypass list, or to "Allow specified actors
# to bypass required pull requests" in classic branch protection.
# The release commit subject ends in [skip ci] (see release-it's git.commitMessage in
# packages/spoolsync-cli/package.json), so CI does not run on it. Its subject is also excluded from the
# releasable check below, so a later run never releases because of it.
# npm auth uses Trusted Publishing (OIDC), so no NPM_TOKEN secret is needed. Configure the trusted
# publisher on npmjs.com: repository robertbaker/spoolsync, workflow `release-cli.yml`.
on:
workflow_run:
workflows: [CI]
types: [completed]
branches: [main]
workflow_dispatch:
concurrency:
group: release-cli
cancel-in-progress: false
permissions:
contents: read # pushes use RELEASE_TOKEN
id-token: write # npm Trusted Publishing (OIDC) and provenance
actions: read # read the triggering CI workflow run
jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 15
# Only after a green CI run on main.
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push')
steps:
- uses: actions/checkout@v7
with:
ref: main
fetch-depth: 0
fetch-tags: true
token: ${{ secrets.RELEASE_TOKEN }}
- name: Decide what to do
id: gate
run: |
# If main moved on since CI ran, a newer CI run will trigger its own release.
if [ "${{ github.event_name }}" = "workflow_run" ] \
&& [ "$(git rev-parse HEAD)" != "${{ github.event.workflow_run.head_sha }}" ]; then
echo "main has advanced past the commit CI validated; skipping."
echo "release=false" >> "$GITHUB_OUTPUT"
exit 0
fi
last=$(git describe --tags --abbrev=0 --match 'spoolsync-cli-v[0-9]*' 2>/dev/null || true)
range=${last:+$last..HEAD}
echo "Last release tag: ${last:-none}"
releasable=$(git log --format=%s $range -- packages/spoolsync-cli packages/spoolsync-core ':!*.md' \
| grep -Ev '^(docs|style)(\(.+\))?!?:' \
| grep -Ev '^chore\(spoolsync-cli\): release' || true)
if [ -z "$releasable" ] && [ "${{ github.event_name }}" != "workflow_dispatch" ]; then
echo "Only docs/style changes since the last release; skipping."
echo "release=false" >> "$GITHUB_OUTPUT"
else
printf 'Releasable commits:\n%s\n' "$releasable"
echo "release=true" >> "$GITHUB_OUTPUT"
fi
- uses: oven-sh/setup-bun@v2
if: steps.gate.outputs.release == 'true'
# Node 24 ships npm >= 11.5.1, which is required for Trusted Publishing.
- uses: actions/setup-node@v7
if: steps.gate.outputs.release == 'true'
with:
node-version: 24
- name: Install dependencies
if: steps.gate.outputs.release == 'true'
run: bun install --frozen-lockfile
- name: Release
if: steps.gate.outputs.release == 'true'
working-directory: packages/spoolsync-cli
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
bunx release-it --ci