Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: publishing to PyPI #31

Merged
merged 7 commits into from
Mar 13, 2024
45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,11 +41,54 @@ jobs:
- name: Build package
run: python -m build

- 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/
angela-tran marked this conversation as resolved.
Show resolved Hide resolved
print_hash: true
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') }}
with:
print_hash: true

- 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 .
littlepay
output=$(littlepay -v)
version=${output/littlepay /}
version=${version/.0/.}
thekaveman marked this conversation as resolved.
Show resolved Hide resolved
echo "PYPI_RELEASE_URL=https://pypi.org/project/calitp-littlepay/$version" >> "$GITHUB_OUTPUT"
thekaveman marked this conversation as resolved.
Show resolved Hide resolved

- name: Release
uses: softprops/action-gh-release@v2
env:
# 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: |
./dist/*.tar.gz
./dist/*.whl
prerelease: ${{ contains(github.ref, '-rc') }}
generate_release_notes: ${{ !contains(github.ref, '-rc') }}
body: $PYPI_RELEASE_URL
Loading