Skip to content

Prepare for open source #4

Prepare for open source

Prepare for open source #4

Workflow file for this run

name: tests
on:
push:
branches: [master]
tags: ['v[0-9]*', '[0-9]+.[0-9]+*'] # Match tags that resemble a version
pull_request: # Run in every PR
workflow_dispatch: # Allow manually triggering the workflow
permissions:
contents: write
concurrency:
group: >-
${{ github.workflow }}-${{ github.ref_type }}-
${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
env:
TOX_VERSION: "4.24.1"
MIN_PYTHON_VERSION: "3.10"
MAX_PYTHON_VERSION: "3.12"
jobs:
prepare:
runs-on: ubuntu-24.04
outputs:
wheel-distribution: ${{ steps.wheel-distribution.outputs.path }}
VERSION: ${{ steps.get_version.outputs.VERSION }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # deep clone for setuptools-scm
- uses: actions/setup-python@v5
id: setup-python
with:
python-version: ${{ env.MIN_PYTHON_VERSION }}
- name: Run static analysis and format checkers
run: >-
pipx run
--python '${{ steps.setup-python.outputs.python-path }}'
--spec tox==${{ env.TOX_VERSION }}
tox -e lint
- name: Build package distribution files
run: >-
pipx run
--python '${{ steps.setup-python.outputs.python-path }}'
--spec tox==${{ env.TOX_VERSION }}
tox -e clean,build
- name: Record the path of wheel distribution
id: wheel-distribution
run: echo "path=$(ls dist/*.whl)" >> $GITHUB_OUTPUT
- name: Extract version
id: get_version
run: |
path=$(ls dist/*.whl)
version=$(basename "$path" | sed -E 's/lob_hlpr-([^-]+)-py3-none-any\.whl/\1/')
echo "VERSION=$version" >> $GITHUB_OUTPUT
- name: Store the distribution files for use in other stages
# `tests` and `publish` will use the same pre-built distributions,
# so we make sure to release the exact same package that was tested
uses: actions/upload-artifact@v4
with:
name: python-distribution-files
path: dist/
retention-days: 1
test:
needs: prepare
strategy:
matrix:
python:
- "3.10"
- "3.12"
platform:
- ubuntu-24.04
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
id: setup-python
with:
python-version: ${{ matrix.python }}
- name: Retrieve pre-built distribution files
uses: actions/download-artifact@v4
with:
name: python-distribution-files
path: dist/
- name: Run tests
run: >-
pipx run
--python '${{ steps.setup-python.outputs.python-path }}'
--spec tox==${{ env.TOX_VERSION }}
tox --installpkg '${{ needs.prepare.outputs.wheel-distribution }}'
-- -rFEx --durations 10 --color yes
release:
if: startsWith(github.ref, 'refs/tags/')
needs: [test, prepare]
runs-on: ubuntu-24.04
steps:
- name: Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
publish-to-pypi:
name: >-
Publish Python distribution to PyPI
needs:
- release
runs-on: ubuntu-24.04
environment:
name: pypi
url: https://pypi.org/p/lob-hlpr # Replace <package-name> with your PyPI project name
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 PyPI
uses: pypa/gh-action-pypi-publish@release/v1