-
Notifications
You must be signed in to change notification settings - Fork 266
93 lines (84 loc) · 3.1 KB
/
release.yml
File metadata and controls
93 lines (84 loc) · 3.1 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
name: Release
on:
workflow_dispatch:
inputs:
bump:
description: "patch | minor | major | prerelease | explicit version (e.g. 1.4.0)"
required: true
default: patch
preid:
description: "Prerelease identifier (only used with bump=prerelease)"
type: choice
options: [beta]
default: beta
pull_request:
types: [closed]
branches: [main]
permissions:
contents: write
pull-requests: write
env:
GH_TOKEN: ${{ github.token }}
jobs:
# Opens a PR that bumps all package versions. Add release notes to
# RELEASES.md in the PR before merging.
prepare:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: main
- uses: actions/setup-node@v6
with:
node-version: "22"
- name: Bump versions
id: bump
run: |
VERSION=$(node scripts/bump-version.mjs "${{ inputs.bump }}" --preid="${{ inputs.preid }}")
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Create release PR
run: |
VERSION="${{ steps.bump.outputs.version }}"
BRANCH="release/v$VERSION"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b "$BRANCH"
git add -u
git commit -m "chore: release v$VERSION"
git push -u origin "$BRANCH"
gh label create release --color B60205 --description "Release PR" 2>/dev/null || true
gh pr create \
--title "chore: release v$VERSION" \
--body "Bumps all packages to \`$VERSION\`. Add release notes to \`RELEASES.md\` before merging. Merging this PR will automatically tag and create the GitHub Release, which triggers npm-publish." \
--label release \
--base main
# When a release PR is merged, tag the commit and create the GitHub Release.
# This triggers the npm-publish workflow.
tag:
if: >
github.event_name == 'pull_request' &&
github.event.pull_request.merged == true &&
contains(github.event.pull_request.labels.*.name, 'release')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}
- name: Create tag and release
env:
# PAT so the `release: published` event triggers npm-publish
# (events from GITHUB_TOKEN don't cascade to other workflows)
GH_TOKEN: ${{ secrets.RELEASE_TOKEN }}
run: |
VERSION=$(node -p "require('./package.json').version")
TAG="v$VERSION"
if gh release view "$TAG" --repo ${{ github.repository }} >/dev/null 2>&1; then
echo "Release $TAG already exists, skipping"
exit 0
fi
git tag "$TAG"
git push origin "$TAG" || echo "tag already on remote"
PRERELEASE=""
[[ "$VERSION" == *-* ]] && PRERELEASE="--prerelease"
gh release create "$TAG" --title "$TAG" --generate-notes $PRERELEASE