-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (115 loc) · 3.93 KB
/
release.yml
File metadata and controls
126 lines (115 loc) · 3.93 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
name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version (e.g. 2026.0.0 or 1.2.3)'
required: true
type: string
scheme:
description: 'Version scheme'
required: true
type: choice
options:
- calver
- semver
default: calver
push:
tags:
- '[0-9]*'
permissions:
contents: write
pull-requests: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: main
fetch-depth: 0
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
persist-credentials: true
- name: Determine version and scheme
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ github.event.inputs.version }}"
SCHEME="${{ github.event.inputs.scheme }}"
else
TAG="${GITHUB_REF_NAME}"
if echo "$TAG" | grep -qE '^[0-9]{4}\.[0-9]+\.[0-9]+$'; then
SCHEME="calver"
else
SCHEME="semver"
fi
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "scheme=$SCHEME" >> "$GITHUB_OUTPUT"
- name: Validate version format
run: |
TAG="${{ steps.version.outputs.tag }}"
SCHEME="${{ steps.version.outputs.scheme }}"
if [ "$SCHEME" = "calver" ]; then
if ! echo "$TAG" | grep -qE '^[0-9]{4}\.[0-9]+\.[0-9]+$'; then
echo "Error: Version must be in CalVer format YYYY.MINOR.PATCH (e.g. 2026.0.0)"
exit 1
fi
else
if ! echo "$TAG" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "Error: Version must be in SemVer format MAJOR.MINOR.PATCH (e.g. 1.2.3)"
exit 1
fi
fi
- name: Create and push tag
if: github.event_name == 'workflow_dispatch'
run: |
git tag "${{ steps.version.outputs.tag }}"
git push origin "${{ steps.version.outputs.tag }}"
- name: Get previous tag
id: previous
run: |
CURRENT="${{ steps.version.outputs.tag }}"
PREVIOUS=$(git tag --list --sort=-version:refname '[0-9]*' | grep -v "^${CURRENT}$" | head -1)
if [ -n "$PREVIOUS" ]; then
echo "tag=$PREVIOUS" >> "$GITHUB_OUTPUT"
echo "found=true" >> "$GITHUB_OUTPUT"
else
echo "tag=" >> "$GITHUB_OUTPUT"
echo "found=false" >> "$GITHUB_OUTPUT"
fi
- name: Generate changelog
if: steps.previous.outputs.found == 'true'
id: changelog
uses: requarks/changelog-action@v1
with:
token: ${{ github.token }}
fromTag: ${{ steps.version.outputs.tag }}
toTag: ${{ steps.previous.outputs.tag }}
excludeTypes: build,docs,other,style,ci,chore
useGitmojis: false
writeToFile: false
- name: Create GitHub release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.version.outputs.tag }}
name: ${{ steps.version.outputs.tag }}
body: ${{ steps.changelog.outputs.changes || 'Initial release' }}
- name: Write changelog to file
if: steps.previous.outputs.found == 'true'
uses: requarks/changelog-action@v1
with:
token: ${{ github.token }}
fromTag: ${{ steps.version.outputs.tag }}
toTag: ${{ steps.previous.outputs.tag }}
excludeTypes: build,docs,other,style,ci,chore
useGitmojis: false
writeToFile: true
- name: Commit updated CHANGELOG
if: steps.previous.outputs.found == 'true'
uses: stefanzweifel/git-auto-commit-action@v7
with:
branch: main
commit_message: "docs: update CHANGELOG for ${{ steps.version.outputs.tag }}"
file_pattern: CHANGELOG.md