diff --git a/.github/actions/package-and-upload-artifacts/action.yaml b/.github/actions/package-and-upload-artifacts/action.yaml new file mode 100644 index 00000000..82d4bad4 --- /dev/null +++ b/.github/actions/package-and-upload-artifacts/action.yaml @@ -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 diff --git a/.github/actions/release/action.yaml b/.github/actions/release/action.yaml new file mode 100644 index 00000000..87b94be1 --- /dev/null +++ b/.github/actions/release/action.yaml @@ -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 }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index cfea6ac8..00000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,83 +0,0 @@ -name: Release -on: - push: - tags: ["*"] - -jobs: - # Create a GitHub release - release: - name: Create a GitHub release - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - name: Checkout the repository - with: - fetch-depth: 0 - token: ${{ secrets.PAT }} - - - name: Setup Python and Git - uses: ./.github/actions/setup-python-and-git - with: - python-version: '3.11' - - - name: Parse changelog - 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: 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: Release - uses: softprops/action-gh-release@v1 - with: - files: dist/* - tag_name: "${{ env.TAG_NAME }}" - body_path: release-notes.md - - # Upload to real PyPI on GitHub Releases. - release-pypi: - name: Publish released package to pypi.org - runs-on: ubuntu-latest - needs: build-package - steps: - - name: Download packages built by build-and-inspect-python-package - uses: actions/download-artifact@v3 - with: - name: Packages - path: dist - - - name: Upload package to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/ci.yaml b/.github/workflows/test.yaml similarity index 100% rename from .github/workflows/ci.yaml rename to .github/workflows/test.yaml diff --git a/.github/workflows/bumpversion-pr.yaml b/.github/workflows/version-preview.yaml similarity index 100% rename from .github/workflows/bumpversion-pr.yaml rename to .github/workflows/version-preview.yaml diff --git a/.github/workflows/bumpversion.yaml b/.github/workflows/version.yaml similarity index 88% rename from .github/workflows/bumpversion.yaml rename to .github/workflows/version.yaml index b605eeec..b56f2231 100644 --- a/.github/workflows/bumpversion.yaml +++ b/.github/workflows/version.yaml @@ -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