CI: only run the publish
job on tag push
#4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test, build, publish | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- '[0-9]+.[0-9]+.[0-9]+' | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', 'pypy3.10'] | |
outputs: | |
version: ${{ steps.run_tests.outputs.VERSION }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
allow-prereleases: true | |
- name: Run code checks | |
run: | | |
pip install 'flake8==6.*' 'bandit[toml]==1.*' 'codespell==2.*' | |
flake8 src tests | |
bandit --configfile=pyproject.toml --recursive src tests | |
codespell src tests | |
- name: Run tests | |
id: run_tests | |
run: | | |
pip install . | |
echo "VERSION=$(pictureshow --version)" >> $GITHUB_OUTPUT | |
pip install -r test-requirements.txt 'pytest-cov==5.*' | |
pytest --cov --cov-report=xml --cov-report=term --verbose | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v5 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
if: matrix.python-version == '3.13' && github.ref == 'refs/heads/main' | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.13' | |
- name: Build | |
run: | | |
pip install build | |
python -m build | |
- name: Upload dist | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dist | |
path: dist/ | |
if-no-files-found: error | |
overwrite: true | |
publish: | |
runs-on: ubuntu-latest | |
if: startsWith(github.ref, 'refs/tags/') | |
needs: [test, build] | |
env: | |
VERSION: ${{ needs.test.outputs.version }} | |
permissions: | |
id-token: write | |
steps: | |
- name: Download dist | |
uses: actions/download-artifact@v4 | |
with: | |
name: dist | |
path: dist/ | |
- name: Publish to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
- name: Create GitHub release | |
uses: softprops/action-gh-release@v2 | |
with: | |
name: version ${{ env.VERSION }} | |
files: 'dist/*' |