Skip to content

Commit

Permalink
Refactored workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
coordt committed Dec 17, 2023
1 parent f2c343b commit d2f30a8
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 85 deletions.
45 changes: 45 additions & 0 deletions .github/actions/package-and-upload-artifacts/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Package and upload artifacts
description: Package a Python project and upload the artifacts and release notes
runs:
using: 'composite'
steps:
- name: Parse changelog for release notes
shell: bash
run: |
function extract_version_content() {
changelog=$1
target_version=$2
awk -v target="$target_version" '
/^## / {
if (found) exit;
version=$2;
if (version == target) found=1;
next;
}
found { print; }
' <<< "$changelog"
}
changelog=$(cat "CHANGELOG.md")
target_version=${GITHUB_REF#refs/tags/}
echo "TAG_NAME=$target_version" >> $GITHUB_ENV
content=$(extract_version_content "$changelog" "$target_version")
if [ -n "$content" ]; then
echo "::notice::Found release notes for ${target_version}"
echo "$content" >> release-notes.md
else
echo "::warning::Did not find release notes for ${target_version}"
touch release-notes.md
fi
- name: Upload release notes
uses: actions/upload-artifact@v3
with:
name: release-notes
path: release-notes.md

- name: Package and upload artifacts
if: ${{ env.PACKAGE == 'true' }}
uses: hynek/build-and-inspect-python-package@v1
37 changes: 37 additions & 0 deletions .github/actions/release/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Release
description: Create a GitHub release and upload the package to PyPI
inputs:
pypi-api-token:
description: 'PyPI API token'
required: true
tag-name:
description: 'The name of the tag for the GitHub release'
required: true

runs:
using: "composite"
steps:
- name: Download packages built by build-and-inspect-python-package
uses: actions/download-artifact@v3
with:
name: Packages
path: dist
if-no-files-found: warn

- name: Download release notes
uses: actions/download-artifact@v3
with:
name: release-notes
if-no-files-found: warn

- name: Create a GitHub release
uses: softprops/action-gh-release@v1
with:
files: dist/*
tag_name: "${{ env.TAG_NAME }}"
body_path: release-notes.md

- name: Upload package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ inputs.pypi-api-token }}
83 changes: 0 additions & 83 deletions .github/workflows/release.yaml

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ jobs:
;;
esac
- name: Package
- name: Package and upload artifacts
if: ${{ env.PACKAGE == 'true' }}
uses: hynek/build-and-inspect-python-package@v1
uses: ./.github/actions/package-and-upload-artifacts

- name: Create a GitHub release
if: ${{ env.PACKAGE == 'true' }}
uses: ./.github/actions/release

0 comments on commit d2f30a8

Please sign in to comment.