Skip to content

Commit

Permalink
Refactor release process in order to include changelog in release fil…
Browse files Browse the repository at this point in the history
…es (#1246)

* Extract `bump-changelog` action into separate workflow

* Create `create-release` job in `tests.yml`

* Bump changelog for 1.0.0 (#2)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Specify pull request types that trigger CI

* Remove requirement for job

* Try to fix label detection

* Try out `pull_request_target` event

* Fix environment variable access syntax

* Try splitting out in separate workflow

* Use concurrency

* Create `create-release` job in `tests.yml`

* Specify pull request types that trigger CI

* Remove requirement for job

* Try to fix label detection

* Try out `pull_request_target` event

* Fix environment variable access syntax

* Try moving related jobs into release workflow

* Specify Python version in release workflow

* Amend for testing

* Retrieve artifact from previous workflow run

* Create release before uploading asset (makes sense)

* Specify tag name

* Don't run in parallel *yawn*

* Get that blasted tag

* Permissions

* Cleanup, docs

* Extract `bump-changelog` action into separate workflow

* Create `create-release` job in `tests.yml`

* Bump changelog for 1.0.0 (#2)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Specify pull request types that trigger CI

* Remove requirement for job

* Try to fix label detection

* Try out `pull_request_target` event

* Fix environment variable access syntax

* Try splitting out in separate workflow

* Use concurrency

* Create `create-release` job in `tests.yml`

* Specify pull request types that trigger CI

* Remove requirement for job

* Try to fix label detection

* Try out `pull_request_target` event

* Fix environment variable access syntax

* Try moving related jobs into release workflow

* Specify Python version in release workflow

* Amend for testing

* Retrieve artifact from previous workflow run

* Create release before uploading asset (makes sense)

* Specify tag name

* Don't run in parallel *yawn*

* Get that blasted tag

* Permissions

* Cleanup, docs

* Better sentence structure

Co-authored-by: Robert <[email protected]>

* Use concurrency in `bump-changelog.yml`

And fix concurrency group definition in
`release.yml`.

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Robert <[email protected]>
  • Loading branch information
3 people authored May 17, 2024
1 parent ffba90c commit 2970397
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 78 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/bump-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Bump changelog before release

on:
workflow_dispatch:
inputs:
version:
description: 'Version to be released'
required: true
type: string
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
default-python: "3.12"
minimum-supported-python: "3.8"

jobs:
bump-changelog:
name: Bump changelog
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout ${{ github.ref }}
uses: actions/checkout@v4
- name: Set up Python ${{ env.default-python }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.default-python }}
cache: "pip"
- name: Get release version and construct PR branch
run: |
echo "RELEASE_VERSION=${{ inputs.version }}" >> $GITHUB_ENV
echo "PR_BRANCH=bump-changelog-for-${{ inputs.version }}" >> $GITHUB_ENV
- name: Create pull request branch
run: git switch -c $PR_BRANCH
- name: Install nox
run: python -m pip install nox
- name: Update changelog
run: nox --error-on-missing-interpreters --non-interactive --session build_changelog -- $RELEASE_VERSION
- name: Commit and push change
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
git commit -am "$RELEASE_VERSION: Bump changelog"
git fetch origin
git push origin $PR_BRANCH
- name: Create pull request
run: |
git fetch origin
gh pr create --base main --fill --label release-version
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
81 changes: 81 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Release

on:
pull_request_target:
types:
- closed
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
default-python: "3.12"

jobs:
pypi-publish:
name: Publish pipx to PyPI
if: >-
github.event.pull_request.merged == true
&& contains(github.event.pull_request.labels.*.name, 'release-version')
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/p/pipx
permissions:
id-token: write
steps:
- name: Checkout ${{ github.ref }}
uses: actions/checkout@v4
- name: Set up Python ${{ env.default-python }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.default-python }}
cache: "pip"
- name: Install nox
run: pip install nox
- name: Build sdist and wheel
run: nox --error-on-missing-interpreters --non-interactive --session build
- name: Publish to PyPi
uses: pypa/[email protected]

create-release:
name: Create a release on GitHub's UI
needs: pypi-publish
runs-on: ubuntu-latest
outputs:
release-tag: ${{ steps.get-version.outputs.version }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Extract version to be released
id: get-version
env:
TITLE: ${{ github.event.pull_request.title }}
run: |
echo "version=${TITLE/: [[:alnum:]]*} }" >> "$GITHUB_OUTPUT"
- name: Create release
uses: ncipollo/release-action@v1
with:
generateReleaseNotes: true
tag: "${{ steps.get-version.outputs.version }}"
commit: ${{ github.event.pull_request.merge_commit_sha }}

upload-zipapp:
name: Upload zipapp to GitHub Release
needs: create-release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: dawidd6/action-download-artifact@v3
with:
name: pipx.pyz
workflow: tests.yml
workflow_conclusion: success
pr: ${{ github.event.pull_request.number }}
- name: Upload to release
uses: softprops/action-gh-release@v1
with:
files: pipx.pyz
tag_name: "${{ needs.create-release.outputs.release-tag }}"
76 changes: 0 additions & 76 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,79 +85,3 @@ jobs:
name: pipx.pyz
path: pipx.pyz
retention-days: 3

pypi-publish:
name: Publish pipx to PyPI on release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
needs: [tests, man, zipapp]
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/p/pipx
permissions:
id-token: write
steps:
- name: Checkout ${{ github.ref }}
uses: actions/checkout@v4
- name: Set up Python ${{ env.default-python }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.default-python }}
cache: "pip"
- name: Install nox
run: pip install nox
- name: Build sdist and wheel
run: nox --error-on-missing-interpreters --non-interactive --session build
- name: Publish to PyPi
uses: pypa/[email protected]

upload-zipapp:
name: Upload zipapp to GitHub Release on release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
needs: [tests, man, zipapp]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: pipx.pyz
- name: Upload to release
uses: softprops/action-gh-release@v2
with:
files: pipx.pyz

bump-changelog:
name: Bump changelog on release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
needs: [pypi-publish, upload-zipapp]
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout ${{ github.ref }}
uses: actions/checkout@v4
- name: Set up Python ${{ env.default-python }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.default-python }}
cache: "pip"
- name: Extract release tag
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Create pull request branch
run: git switch -c "bump-changelog-for-${RELEASE_VERSION}"
- name: Install nox
run: python -m pip install nox
- name: Update changelog
run: nox --error-on-missing-interpreters --non-interactive --session build_changelog -- $RELEASE_VERSION
- name: Commit and push change
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
git commit -am "Bump changelog for $RELEASE_VERSION"
git push origin "bump-changelog-for-${RELEASE_VERSION}"
- name: Create pull request
run: |
git fetch origin
gh pr create --base main --fill
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9 changes: 7 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,15 @@ nox -s watch_docs
## Releasing New `pipx` Versions
To publish to PyPI simply create a "published" release on GitHub. This will trigger GitHub workflows that publishes:
To release a new version, manually run the `bump-changelog` action under the *"Actions"* tab, passing it the version to be released. This will create a pull request updating the changelog for the upcoming version, with the `release-version` label. Merging this PR will automatically trigger the release workflows.
Attaching this label to any pull request of which the title follows the format `<Version>: Description` and merging it will trigger the release workflows as well.
The release workflow consists of publishing:
- the pipx version to PyPI,
- the documentation to readthedocs,
- the documentation to ReadTheDocs,
- a GitHub release,
- the `zipapp` to the GitHub release created.
No need for any other pre or post publish steps.

0 comments on commit 2970397

Please sign in to comment.