-
Notifications
You must be signed in to change notification settings - Fork 3
90 lines (78 loc) · 3.03 KB
/
release.yml
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
name: Create Tag and Release
on:
push:
branches:
- main
jobs:
release:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, 'no-release') }}
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get latest tag
id: get_latest_tag
run: |
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "latest_tag=$latest_tag" >> $GITHUB_OUTPUT
- name: Bump version and update package.json
id: tag_version
run: |
latest_tag="${{ steps.get_latest_tag.outputs.latest_tag }}"
echo "Latest tag: $latest_tag"
if [[ $latest_tag =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
major=${BASH_REMATCH[1]}
minor=${BASH_REMATCH[2]}
patch=${BASH_REMATCH[3]}
new_tag="v$major.$minor.$((patch + 1))"
else
new_tag="v0.0.1"
fi
echo "New tag: $new_tag"
# Check if the new tag and the latest tag are the same. If so, exit.
if [[ "$latest_tag" == "$new_tag" ]]; then
echo "New tag and latest tag are the same ($new_tag), skipping version bump."
exit 0
fi
# Update package.json version (without the 'v' prefix)
new_version="${new_tag:1}"
npm version $new_version --no-git-tag-version
# Stage and commit package.json changes
git config user.name github-actions
git config user.email github-actions@github.com
git add package.json package-lock.json
git commit -m "chore: bump version to ${new_tag}"
git push
# Create and push new tag
git tag "$new_tag"
git push origin "$new_tag"
echo "new_tag=$new_tag" >> $GITHUB_OUTPUT
- name: Generate Release Notes
id: release_notes
run: |
# Get commit messages since last tag
if [ "${{ steps.get_latest_tag.outputs.latest_tag }}" = "v0.0.0" ]; then
COMMITS="- Initial Release"
else
COMMITS=$(git log "${{ steps.get_latest_tag.outputs.latest_tag }}"..HEAD --pretty=format:"- %s")
fi
echo "commits<<EOF" >> $GITHUB_OUTPUT
echo "$COMMITS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GHCR_PAT }}
with:
tag_name: ${{ steps.tag_version.outputs.new_tag }}
release_name: Release ${{ steps.tag_version.outputs.new_tag }}
body: |
# What's Changed
${{ steps.release_notes.outputs.commits }}
**Full Changelog**: https://github.com/${{ github.repository }}/commits/${{ steps.tag_version.outputs.new_tag }}
draft: false
prerelease: false