From bc11959893432293865810d82c72fa562ca20a86 Mon Sep 17 00:00:00 2001 From: Angela Tran Date: Mon, 11 Mar 2024 21:42:29 +0000 Subject: [PATCH 1/7] feat: add steps for publishing to PyPI (test and production) --- .github/workflows/release.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e69aded..e185443 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,6 +22,8 @@ jobs: permissions: # https://github.com/softprops/action-gh-release#permissions contents: write + # https://docs.pypi.org/trusted-publishers/using-a-publisher/ + id-token: write steps: - name: Checkout @@ -47,3 +49,18 @@ jobs: ./dist/*.whl prerelease: ${{ contains(github.ref, '-rc') }} generate_release_notes: ${{ !contains(github.ref, '-rc') }} + + - name: Publish to Test PyPI + uses: pypa/gh-action-pypi-publish@release/v1.5 + if: ${{ contains(github.ref, '-rc') }} + with: + repository_url: https://test.pypi.org/legacy/ + print_hash: true + skip_existing: true + verbose: true + + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1.5 + if: ${{ !contains(github.ref, '-rc') }} + with: + print_hash: true From 7100515d9ea5ba8cee9d5d221ca1d234475b9df5 Mon Sep 17 00:00:00 2001 From: Angela Tran Date: Tue, 12 Mar 2024 17:57:58 +0000 Subject: [PATCH 2/7] refactor: move GitHub release step to happen last this is in preparation for putting the PyPI URL in the GitHub release --- .github/workflows/release.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e185443..634c7c2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,15 +41,6 @@ jobs: - name: Build package run: python -m build - - name: Release - uses: softprops/action-gh-release@v2 - with: - files: | - ./dist/*.tar.gz - ./dist/*.whl - prerelease: ${{ contains(github.ref, '-rc') }} - generate_release_notes: ${{ !contains(github.ref, '-rc') }} - - name: Publish to Test PyPI uses: pypa/gh-action-pypi-publish@release/v1.5 if: ${{ contains(github.ref, '-rc') }} @@ -64,3 +55,12 @@ jobs: if: ${{ !contains(github.ref, '-rc') }} with: print_hash: true + + - name: Release + uses: softprops/action-gh-release@v2 + with: + files: | + ./dist/*.tar.gz + ./dist/*.whl + prerelease: ${{ contains(github.ref, '-rc') }} + generate_release_notes: ${{ !contains(github.ref, '-rc') }} From 294efa9b4cdab0d5377b651de272250e57bf8ae7 Mon Sep 17 00:00:00 2001 From: Angela Tran Date: Wed, 13 Mar 2024 00:00:17 +0000 Subject: [PATCH 3/7] feat: include PyPI release URL in GitHub release notes --- .github/workflows/release.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 634c7c2..99cd70f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -56,11 +56,25 @@ jobs: with: print_hash: true + - name: Parse version and output PyPI URL + id: version + # run littlepay first, so `littlepay -v` doesn't create the config file (which outputs a message) + run: | + littlepay + pip install pyproject.toml + output=$(littlepay -v) + version=${output/littlepay /} + version=${version/.0/} + echo "PYPI_RELEASE_URL=https://pypi.org/project/calitp-littlepay/$version" >> "$GITHUB_OUTPUT" + - name: Release uses: softprops/action-gh-release@v2 + env: + PYPI_RELEASE_URL: ${{ steps.version.outputs.PYPI_RELEASE_URL }} with: files: | ./dist/*.tar.gz ./dist/*.whl prerelease: ${{ contains(github.ref, '-rc') }} generate_release_notes: ${{ !contains(github.ref, '-rc') }} + body: $PYPI_RELEASE_URL From 59d60c70d64f304bb8ff2c5cc544c11efbf8c377 Mon Sep 17 00:00:00 2001 From: Angela Tran Date: Wed, 13 Mar 2024 00:16:44 +0000 Subject: [PATCH 4/7] fix: preserve . that comes before 0 in month --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 99cd70f..d13c6dc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -64,7 +64,7 @@ jobs: pip install pyproject.toml output=$(littlepay -v) version=${output/littlepay /} - version=${version/.0/} + version=${version/.0/.} echo "PYPI_RELEASE_URL=https://pypi.org/project/calitp-littlepay/$version" >> "$GITHUB_OUTPUT" - name: Release From 3974c4b7dd451e749ddea4baaa017748c58c3af2 Mon Sep 17 00:00:00 2001 From: Angela Tran Date: Wed, 13 Mar 2024 15:58:25 +0000 Subject: [PATCH 5/7] fix: need to install littlepay first and as editable install --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d13c6dc..dd70ac1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -60,8 +60,8 @@ jobs: id: version # run littlepay first, so `littlepay -v` doesn't create the config file (which outputs a message) run: | + pip install -e . littlepay - pip install pyproject.toml output=$(littlepay -v) version=${output/littlepay /} version=${version/.0/.} From 2dc4970a9c95148b346f72c9d989978d140ba49c Mon Sep 17 00:00:00 2001 From: Angela Tran Date: Wed, 13 Mar 2024 16:37:46 +0000 Subject: [PATCH 6/7] refactor: use Test PyPI URL for pre-releases --- .github/workflows/release.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dd70ac1..d276ac9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -50,6 +50,18 @@ jobs: skip_existing: true verbose: true + - name: Parse version and output Test PyPI URL + id: test-version + if: ${{ contains(github.ref, '-rc') }} + # run littlepay first, so `littlepay -v` doesn't create the config file (which outputs a message) + run: | + pip install -e . + littlepay + output=$(littlepay -v) + version=${output/littlepay /} + version=${version/.0/.} + echo "PYPI_RELEASE_URL=https://test.pypi.org/project/calitp-littlepay/$version" >> "$GITHUB_OUTPUT" + - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1.5 if: ${{ !contains(github.ref, '-rc') }} @@ -58,6 +70,7 @@ jobs: - name: Parse version and output PyPI URL id: version + if: ${{ !contains(github.ref, '-rc') }} # run littlepay first, so `littlepay -v` doesn't create the config file (which outputs a message) run: | pip install -e . @@ -70,7 +83,8 @@ jobs: - name: Release uses: softprops/action-gh-release@v2 env: - PYPI_RELEASE_URL: ${{ steps.version.outputs.PYPI_RELEASE_URL }} + # this syntax is the only way to get ternary-operator behavior (see https://7tonshark.com/posts/github-actions-ternary-operator/) + PYPI_RELEASE_URL: ${{ !contains(github.ref, '-rc') && steps.version.outputs.PYPI_RELEASE_URL || steps.test-version.outputs.PYPI_RELEASE_URL }} with: files: | ./dist/*.tar.gz From 4c26e31a84921c984322ffb54b01a972dcff181b Mon Sep 17 00:00:00 2001 From: Angela Tran Date: Wed, 13 Mar 2024 12:22:43 -0500 Subject: [PATCH 7/7] chore: update comment with more helpful article --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d276ac9..ea4f1aa 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -83,7 +83,7 @@ jobs: - name: Release uses: softprops/action-gh-release@v2 env: - # this syntax is the only way to get ternary-operator behavior (see https://7tonshark.com/posts/github-actions-ternary-operator/) + # this syntax is the only way to get ternary-operator behavior (see https://mattdood.com/2022/3/github-actions-conditional-environment-variables-20220325012837) PYPI_RELEASE_URL: ${{ !contains(github.ref, '-rc') && steps.version.outputs.PYPI_RELEASE_URL || steps.test-version.outputs.PYPI_RELEASE_URL }} with: files: |