Repository navigation
55 lines (49 loc) · 1.88 KB
/
Copy pathrelease.yml
File metadata and controls
55 lines (49 loc) · 1.88 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
name: 🚀 Release — Tag
# Merging a release/X.Y.Z PR into main tags main as vX.Y.Z, which runs the publish workflow
# (gate, npm, GitHub Release, docs). The version bump itself arrived with the merge: the
# release-branch workflow put it on the branch when the branch was created. Can also be run
# from the Actions tab, which tags main with whatever version package.json has.
on:
pull_request:
types: [closed]
branches: [main]
workflow_dispatch:
jobs:
tag:
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/'))
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout main
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
token: ${{ secrets.GH_PAT }}
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Version from package.json (must match the branch name)
id: version
env:
HEAD_REF: ${{ github.event.pull_request.head.ref }}
run: |
VERSION=$(node -p "require('./package.json').version")
if [ -n "$HEAD_REF" ]; then
FROM_BRANCH="${HEAD_REF#release/}"; FROM_BRANCH="${FROM_BRANCH#v}"
if [ "$FROM_BRANCH" != "$VERSION" ]; then
echo "ERROR: branch says $FROM_BRANCH but package.json on main says $VERSION" && exit 1
fi
fi
if git ls-remote --exit-code --tags origin "v$VERSION" >/dev/null 2>&1; then
echo "ERROR: tag v$VERSION already exists" && exit 1
fi
echo "Tagging v$VERSION"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Tag
run: |
git tag "v${{ steps.version.outputs.version }}"
git push origin "v${{ steps.version.outputs.version }}"