-
Notifications
You must be signed in to change notification settings - Fork 0
70 lines (61 loc) · 1.76 KB
/
release.yml
File metadata and controls
70 lines (61 loc) · 1.76 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
name: Release
on:
push:
tags:
- "*"
workflow_dispatch:
inputs:
tag:
description: "Tag to publish, for example 1.0.0"
required: true
type: string
permissions:
contents: write
jobs:
release:
name: GitHub Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create or update release
env:
GH_TOKEN: ${{ github.token }}
TAG_NAME: ${{ inputs.tag || github.ref_name }}
run: |
set -euo pipefail
tag="${TAG_NAME}"
if [[ ! "${tag}" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Skip non-semver tag: ${tag}"
exit 0
fi
git fetch --tags --force
if ! git rev-parse -q --verify "refs/tags/${tag}" >/dev/null; then
echo "Tag does not exist: ${tag}" >&2
exit 1
fi
version="${tag#v}"
notes_file="$(mktemp)"
awk -v version="${version}" '
BEGIN { in_section = 0 }
$0 ~ "^##[[:space:]]+" version "([[:space:]]|-|$)" {
in_section = 1
next
}
in_section && /^##[[:space:]]+/ {
exit
}
in_section {
print
}
' CHANGELOG.md > "${notes_file}"
if [[ ! -s "${notes_file}" ]]; then
printf 'Release %s\n' "${tag}" > "${notes_file}"
fi
if gh release view "${tag}" >/dev/null 2>&1; then
gh release edit "${tag}" --title "${tag}" --notes-file "${notes_file}"
else
gh release create "${tag}" --title "${tag}" --notes-file "${notes_file}" --verify-tag
fi