Skip to content

Commit d2f30a8

Browse files
committed
Refactored workflows
1 parent f2c343b commit d2f30a8

File tree

6 files changed

+88
-85
lines changed

6 files changed

+88
-85
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Package and upload artifacts
2+
description: Package a Python project and upload the artifacts and release notes
3+
runs:
4+
using: 'composite'
5+
steps:
6+
- name: Parse changelog for release notes
7+
shell: bash
8+
run: |
9+
function extract_version_content() {
10+
changelog=$1
11+
target_version=$2
12+
13+
awk -v target="$target_version" '
14+
/^## / {
15+
if (found) exit;
16+
version=$2;
17+
if (version == target) found=1;
18+
next;
19+
}
20+
found { print; }
21+
' <<< "$changelog"
22+
}
23+
24+
changelog=$(cat "CHANGELOG.md")
25+
target_version=${GITHUB_REF#refs/tags/}
26+
echo "TAG_NAME=$target_version" >> $GITHUB_ENV
27+
content=$(extract_version_content "$changelog" "$target_version")
28+
29+
if [ -n "$content" ]; then
30+
echo "::notice::Found release notes for ${target_version}"
31+
echo "$content" >> release-notes.md
32+
else
33+
echo "::warning::Did not find release notes for ${target_version}"
34+
touch release-notes.md
35+
fi
36+
37+
- name: Upload release notes
38+
uses: actions/upload-artifact@v3
39+
with:
40+
name: release-notes
41+
path: release-notes.md
42+
43+
- name: Package and upload artifacts
44+
if: ${{ env.PACKAGE == 'true' }}
45+
uses: hynek/build-and-inspect-python-package@v1

.github/actions/release/action.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Release
2+
description: Create a GitHub release and upload the package to PyPI
3+
inputs:
4+
pypi-api-token:
5+
description: 'PyPI API token'
6+
required: true
7+
tag-name:
8+
description: 'The name of the tag for the GitHub release'
9+
required: true
10+
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Download packages built by build-and-inspect-python-package
15+
uses: actions/download-artifact@v3
16+
with:
17+
name: Packages
18+
path: dist
19+
if-no-files-found: warn
20+
21+
- name: Download release notes
22+
uses: actions/download-artifact@v3
23+
with:
24+
name: release-notes
25+
if-no-files-found: warn
26+
27+
- name: Create a GitHub release
28+
uses: softprops/action-gh-release@v1
29+
with:
30+
files: dist/*
31+
tag_name: "${{ env.TAG_NAME }}"
32+
body_path: release-notes.md
33+
34+
- name: Upload package to PyPI
35+
uses: pypa/gh-action-pypi-publish@release/v1
36+
with:
37+
password: ${{ inputs.pypi-api-token }}

.github/workflows/release.yaml

-83
This file was deleted.
File renamed without changes.
File renamed without changes.

.github/workflows/bumpversion.yaml .github/workflows/version.yaml

+6-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ jobs:
5151
;;
5252
esac
5353
54-
- name: Package
54+
- name: Package and upload artifacts
5555
if: ${{ env.PACKAGE == 'true' }}
56-
uses: hynek/build-and-inspect-python-package@v1
56+
uses: ./.github/actions/package-and-upload-artifacts
57+
58+
- name: Create a GitHub release
59+
if: ${{ env.PACKAGE == 'true' }}
60+
uses: ./.github/actions/release

0 commit comments

Comments
 (0)