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
54name: Release
# When the root package.json version is bumped and merged to main, tag the
# commit vX.Y.Z and publish a GitHub Release with auto-generated notes.
# Bumping the version is a deliberate PR change; publishing is automatic.
on:
push:
branches: ["main"]
paths:
- 'package.json'
- '.github/workflows/release.yml'
permissions:
contents: write
concurrency:
group: release
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Read version from package.json
id: version
run: echo "version=$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT"
- name: Check whether this release already exists
id: check
env:
GH_TOKEN: ${{ github.token }}
run: |
if gh release view "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> "$GITHUB_OUTPUT"
echo "v${{ steps.version.outputs.version }} already released — nothing to do."
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Create tag and GitHub Release
if: steps.check.outputs.exists == 'false'
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "v${{ steps.version.outputs.version }}" \
--target "${{ github.sha }}" \
--title "v${{ steps.version.outputs.version }}" \
--generate-notes