-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (122 loc) · 4.34 KB
/
Copy pathrelease-action.yml
File metadata and controls
134 lines (122 loc) · 4.34 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
name: Release Action
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
concurrency: ${{ github.workflow }}-${{ github.ref }}
permissions:
contents: write
pull-requests: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
with:
ref: main
fetch-depth: 0
persist-credentials: false
- 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
# Local tag is needed for changelog generation; remote ref is created via the API
- name: Create tag
if: github.event_name == 'workflow_dispatch'
env:
GH_TOKEN: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
TAG: ${{ steps.version.outputs.tag }}
run: |
git tag "$TAG"
gh api "repos/${GITHUB_REPOSITORY}/git/refs" \
-f ref="refs/tags/${TAG}" \
-f sha="$(git rev-parse HEAD)"
- 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
# Commits via the GitHub API are signed by GitHub and show as Verified
- name: Commit updated CHANGELOG
if: steps.previous.outputs.found == 'true'
uses: planetscale/ghcommit-action@v0.2.22
with:
commit_message: "docs: update CHANGELOG for ${{ steps.version.outputs.tag }}"
repo: ${{ github.repository }}
branch: main
file_pattern: CHANGELOG.md
env:
GITHUB_TOKEN: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}