Skip to content

Feat: auto-add dependency PRs to project (#65) #38

Feat: auto-add dependency PRs to project (#65)

Feat: auto-add dependency PRs to project (#65) #38

Workflow file for this run

name: Publish release
on:
workflow_dispatch:
push:
tags:
- "202[3-9].[0-9][0-9].[0-9]+"
- "202[3-9].[0-9][0-9].[0-9]+-rc[0-9]+"
defaults:
run:
shell: bash
jobs:
test:
uses: ./.github/workflows/pytest.yml
release:
runs-on: ubuntu-latest
environment: release
needs: test
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
uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: pip
cache-dependency-path: "**/pyproject.toml"
- name: Install build dependencies
run: pip install build
- name: Build package
run: python -m build
- name: Publish to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: ${{ contains(github.ref, '-rc') }}
with:
repository_url: https://test.pypi.org/legacy/
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: |
pip install -e .
output=$(littlepay -v)
version=${output/littlepay /}
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
if: ${{ !contains(github.ref, '-rc') }}
with:
print_hash: true
- name: Parse version and output PyPI URL
id: version
if: ${{ !contains(github.ref, '-rc') }}
run: |
pip install -e .
output=$(littlepay -v)
version=${output/littlepay /}
echo "PYPI_RELEASE_URL=https://pypi.org/project/calitp-littlepay/$version" >> "$GITHUB_OUTPUT"
- 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: ${{ env.PYPI_RELEASE_URL }}