Skip to content

Commit 2207ed3

Browse files
committed
Fixed the release automation.
1 parent c353b17 commit 2207ed3

6 files changed

Lines changed: 207 additions & 39 deletions

File tree

.changelog-config.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,24 @@ valid_author_tokens:
103103
# Rules applied to commits to determine the type of release to suggest.
104104
release_hint_rules:
105105
- match_result: dev
106-
no_match_result: no-release
107106
branch: ^((?!master|main).)*$
108107
- match_result: patch
109-
no_match_result: no-release
110108
grouping: Other
111109
branch: master|main
110+
paths: generate_changelog/
112111
- match_result: patch
113-
no_match_result: no-release
114112
grouping: Fixes
115113
branch: master|main
114+
paths: generate_changelog/
116115
- match_result: minor
117-
no_match_result: no-release
118116
grouping: Updates
119117
branch: master|main
118+
paths: generate_changelog/
120119
- match_result: minor
121-
no_match_result:
122120
grouping: New
121+
paths: generate_changelog/
123122
branch: master|main
124123
- match_result: major
125-
no_match_result:
126124
grouping: Breaking Changes
125+
paths: generate_changelog/
127126
branch: master|main
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Display the version hint
2+
on:
3+
pull_request:
4+
types: [synchronize]
5+
branches: [master]
6+
7+
jobs:
8+
bumpversion:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 0
14+
token: ${{ secrets.PAT }}
15+
16+
- uses: actions/setup-python@v4
17+
with:
18+
python-version: '3.11'
19+
cache: 'pip' # caching pip dependencies
20+
21+
- name: Install requirements
22+
run: |
23+
python -m pip install . bump-my-version
24+
25+
- name: Git check
26+
run: |
27+
git config --global user.email "no-reply@github.actions"
28+
git config --global user.name "Testing Git"
29+
git --version
30+
git config --list
31+
32+
- name: Get the release hint
33+
id: generate-changelog
34+
run: |
35+
RELEASE_KIND=$(generate-changelog --output release-hint --branch-override ${{ github.base_ref }} --skip-output-pipeline)
36+
echo "::notice::Suggested release type upon merge to ${{ github.base_ref }}: ${RELEASE_KIND}"
37+
echo "RELEASE_KIND=$RELEASE_KIND" >> $GITHUB_ENV
38+
echo "release-kind=$RELEASE_KIND" >> $GITHUB_OUTPUT
39+
40+
- name: Bump Version dry run
41+
shell: bash
42+
run: |
43+
PR_NUMBER=$(gh pr view --json number -q .number || echo "")
44+
REVISION=$(git describe --tags --long | awk -F- '{print $2}')
45+
export PR_NUMBER REVISION
46+
47+
# This will display a full log of what would happen if we were to bump the version.
48+
bump-my-version bump --dry-run --verbose "$RELEASE_KIND"
49+
50+
# This retrieves the current and new version numbers as a JSON-formatted string.
51+
VERSION_INFO=$(bump-my-version show --format json --increment "$RELEASE_KIND" current_version new_version)
52+
echo "CURRENT_VERSION=$(echo $VERSION_INFO | jq -r .current_version)" >> $GITHUB_ENV
53+
echo "NEW_VERSION=$(echo $VERSION_INFO | jq -r .new_version)" >> $GITHUB_ENV
54+
55+
- name: Display the version hint
56+
uses: s-gehring/singleton-comment@v1
57+
with:
58+
comment-body: |
59+
**Version hint:** ${{ env.RELEASE_KIND }}
60+
**Current version:** ${{ env.CURRENT_VERSION }}
61+
**New version (when merged):** ${{ env.NEW_VERSION }}

.github/workflows/bumpversion.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Bump the version on merge
2+
on:
3+
pull_request:
4+
types: [closed]
5+
branches: [master]
6+
7+
jobs:
8+
bumpversion:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
fetch-depth: 0
14+
token: ${{ secrets.PAT }}
15+
16+
- uses: actions/setup-python@v4
17+
with:
18+
python-version: '3.11'
19+
cache: 'pip' # caching pip dependencies
20+
21+
- name: Install requirements
22+
run: |
23+
python -m pip install . bump-my-version
24+
25+
- name: Git check
26+
run: |
27+
git config --global user.email "bump-my-version@github.actions"
28+
git config --global user.name "Testing Git"
29+
git --version
30+
git config --list
31+
32+
- name: Generate the changelog and get the release hint
33+
id: generate-changelog
34+
run: |
35+
RELEASE_KIND=$(generate-changelog --output release-hint)
36+
echo "::notice::Suggested release type for this branch is: ${RELEASE_KIND}"
37+
echo "RELEASE_KIND=$RELEASE_KIND" >> $GITHUB_ENV
38+
echo "release-kind=$RELEASE_KIND" >> $GITHUB_OUTPUT
39+
echo "PACKAGE=false" >> $GITHUB_ENV
40+
41+
- name: Bump Version auto
42+
shell: bash
43+
run: |
44+
PR_NUMBER=$(gh pr view --json number -q .number || echo "")
45+
REVISION=$(git describe --tags --long | awk -F- '{print $2}')
46+
export PR_NUMBER REVISION
47+
case "$RELEASE_KIND" in
48+
major|minor|patch)
49+
bump-my-version bump "$RELEASE_KIND"
50+
git push
51+
git push --tags
52+
echo "PACKAGE=true" >> $GITHUB_ENV
53+
;;
54+
dev)
55+
echo "Intentionally not bumping version for dev release"
56+
;;
57+
esac
58+
59+
- name: Package
60+
if: ${{ env.PACKAGE == 'true' }}
61+
uses: hynek/build-and-inspect-python-package@v1

.github/workflows/publish-package.yaml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/release.yaml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Release
2+
on:
3+
push:
4+
tags: ["*"]
5+
6+
jobs:
7+
# Create a GitHub release
8+
release:
9+
name: Create a GitHub release
10+
runs-on: ubuntu-latest
11+
needs: build-package
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Parse changelog
15+
shell: bash
16+
run: |
17+
function extract_version_content() {
18+
changelog=$1
19+
target_version=$2
20+
21+
awk -v target="$target_version" '
22+
/^## / {
23+
if (found) exit;
24+
version=$2;
25+
if (version == target) found=1;
26+
next;
27+
}
28+
found { print; }
29+
' <<< "$changelog"
30+
}
31+
32+
changelog=$(cat "CHANGELOG.md")
33+
target_version=${GITHUB_REF#refs/tags/}
34+
echo "TAG_NAME=$target_version" >> $GITHUB_ENV
35+
content=$(extract_version_content "$changelog" "$target_version")
36+
37+
if [ -n "$content" ]; then
38+
echo "::notice::Found release notes for ${target_version}"
39+
echo "$content" >> release-notes.md
40+
else
41+
echo "::warning::Did not find release notes for ${target_version}"
42+
touch release-notes.md
43+
fi
44+
45+
- name: Download packages built by build-and-inspect-python-package
46+
uses: actions/download-artifact@v3
47+
with:
48+
name: Packages
49+
path: dist
50+
51+
- name: Release
52+
uses: softprops/action-gh-release@v1
53+
with:
54+
files: dist/*
55+
tag_name: "${{ env.TAG_NAME }}"
56+
body_path: release-notes.md
57+
58+
# Upload to real PyPI on GitHub Releases.
59+
release-pypi:
60+
name: Publish released package to pypi.org
61+
if: startsWith(github.ref, 'refs/tags/')
62+
runs-on: ubuntu-latest
63+
needs: build-package
64+
steps:
65+
- name: Download packages built by build-and-inspect-python-package
66+
uses: actions/download-artifact@v3
67+
with:
68+
name: Packages
69+
path: dist
70+
71+
- name: Upload package to PyPI
72+
uses: pypa/gh-action-pypi-publish@release/v1
73+
with:
74+
password: ${{ secrets.PYPI_API_TOKEN }}

pyproject.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,16 @@ commit = true
226226
commit_args = "--no-verify"
227227
tag = true
228228
tag_name = "{new_version}"
229-
parse = '(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\+\w+-(?P<dev>\d+))?'
229+
parse = '(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\.(?P<dev>post)\d+\.dev\d+)?'
230230
serialize = [
231-
"{major}.{minor}.{patch}+{$BRANCH_NAME}-{dev}",
232-
"{major}.{minor}.{patch}",
231+
"{major}.{minor}.{patch}.{dev}{$PR_NUMBER}.dev{$REVISION}",
232+
"{major}.{minor}.{patch}"
233233
]
234234
message = "Version updated from {current_version} to {new_version}"
235235

236+
[tool.bumpversion.parts.dev]
237+
values = ["release", "post"]
238+
236239
[[tool.bumpversion.files]]
237240
filename = "generate_changelog/__init__.py"
238241

0 commit comments

Comments
 (0)