-
Notifications
You must be signed in to change notification settings - Fork 1
78 lines (67 loc) · 2.9 KB
/
github-release.yml
File metadata and controls
78 lines (67 loc) · 2.9 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
name: Create release
on:
push:
branches:
- main
jobs:
github-release:
name: Create GitHub Release
runs-on: ubuntu-latest
permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Extract version from pyproject.toml
id: get_version
run: |
VERSION=$(grep -m 1 'version = ' pyproject.toml | cut -d '"' -f 2)
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Extract changelog notes for current version
id: get_changelog
run: |
VERSION=${{ env.VERSION }}
echo "Extracting changelog for version v$VERSION"
# Find the start of the current version section
START_LINE=$(grep -n "## \[v$VERSION\] - " CHANGELOG.md | cut -d: -f1)
if [ -z "$START_LINE" ]; then
echo "Warning: No changelog entry found for version v$VERSION"
echo "CHANGELOG_NOTES=" >> $GITHUB_ENV
exit 0
fi
# Find the start of the next version section (previous version)
NEXT_VERSION_LINE=$(tail -n +$((START_LINE + 1)) CHANGELOG.md | grep -n "^## \[v.*\] - " | head -1 | cut -d: -f1)
if [ -z "$NEXT_VERSION_LINE" ]; then
# No next version found, extract from current version till end of file
CHANGELOG_CONTENT=$(tail -n +$START_LINE CHANGELOG.md)
else
# Extract content from current version header to before next version
END_LINE=$((START_LINE + NEXT_VERSION_LINE - 1))
CHANGELOG_CONTENT=$(sed -n "$START_LINE,$((END_LINE - 1))p" CHANGELOG.md)
fi
# Clean up the content but preserve the blank line after the header
# First, get the header line and add a blank line after it
HEADER_LINE=$(echo "$CHANGELOG_CONTENT" | head -1)
CONTENT_LINES=$(echo "$CHANGELOG_CONTENT" | tail -n +2 | sed '/^$/d' | sed 's/^[[:space:]]*//' | sed 's/[[:space:]]*$//')
# Combine header + blank line + content
CHANGELOG_CONTENT=$(printf "%s\n\n%s" "$HEADER_LINE" "$CONTENT_LINES")
# Escape for GitHub Actions
echo "CHANGELOG_NOTES<<EOF" >> $GITHUB_ENV
echo "$CHANGELOG_CONTENT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
if [ -n "$CHANGELOG_NOTES" ]; then
gh release create "v$VERSION" \
--repo "$GITHUB_REPOSITORY" \
--title "v$VERSION" \
--notes "$CHANGELOG_NOTES"
else
gh release create "v$VERSION" \
--repo "$GITHUB_REPOSITORY" \
--title "v$VERSION" \
--notes "Release v$VERSION"
fi