Repository navigation
100 lines (87 loc) · 3.33 KB
/
Copy pathrelease.yml
File metadata and controls
100 lines (87 loc) · 3.33 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
# Creates a GitHub release whenever a version tag is pushed, using the
# corresponding section of CHANGELOG.md as release notes.
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: 'Existing version tag to (re-)generate the release for, e.g. v1.4.1'
required: true
name: release
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Determine tag
id: tag
shell: bash
run: |
set -euo pipefail
TAG="${{ github.event.inputs.tag || github.ref_name }}"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "version=${TAG#v}" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
with:
ref: ${{ steps.tag.outputs.tag }}
- name: Extract release notes from CHANGELOG.md
id: notes
shell: bash
run: |
set -euo pipefail
VERSION="${{ steps.tag.outputs.version }}"
# Print everything between the level 2 CHANGELOG.md heading that
# mentions this version and the next level 1 or 2 heading, then
# strip the blank lines at both ends.
awk -v ver="$VERSION" '
/^##? / {
if (found) exit
line = $0
gsub(/[^0-9A-Za-z.]+/, " ", line)
split(line, tok, " ")
for (i in tok) if (tok[i] == ver) found = 1
next
}
found { print }
' CHANGELOG.md | sed -e '/./,$!d' | tac | sed -e '/./,$!d' | tac > release-notes.md
if [ ! -s release-notes.md ]; then
echo "::error::No CHANGELOG.md section found for version ${VERSION}."
exit 1
fi
echo "Release notes for ${VERSION}:"
cat release-notes.md
PACKAGE_VERSION="$(grep -m1 '^version[[:space:]]*=' pyproject.toml | sed -e 's/^version[[:space:]]*=[[:space:]]*"\(.*\)".*/\1/')"
if [ "$PACKAGE_VERSION" != "$VERSION" ]; then
echo "::warning::Tag version ${VERSION} does not match pyproject.toml version ${PACKAGE_VERSION}."
fi
# x.y.z is a regular (PyPI) release, everything else a pre-release
if echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "title=PyPi release v${VERSION}" >> "$GITHUB_OUTPUT"
echo "prerelease=" >> "$GITHUB_OUTPUT"
else
echo "title=PythonKorAPClient v${VERSION}" >> "$GITHUB_OUTPUT"
echo "prerelease=--prerelease" >> "$GITHUB_OUTPUT"
fi
- name: Create or update the release
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
TAG="${{ steps.tag.outputs.tag }}"
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then
echo "Release ${TAG} already exists, updating it."
gh release edit "$TAG" \
--repo "$GITHUB_REPOSITORY" \
--title "${{ steps.notes.outputs.title }}" \
--notes-file release-notes.md
else
gh release create "$TAG" \
--repo "$GITHUB_REPOSITORY" \
--title "${{ steps.notes.outputs.title }}" \
--notes-file release-notes.md \
${{ steps.notes.outputs.prerelease }}
fi