-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (108 loc) · 3.97 KB
/
Copy pathrelease.yml
File metadata and controls
126 lines (108 loc) · 3.97 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
115
116
117
118
119
120
121
122
123
124
125
126
name: Release
on:
workflow_run:
workflows:
- CI
types:
- completed
branches:
- master
workflow_dispatch:
inputs:
version:
description: Explicit version to release, such as 0.1.0 or v0.1.0.
required: false
type: string
permissions:
contents: write
id-token: write
concurrency:
group: release
cancel-in-progress: false
jobs:
publish:
name: Publish to npm
runs-on: ubuntu-latest
if: >-
(github.event_name == 'workflow_run' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'master') ||
(github.event_name == 'workflow_dispatch' &&
github.ref == 'refs/heads/master')
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v5
with:
node-version: 24
registry-url: https://registry.npmjs.org
package-manager-cache: false
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
- name: Install git-cliff
uses: taiki-e/install-action@git-cliff
- name: Resolve release version
id: version
env:
VERSION_OVERRIDE: ${{ github.event.inputs.version || '' }}
run: |
set -euo pipefail
current_version="$(node -p "require('./package.json').version")"
if [ -n "$VERSION_OVERRIDE" ]; then
next_version="${VERSION_OVERRIDE#v}"
if ! node -e "process.exit(/^[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(process.argv[1]) ? 0 : 1)" "$next_version"; then
echo "Invalid version override: $VERSION_OVERRIDE" >&2
exit 1
fi
echo "Using explicit version override: $next_version"
else
next_version="$(git-cliff --bumped-version | sed 's/^v//')"
fi
if [ -z "$next_version" ]; then
echo "git-cliff did not infer a version" >&2
exit 1
fi
if [ -z "$VERSION_OVERRIDE" ] && [ "$next_version" = "$current_version" ]; then
echo "git-cliff inferred $next_version, which matches package.json; skipping release."
echo "should_release=false" >> "$GITHUB_OUTPUT"
exit 0
fi
if git rev-parse --verify --quiet "v$next_version" >/dev/null; then
echo "Release tag v$next_version already exists" >&2
exit 1
fi
echo "should_release=true" >> "$GITHUB_OUTPUT"
echo "version=$next_version" >> "$GITHUB_OUTPUT"
echo "tag=v$next_version" >> "$GITHUB_OUTPUT"
- name: Install dependencies
if: steps.version.outputs.should_release == 'true'
run: pnpm install --frozen-lockfile
- name: Bump package version
if: steps.version.outputs.should_release == 'true'
run: npm pkg set version="${{ steps.version.outputs.version }}"
- name: Build
if: steps.version.outputs.should_release == 'true'
run: pnpm run --if-present build
- name: Commit release updates
if: steps.version.outputs.should_release == 'true'
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add package.json
if git diff --cached --quiet; then
git commit --allow-empty -m "chore(release): ${{ steps.version.outputs.tag }}"
else
git commit -m "chore(release): ${{ steps.version.outputs.tag }}"
fi
git tag "${{ steps.version.outputs.tag }}"
git push origin HEAD:master
git push origin "${{ steps.version.outputs.tag }}"
- name: Publish to npm with provenance
if: steps.version.outputs.should_release == 'true'
run: npm publish --provenance --access public