Skip to content

Commit 857835d

Browse files
committed
Updated workflows
- Added better changelog parsing - Added workflow dispatch inputs for manual runs
1 parent a8df235 commit 857835d

File tree

2 files changed

+60
-27
lines changed

2 files changed

+60
-27
lines changed

.github/workflows/bumpversion.yaml

+25-20
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ on:
44
types: [closed]
55
branches: [master]
66
workflow_dispatch:
7-
7+
inputs:
8+
dry_run:
9+
description: Don't actually do the work, just describe it
10+
default: true
11+
type: boolean
12+
new_version:
13+
description: Set the version to a specific value
14+
required: false
15+
type: string
816
jobs:
917
bumpversion:
1018
runs-on: ubuntu-latest
@@ -31,33 +39,30 @@ jobs:
3139
- name: Generate the changelog and get the release hint
3240
id: generate-changelog
3341
run: |
34-
INFO=$(generate-changelog --output all)
35-
RELEASE_KIND=$(echo "$INFO" | jq -r '.release_hint')
36-
NOTES=$(echo "$INFO" | jq -r '.notes')
37-
NOTES="${NOTES//'%'/'%25'}"
38-
NOTES="${NOTES//$'\\n'/'%0A'}"
39-
NOTES="${NOTES//$'\n'/'%0A'}"
40-
NOTES="${NOTES//$'\r'/'%0D'}"
41-
42+
RELEASE_KIND=$(generate-changelog --output release-hint)
4243
echo "::notice::Suggested release type is: ${RELEASE_KIND}"
4344
echo "RELEASE_KIND=$RELEASE_KIND" >> $GITHUB_ENV
4445
echo "release-kind=$RELEASE_KIND" >> $GITHUB_OUTPUT
4546
46-
echo "NOTES=$NOTES" >> $GITHUB_ENV
47-
echo "notes=$NOTES" >> $GITHUB_OUTPUT
48-
echo $NOTES >> release-notes.md
49-
50-
- name: Archive production artifacts
51-
uses: actions/upload-artifact@v3
52-
with:
53-
name: release-notes.md
54-
path: release-notes.md
55-
56-
- name: Bump Version
47+
- name: Bump Version auto
48+
if: ${{ github.event_name != "workflow_dispatch" }}
5749
shell: bash
5850
run: |
5951
if [[ $RELEASE_KIND != "no-release" ]]; then
6052
bump-my-version -v "$RELEASE_KIND"
6153
git push
6254
git push --tags
6355
fi
56+
57+
- name: Bump Version manual
58+
if: ${{ github.event_name == "workflow_dispatch" }}
59+
shell: bash
60+
env:
61+
BUMPVERSION_DRY_RUN: ${{ inputs.dry_run }}
62+
BUMPVERSION_NEW_VERSION: ${{ inputs.tags }}
63+
run: |
64+
bump-my-version -v "$RELEASE_KIND"
65+
if [[ BUMPVERSION_DRY_RUN == "false" ]]; then
66+
git push
67+
git push --tags
68+
fi

.github/workflows/release.yaml

+35-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ jobs:
88
# Package when a new tag is pushed
99
build-package:
1010
if: startsWith(github.ref, 'refs/tags/')
11-
needs: bumpversion
1211
runs-on: ubuntu-latest
1312
steps:
1413
- uses: actions/checkout@v3
@@ -24,21 +23,50 @@ jobs:
2423
runs-on: ubuntu-latest
2524
needs: build-package
2625
steps:
26+
- name: Parse changelog
27+
shell: bash
28+
run: |
29+
function extract_version_content() {
30+
changelog=$1
31+
target_version=$2
32+
33+
awk -v target="$target_version" '
34+
/^## / {
35+
if (found) exit;
36+
version=$2;
37+
if (version == target) found=1;
38+
next;
39+
}
40+
found { print; }
41+
' <<< "$changelog"
42+
}
43+
44+
changelog=$(cat "CHANGELOG.md")
45+
target_version=${GITHUB_REF#refs/tags/}
46+
echo "TAG_NAME=$target_version" >> $GITHUB_ENV
47+
48+
content=$(extract_version_content "$changelog" "$target_version")
49+
50+
if [ -n "$content" ]; then
51+
echo "::notice::Found release notes for ${target_version}"
52+
echo "RELEASE_NOTES=$content" >> $GITHUB_ENV
53+
else
54+
echo "::warning::Did not find release notes for ${target_version}"
55+
echo "RELEASE_NOTES=" >> $GITHUB_ENV
56+
fi
57+
2758
- name: Download packages built by build-and-inspect-python-package
2859
uses: actions/download-artifact@v3
2960
with:
3061
name: Packages
3162
path: dist
32-
- name: Download release notes
33-
uses: actions/download-artifact@v3
34-
with:
35-
name: release-notes.md
36-
path: release-notes.md
63+
3764
- name: Release
3865
uses: softprops/action-gh-release@v1
3966
with:
40-
body_path: release-notes.md
4167
files: dist/*
68+
tag_name: "${{ env.TAG_NAME }}"
69+
body: "${{ env.RELEASE_NOTES }}"
4270

4371
# Upload to Test PyPI.
4472
release-test-pypi:

0 commit comments

Comments
 (0)