-
Notifications
You must be signed in to change notification settings - Fork 5
92 lines (83 loc) · 2.85 KB
/
Copy pathdraft-release.yml
File metadata and controls
92 lines (83 loc) · 2.85 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
name: Draft Release
on:
workflow_dispatch:
inputs:
branch:
description: "Branch to release from"
required: false
default: "main"
type: string
tag:
description: "New tag (default: 'v' + version from pyproject.toml)"
required: false
type: string
permissions:
contents: write
jobs:
draft-release:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
fetch-depth: 0
fetch-tags: true
- name: Resolve tags and target SHA
id: vars
env:
INPUT_TAG: ${{ inputs.tag }}
run: |
set -euo pipefail
TARGET_SHA=$(git rev-parse HEAD)
if ! PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null); then
echo "::error::No previous tag found in history; cannot auto-bump. Pass 'tag' input explicitly."
exit 1
fi
if [ -n "$INPUT_TAG" ]; then
NEW_TAG="$INPUT_TAG"
else
VERSION=$(grep -E '^version[[:space:]]*=[[:space:]]*"' pyproject.toml | head -1 | sed -E 's/^version[[:space:]]*=[[:space:]]*"([^"]+)".*/\1/')
if [ -z "$VERSION" ]; then
echo "::error::Could not read version from pyproject.toml. Pass 'tag' input explicitly."
exit 1
fi
NEW_TAG="v${VERSION}"
fi
if [ "$NEW_TAG" = "$PREV_TAG" ]; then
echo "::error::New tag ($NEW_TAG) matches the latest existing tag ($PREV_TAG). Bump the version in pyproject.toml (or pass an explicit 'tag') before drafting a release."
exit 1
fi
echo "Previous tag: $PREV_TAG"
echo "New tag: $NEW_TAG"
echo "Target SHA: $TARGET_SHA"
{
echo "PREV_TAG=$PREV_TAG"
echo "NEW_TAG=$NEW_TAG"
echo "TARGET_SHA=$TARGET_SHA"
} >> "$GITHUB_OUTPUT"
- name: Generate release notes
env:
PREV_TAG: ${{ steps.vars.outputs.PREV_TAG }}
run: |
set -euo pipefail
{
echo "# Changelog"
git log --reverse --no-merges --pretty=format:"* %s (%H)" "${PREV_TAG}..HEAD" \
| sed -E 's/ \(#[0-9]+\)( \([0-9a-f]{40}\))$/\1/'
} > release-notes.md
echo "::group::Generated release notes"
cat release-notes.md
echo "::endgroup::"
- name: Create draft release
env:
GH_TOKEN: ${{ github.token }}
NEW_TAG: ${{ steps.vars.outputs.NEW_TAG }}
TARGET_SHA: ${{ steps.vars.outputs.TARGET_SHA }}
run: |
set -euo pipefail
gh release create "$NEW_TAG" \
--draft \
--title "$NEW_TAG" \
--target "$TARGET_SHA" \
--notes-file release-notes.md