-
Notifications
You must be signed in to change notification settings - Fork 40
84 lines (74 loc) · 2.61 KB
/
Copy pathrelease.yml
File metadata and controls
84 lines (74 loc) · 2.61 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
name: release
on:
workflow_dispatch:
inputs:
version:
description: "New version (e.g. 0.4.0)"
required: true
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PAT_WORKFLOW }}
- name: Validate version format
run: |
if ! echo "${{ inputs.version }}" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::error::Version must be in X.Y.Z format"
exit 1
fi
if git tag -l "v${{ inputs.version }}" | grep -q .; then
echo "::error::Tag v${{ inputs.version }} already exists"
exit 1
fi
- name: Bump version.py
run: |
echo '__version__ = "${{ inputs.version }}"' > pygeofilter/version.py
- name: Update CHANGELOG.md
env:
GH_TOKEN: ${{ github.token }}
run: |
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -n "$LAST_TAG" ]; then
NOTES=$(gh api repos/${{ github.repository }}/releases/generate-notes \
-f tag_name="v${{ inputs.version }}" \
-f previous_tag_name="$LAST_TAG" \
-f target_commitish="main" \
--jq .body)
else
NOTES=$(gh api repos/${{ github.repository }}/releases/generate-notes \
-f tag_name="v${{ inputs.version }}" \
-f target_commitish="main" \
--jq .body)
fi
HEADER="# Changelog"
DATE=$(date +%Y-%m-%d)
SECTION="## [${{ inputs.version }}](https://github.com/${{ github.repository }}/compare/${LAST_TAG}...v${{ inputs.version }}) ($DATE)"
{
echo "$HEADER"
echo
echo "$SECTION"
echo
echo "$NOTES"
echo
# append everything after the "# Changelog" header from the existing file
tail -n +2 CHANGELOG.md
} > CHANGELOG.new.md
mv CHANGELOG.new.md CHANGELOG.md
- name: Commit, tag, push
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pygeofilter/version.py CHANGELOG.md
git commit -m "Release ${{ inputs.version }}"
git tag "v${{ inputs.version }}"
git push origin HEAD --tags
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "v${{ inputs.version }}" --generate-notes