-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (95 loc) · 4.03 KB
/
Copy pathrelease.yml
File metadata and controls
107 lines (95 loc) · 4.03 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
101
102
103
104
105
106
107
name: Create Release
on:
push:
branches:
- master
workflow_dispatch:
# Deployment of the site itself is handled by publish.yml (mkdocs gh-deploy).
# This workflow only cuts a version tag and a GitHub Release whose notes list the
# changed documentation pages and the commits since the previous release.
jobs:
release:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-python@v7
with:
python-version: "3.12"
- name: Install poetry
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Version bump
id: version
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Bump the patch version only if the current version already has a tag,
# so a plain docs edit that forgot to bump still gets a fresh release.
if [[ "v$(poetry version --short)" == "$(git describe --tags --always --abbrev=0)" ]]; then
poetry version patch
NEW=$(poetry version --short)
# Commit the bump via the Contents API rather than `git push`: master requires verified
# signatures, and API commits are signed by GitHub's web-flow key (a plain runner push is
# unsigned and gets rejected by branch protection). Then fast-forward the runner to it so
# the tag/changelog steps below see the bump commit.
gh api -X PUT "repos/${{ github.repository }}/contents/pyproject.toml" \
-f message="Version bump v$NEW" \
-f content="$(base64 -w0 pyproject.toml)" \
-f sha="$(git rev-parse "HEAD:pyproject.toml")" \
-f branch="${{ github.ref_name }}"
# The API already committed the bump; discard the local `poetry version patch` edit
# (a plain `git pull` would refuse — "local changes would be overwritten") and sync the
# runner to the signed commit so the tag/changelog steps below build on it.
git fetch origin "${{ github.ref_name }}"
git reset --hard "origin/${{ github.ref_name }}"
echo "Version bumped to $NEW"
fi
echo "Using version $(poetry version --short)"
echo "VERSION=v$(poetry version --short)" >> $GITHUB_OUTPUT
- name: Create tag
uses: rickstaa/action-create-tag@v1
with:
tag: ${{ steps.version.outputs.VERSION }}
- name: Generate changelog
id: changelog
run: |
PREV_TAG=$(git describe --tags --abbrev=0 "${{ steps.version.outputs.VERSION }}^" 2>/dev/null || git rev-list --max-parents=0 HEAD)
RANGE="${PREV_TAG}..${{ steps.version.outputs.VERSION }}"
COMMITS=$(git log --pretty=format:"- %s" "$RANGE")
# docs/**/*.md pages, linked to the live site (mkdocs directory URLs: strip .md / index).
fmt_pages() {
git diff --diff-filter="$1" --name-only "$RANGE" -- 'docs/*.md' 'docs/**/*.md' \
| sed 's|^docs/||; s|/index\.md$|/|; s|\.md$|/|' \
| while read -r p; do echo "- [${p}](https://docs.majordom.io/${p})"; done
}
NEW_DOCS=$(fmt_pages A)
CHANGED_DOCS=$(fmt_pages M)
{
echo "BODY<<EOF"
if [ -n "$NEW_DOCS" ]; then
echo "## New Documentation"
echo "$NEW_DOCS"
echo ""
fi
if [ -n "$CHANGED_DOCS" ]; then
echo "## Updated Documentation"
echo "$CHANGED_DOCS"
echo ""
fi
echo "## Changes"
echo "$COMMITS"
echo "EOF"
} >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.version.outputs.VERSION }}
name: Release ${{ steps.version.outputs.VERSION }}
body: ${{ steps.changelog.outputs.BODY }}
draft: false
prerelease: false