Skip to content

Commit 65733fa

Browse files
committed
updated version tag release workflow
1 parent 3a4813a commit 65733fa

1 file changed

Lines changed: 63 additions & 13 deletions

File tree

.github/workflows/main.yml

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,77 @@
1-
21
name: Create release
32

43
on:
54
push:
6-
branches:
7-
- master
85
tags:
9-
- '*.*.*'
6+
- 'v[0-9]+.[0-9]+.[0-9]+'
7+
- '[0-9]+.[0-9]+.[0-9]+'
8+
9+
permissions:
10+
contents: write
1011

1112
jobs:
12-
build:
13+
release:
1314
runs-on: ubuntu-latest
1415

1516
steps:
16-
- uses: actions/checkout@v2
17+
- name: Resolve version from tag
18+
id: version
19+
run: |
20+
VERSION="${GITHUB_REF_NAME#v}"
21+
TAG="${GITHUB_REF_NAME}"
22+
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
23+
echo "Tag must be a semver version (for example v1.2.3 or 1.2.3)."
24+
exit 1
25+
fi
26+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
27+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
28+
29+
- uses: actions/checkout@v4
30+
with:
31+
ref: ${{ github.ref }}
32+
fetch-depth: 0
33+
34+
- name: Bump package.json and move tag onto that commit
35+
run: |
36+
VERSION="${{ steps.version.outputs.version }}"
37+
TAG="${{ steps.version.outputs.tag }}"
38+
39+
git fetch origin master
40+
41+
if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/master)" ]; then
42+
echo "Tag must point to the current tip of master."
43+
echo "Push master first, then tag that commit and push the tag."
44+
exit 1
45+
fi
46+
47+
git config user.name "github-actions[bot]"
48+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
49+
50+
CURRENT="$(jq -r '.version' package.json)"
51+
if [ "$CURRENT" = "$VERSION" ]; then
52+
echo "package.json already at $VERSION"
53+
else
54+
jq --arg version "$VERSION" '.version = $version' package.json > package.json.tmp
55+
mv package.json.tmp package.json
56+
git add package.json
57+
git commit -m "chore: release $TAG [skip ci]"
58+
fi
59+
60+
git tag -f "$TAG"
61+
git push origin HEAD:master
62+
git push origin "refs/tags/$TAG" --force
1763
18-
- name: Zip Folder
19-
run: zip -r ${{ github.event.repository.name }}.zip .
64+
- name: Create package archive
65+
run: |
66+
zip -r "${{ github.event.repository.name }}.zip" . \
67+
-x "*.git*" \
68+
-x ".github/*" \
69+
-x ".cursorignore" \
70+
-x "Tests/*"
2071
21-
- name: Release
22-
uses: softprops/action-gh-release@v1
23-
if: startsWith(github.ref, 'refs/tags/')
72+
- name: Create GitHub Release
73+
uses: softprops/action-gh-release@v2
2474
with:
75+
tag_name: ${{ steps.version.outputs.tag }}
2576
files: ${{ github.event.repository.name }}.zip
26-
env:
27-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
generate_release_notes: true

0 commit comments

Comments
 (0)