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

Python: publish on version bump only #230

Merged
merged 4 commits into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ on:
- 'python/**/*.py'
- 'python/pyproject.toml'

defaults:
run:
working-directory: ./python

jobs:
build:
lint_and_test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./python
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -50,12 +51,31 @@ jobs:
run: |
poetry run pytest --cov=truelayer_signing -v tests/

check_version:
runs-on: ubuntu-latest
# Runs only on the main branch
if: ${{ github.ref == 'refs/heads/main' }}
needs: lint_and_test
outputs:
version: ${{ steps.get_version.outputs.VERSION }}
is_published: ${{ steps.check_published.outputs.IS_PUBLISHED }}
steps:
- uses: actions/checkout@v4
- name: Get current version
id: get_version
run: echo VERSION="$(grep -m1 'version = "' pyproject.toml | cut -d '"' -f2)" >> $GITHUB_OUTPUT
- name: Check if it's already published
id: check_published
run: |
PACKAGE_URL=https://pypi.org/pypi/truelayer-signing/${{ steps.get_version.outputs.VERSION }}/json
STATUS_CODE=$(curl --write-out %{http_code} --silent --output /dev/null $PACKAGE_URL)
echo IS_PUBLISHED=$(([ $STATUS_CODE -eq 200 ] && echo true ) || echo false) >> $GITHUB_OUTPUT

publish:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' # Runs only on commits on main branch
defaults:
run:
working-directory: ./python
# Runs only on the main branch and if the current version isn't already published
if: ${{ github.ref == 'refs/heads/main' && needs.check_version.outputs.is_published == false }}
needs: [lint_and_test, check_version]
env:
python-version: "3.10"
strategy:
Expand Down