-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (105 loc) · 3.5 KB
/
github_release.yml
File metadata and controls
120 lines (105 loc) · 3.5 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
name: Release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
workflow_dispatch:
inputs:
bump:
description: "Version bump type (leave empty to auto-detect from commits)"
required: false
type: choice
options:
- auto
- major
- minor
- patch
default: auto
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine version
id: version
run: |
if [ "${{ github.event_name }}" = "push" ]; then
TAG="${GITHUB_REF#refs/tags/}"
VERSION="${TAG#v}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
exit 0
fi
LATEST_STABLE=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1)
BUMP="${{ inputs.bump }}"
if [ "$BUMP" = "auto" ] || [ -z "$BUMP" ]; then
if [ -z "$LATEST_STABLE" ]; then
COMMITS=$(git log --pretty=format:"%s%n%b" HEAD)
else
COMMITS=$(git log --pretty=format:"%s%n%b" "${LATEST_STABLE}..HEAD")
fi
BUMP="patch"
if echo "$COMMITS" | grep -qE '^feat(\(.+\))?!:|^fix(\(.+\))?!:|^refactor(\(.+\))?!:|^[a-z]+(\(.+\))?!:|BREAKING CHANGE:'; then
BUMP="major"
elif echo "$COMMITS" | grep -qE '^feat(\(.+\))?:'; then
BUMP="minor"
fi
fi
if [ -z "$LATEST_STABLE" ]; then
MAJOR=0; MINOR=1; PATCH=0
else
VERSION="${LATEST_STABLE#v}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
fi
case "$BUMP" in
major)
MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0
;;
minor)
MINOR=$((MINOR + 1)); PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac
NEXT_VERSION="${MAJOR}.${MINOR}.${PATCH}"
TAG="v${NEXT_VERSION}"
echo "version=${NEXT_VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
- name: Create and push tag (manual dispatch)
if: github.event_name == 'workflow_dispatch'
run: |
git tag "${{ steps.version.outputs.tag }}"
git push origin "${{ steps.version.outputs.tag }}"
echo "Tag pushed. The release will be created by the tag-push trigger."
- name: Generate changelog
if: github.event_name == 'push'
id: changelog
run: |
PREVIOUS_TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -2 | tail -1)
if [ -z "$PREVIOUS_TAG" ]; then
CHANGELOG=$(git log --pretty=format:"- %s (%h)" HEAD)
else
CHANGELOG=$(git log --pretty=format:"- %s (%h)" "${PREVIOUS_TAG}..HEAD")
fi
{
echo "changelog<<EOF"
echo "$CHANGELOG"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Create GitHub release
if: github.event_name == 'push'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag }}
name: ${{ steps.version.outputs.tag }}
body: |
## What's Changed
${{ steps.changelog.outputs.changelog }}
draft: false
prerelease: false