Repository navigation
96 lines (87 loc) · 3.61 KB
/
Copy pathrelease.yml
File metadata and controls
96 lines (87 loc) · 3.61 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
on:
workflow_dispatch:
inputs:
version:
description: 'Version to release: a semver bump (patch/minor/major/prerelease) or an explicit version (e.g. 0.2.0)'
required: true
default: patch
permissions:
contents: write # push the version commit/tag and create the GitHub Release
id-token: write # npm provenance
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: pnpm/action-setup@v6
with:
version: 10
- uses: actions/setup-node@v7
with:
node-version: 22
registry-url: https://registry.npmjs.org
cache: pnpm
- run: pnpm install --frozen-lockfile
- run: pnpm run ci
- run: pnpm run typecheck
- run: pnpm run check:docs
- run: pnpm run test
- run: pnpm run build
- name: Bump version
id: bump
run: |
OLD="$(node -p "require('./package.json').version")"
npm version "${{ inputs.version }}" --no-git-tag-version --allow-same-version >/dev/null
NEW="$(node -p "require('./package.json').version")"
echo "version=v${NEW}" >> "$GITHUB_OUTPUT"
if [ "$OLD" = "$NEW" ]; then
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "::notice::Version is already ${NEW}; skipping the bump commit but still releasing."
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
# CHANGELOG.md is rebuilt from the commit history (cliff.toml) with the new version as the latest release, and the same section becomes the GitHub Release notes.
- name: Generate changelog
uses: orhun/git-cliff-action@v4
with:
config: cliff.toml
args: --tag ${{ steps.bump.outputs.version }}
env:
OUTPUT: CHANGELOG.md
- name: Generate release notes
uses: orhun/git-cliff-action@v4
with:
config: cliff.toml
args: --unreleased --strip all --tag ${{ steps.bump.outputs.version }}
env:
OUTPUT: RELEASE_NOTES.md
# pnpm doesn't do the OIDC exchange, so publish uses npm directly
- run: npm install -g npm@11
- run: npm publish --access public --provenance
- name: Commit, tag and push
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Only commit when the bump or the regenerated changelog changed something; otherwise just tag and release.
git add package.json CHANGELOG.md
if ! git diff --cached --quiet; then
git commit -m "release: ${{ steps.bump.outputs.version }}"
fi
if ! git rev-parse -q --verify "refs/tags/${{ steps.bump.outputs.version }}" >/dev/null; then
git tag "${{ steps.bump.outputs.version }}"
fi
git push origin HEAD "${{ steps.bump.outputs.version }}"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
# The notes are the new changelog section minus its version heading. Re-releasing a version with no new commits leaves it empty, so fall back to GitHub's generated notes.
if [ -s RELEASE_NOTES.md ]; then
sed -i '1,2d' RELEASE_NOTES.md
gh release create "${{ steps.bump.outputs.version }}" --title "${{ steps.bump.outputs.version }}" --notes-file RELEASE_NOTES.md
else
gh release create "${{ steps.bump.outputs.version }}" --title "${{ steps.bump.outputs.version }}" --generate-notes
fi