Skip to content

Test Building + Publish Python Package TestPyPI if version bumped #98

Test Building + Publish Python Package TestPyPI if version bumped

Test Building + Publish Python Package TestPyPI if version bumped #98

name: Test Building + Publish Python Package TestPyPI if version bumped
on:
workflow_run:
workflows: [Tests]
types:
- completed
workflow_dispatch: # Manual trigger
jobs:
build:
name: Build distribution 📦
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: 'pip'
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
check-version:
runs-on: ubuntu-latest
outputs:
version_changed: ${{ steps.check_version.outputs.version_changed }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- run: |
current_version=$(grep -oP '(?<=__version__ = ")[^"]*' projectcard/__init__.py)
if git show HEAD~1:projectcard/__init__.py > /dev/null 2>&1; then
previous_version=$(git show HEAD~1:projectcard/__init__.py | grep -oP '(?<=__version__ = ")[^"]*')
if [ "$current_version" != "$previous_version" ]; then
echo "version_changed=true" >> "$GITHUB_OUTPUT"
else
echo "version_changed=false" >> "$GITHUB_OUTPUT"
fi
else
echo "version_changed=true" >> "$GITHUB_OUTPUT"
fi
publish-to-testpypi:
name: If version bumped, publish 📦 to TestPyPI
needs:
- check-version
- build
if: (needs.check-version.outputs.version_changed == 'true' && github.event_name == 'push') || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish_target == 'testpypi')
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/projectcard
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/[email protected]
with:
repository-url: https://test.pypi.org/legacy/