-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (80 loc) · 2.85 KB
/
auto-release.yml
File metadata and controls
96 lines (80 loc) · 2.85 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
94
95
96
name: Auto Versioned Release
on:
push:
branches: [main]
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get latest tag from remote
id: get_tag
run: |
# Fetch all tags to ensure we see tags even if they aren't in this branch's history
git fetch --tags --force
# Find the highest version tag using natural version sorting
# Filters for tags starting with 'v'
tag=$(git tag -l "v*" --sort=-v:refname | head -n 1)
# If no tag is found, start at v1.0.0
if [ -z "$tag" ]; then
tag="v1.0.0"
fi
echo "latest_tag=$tag" >> $GITHUB_OUTPUT
echo "Found latest tag: $tag"
- name: Bump version (semantic roll over)
id: bump
run: |
tag="${{ steps.get_tag.outputs.latest_tag }}"
base=${tag#v}
IFS='.' read -r major minor patch <<< "$base"
# Logic: Rolls over to next decimal place if value is 9
if [ "$patch" -lt 9 ]; then
patch=$((patch + 1))
else
patch=0
if [ "$minor" -lt 9 ]; then
minor=$((minor + 1))
else
minor=0
major=$((major + 1))
fi
fi
new_tag="v${major}.${minor}.${patch}"
echo "new_tag=$new_tag" >> $GITHUB_OUTPUT
echo "New calculated tag: $new_tag"
- name: Generate changelog
id: changelog
run: |
prev=${{ steps.get_tag.outputs.latest_tag }}
# If the latest_tag was the fallback v1.0.0 and doesn't actually exist in git
if git rev-parse "$prev" >/dev/null 2>&1; then
log=$(git log $prev..HEAD --pretty=format:"- %s")
else
log=$(git log --pretty=format:"- %s")
fi
# Handle empty logs
if [ -z "$log" ]; then log="- No changes documented."; fi
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$log" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create and Push Tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag ${{ steps.bump.outputs.new_tag }}
git push origin ${{ steps.bump.outputs.new_tag }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.bump.outputs.new_tag }}
name: "${{ steps.bump.outputs.new_tag }}"
body: |
## Changes since last release
${{ steps.changelog.outputs.changelog }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}