-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (124 loc) · 5.14 KB
/
release.yml
File metadata and controls
145 lines (124 loc) · 5.14 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: Release
on:
push:
branches: [main]
workflow_dispatch:
inputs:
version:
description: 'Version bump (major, minor, patch)'
default: 'patch'
type: choice
options:
- major
- minor
- patch
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Fetch all tags
run: git fetch --tags --force origin
- name: Determine version bump
id: version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
BUMP="${{ github.event.inputs.version }}"
else
# Get commits on main since last tag
LAST_TAG=$(git describe --tags --abbrev=0 origin/main 2>/dev/null || echo "none")
# Get commit messages
if [ "$LAST_TAG" = "none" ]; then
COMMITS=$(git log --format=%s origin/main)
else
COMMITS=$(git log --format=%s $LAST_TAG..origin/main 2>/dev/null || git log --format=%s origin/main)
fi
# Count features and fixes
FEAT_COUNT=$(echo "$COMMITS" | grep -c "^feat:" || true)
FIX_COUNT=$(echo "$COMMITS" | grep -c "^fix:" || true)
# Remove any whitespace
FEAT_COUNT=$(echo "$FEAT_COUNT" | tr -d ' ')
FIX_COUNT=$(echo "$FIX_COUNT" | tr -d ' ')
echo "LAST_TAG=$LAST_TAG FEAT_COUNT=$FEAT_COUNT FIX_COUNT=$FIX_COUNT"
if [ "$FEAT_COUNT" = "" ] || [ "$FEAT_COUNT" -eq 0 ]; then
if [ "$FIX_COUNT" = "" ] || [ "$FIX_COUNT" -eq 0 ]; then
BUMP="none"
else
BUMP="patch"
fi
else
BUMP="minor"
fi
fi
echo "bump=$BUMP" >> $GITHUB_OUTPUT
- name: Bump version and tag
id: bump
if: steps.version.outputs.bump != 'none'
run: |
LAST_TAG=$(git describe --tags --abbrev=0 origin/main 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
MAJOR=1; MINOR=0; PATCH=0
else
VERSION=$(echo $LAST_TAG | sed 's/v//')
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
MAJOR=${MAJOR:-0}; MINOR=${MINOR:-0}; PATCH=${PATCH:-0}
fi
case "${{ steps.version.outputs.bump }}" in
major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;;
minor) MINOR=$((MINOR + 1)); PATCH=0 ;;
patch) PATCH=$((PATCH + 1)) ;;
esac
NEW_TAG="v${MAJOR}.${MINOR}.${PATCH}"
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_OUTPUT
echo "Creating tag: $NEW_TAG"
git tag -f $NEW_TAG
git push -f origin $NEW_TAG
- name: Generate release notes
if: steps.version.outputs.bump != 'none'
id: release_notes
run: |
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null | tr -d "\n")
echo "## What's Changed" > release_notes.md
echo "" >> release_notes.md
FEATS=$(git log --pretty=format:"%s" $LAST_TAG..HEAD | grep "^feat:" | sed 's/^feat: /- /' || true)
if [ -n "$FEATS" ]; then
echo "### ✨ Features" >> release_notes.md
echo "$FEATS" >> release_notes.md
echo "" >> release_notes.md
fi
FIXES=$(git log --pretty=format:"%s" $LAST_TAG..HEAD | grep "^fix:" | sed 's/^fix: /- /' || true)
if [ -n "$FIXES" ]; then
echo "### 🐛 Bug Fixes" >> release_notes.md
echo "$FIXES" >> release_notes.md
echo "" >> release_notes.md
fi
DOCS=$(git log --pretty=format:"%s" $LAST_TAG..HEAD | grep "^docs:" | sed 's/^docs: /- /' || true)
if [ -n "$DOCS" ]; then
echo "### 📝 Documentation" >> release_notes.md
echo "$DOCS" >> release_notes.md
echo "" >> release_notes.md
fi
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/$LAST_TAG...${{ steps.bump.outputs.NEW_TAG }}" >> release_notes.md
- name: Create Release
if: steps.version.outputs.bump != 'none'
run: |
TAG="${{ steps.bump.outputs.NEW_TAG }}"
echo "Creating release for tag: $TAG"
# Check if release already exists
if gh release view "$TAG" --repo "${{ github.repository }}" >/dev/null 2>&1; then
echo "Release $TAG already exists, updating..."
gh release edit "$TAG" --notes-file release_notes.md --draft=false
else
# Create release using gh cli
gh release create "$TAG" --title "Release $TAG" --notes-file release_notes.md --draft=false
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: No release needed
if: steps.version.outputs.bump == 'none'
run: echo "No breaking changes or new features - no release needed"