-
Notifications
You must be signed in to change notification settings - Fork 16
89 lines (77 loc) · 2.54 KB
/
github-release.yml
File metadata and controls
89 lines (77 loc) · 2.54 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
name: SDK Github Release
on:
workflow_dispatch:
inputs:
version:
description: "Version (e.g. 2.1.0)"
required: true
is_prerelease:
description: "Mark as pre-release?"
type: boolean
required: false
default: false
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # need tags
- name: Configure git user for tagging
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Validate version format (SemVer core + optional suffix)
run: |
set -euo pipefail
VERSION="${{ inputs.version }}"
if [[ "$VERSION" =~ ^v ]]; then
echo "::error::Version must not start with 'v' — use format like 1.2.3 or 1.2.3-rc1"
exit 1
fi
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
echo "::error::Version must be X.Y.Z with optional -suffix and optional +build (e.g., 1.2.3-rc1 or 1.2.3-rc.1+build.45)"
exit 1
fi
- name: Ensure tag exists (v${{ inputs.version }})
run: |
set -euo pipefail
NEW_TAG="v${{ inputs.version }}"
if git rev-parse -q --verify "refs/tags/${NEW_TAG}" >/dev/null; then
echo "Tag ${NEW_TAG} already exists."
else
git tag -a "${NEW_TAG}" -m "${NEW_TAG}"
git push origin "${NEW_TAG}"
fi
- name: Prepare release notes (notes.md)
run: |
awk '
BEGIN { found_first = 0; found_second = 0 }
/^\*\*/ {
if (found_first == 0) {
found_first = 1
next
} else {
found_second = 1
exit
}
}
found_first == 1 && found_second == 0 {
print $0
}
' CHANGELOG.md > notes.md
- name: Zip sdk-example
run: |
rm -f sdk-example.zip
zip -r sdk-example.zip sdk-example
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: |
FLAGS=("--title" "v${{ inputs.version }}" "--notes-file" "notes.md")
if [ "${{ inputs.is_prerelease }}" = "true" ]; then
FLAGS+=("--prerelease")
fi
gh release create "v${{ inputs.version }}" "${FLAGS[@]}" sdk-example.zip