Merge pull request #206 from communitiesuk/renovate/ncipollo-release-… #940
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 and Tag | |
# Runs on every push to run the unit tests. | |
# Additionally, if on main, reads the current version from setup.py and then creates a new tag and release named | |
# for that version. | |
# If a tag already exists with that name, the Create Release step is skipped. | |
on: | |
workflow_dispatch: | |
push: | |
paths-ignore: | |
- "**/README.md" | |
jobs: | |
run-unit-tests: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
# If updating this list of python versions, you also need to update tox config in pyproject.toml | |
env: | |
- "3.10" | |
- "3.11" | |
- "3.12" | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
- name: Install the latest version of uv | |
uses: astral-sh/setup-uv@e779db74266a80753577425b0f4ee823649f251d # v3 | |
- name: Install tox | |
run: uv tool install --python-preference only-managed --python 3.12 tox --with tox-uv --with tox-gh | |
- name: Install Python | |
if: matrix.env != '3.12' | |
run: uv python install --python-preference only-managed ${{ matrix.env }} | |
- name: Setup test suite | |
run: tox run -vv --notest --skip-missing-interpreters false | |
env: | |
TOX_GH_MAJOR_MINOR: ${{ matrix.env }} | |
- name: Run test suite | |
run: tox run --skip-pkg-install | |
env: | |
TOX_GH_MAJOR_MINOR: ${{ matrix.env }} | |
create-release: | |
runs-on: ubuntu-latest | |
needs: run-unit-tests | |
if: github.ref == 'refs/heads/main' | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
- name: Setup python | |
id: setup_python | |
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5 | |
with: | |
python-version: '3.10' | |
- name: Get package version | |
id: package_version | |
run: echo "app_version="$(python setup.py --version) >> $GITHUB_OUTPUT | |
- name: Check if tag exists | |
uses: mukunku/tag-exists-action@bdad1eaa119ce71b150b952c97351c75025c06a9 # v1.6.0 | |
id: check_tag | |
with: | |
tag: ${{ steps.package_version.outputs.app_version }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- uses: ncipollo/release-action@cdcc88a9acf3ca41c16c37bb7d21b9ad48560d87 # v1.15.0 | |
name: Create Release | |
id: create_release | |
if: ${{ steps.check_tag.outputs.exists == 'false' }} | |
with: | |
commit: main | |
tag: ${{ steps.package_version.outputs.app_version }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
publish-release: | |
runs-on: ubuntu-latest | |
needs: create-release | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
- name: Install uv | |
uses: astral-sh/setup-uv@e779db74266a80753577425b0f4ee823649f251d # v3 | |
- name: Build for publish | |
id: build_dist | |
run: | | |
uv sync --python 3.10 --frozen | |
uv tool run --from build python -m build | |
echo workspace dir $GITHUB_WORKSPACE | |
- name: Publish to PyPI | |
id: publish-to-pypi | |
uses: pypa/gh-action-pypi-publish@67339c736fd9354cd4f8cb0b744f2b82a74b5c70 # v1.12.3 | |
with: | |
password: ${{ secrets.PYPI_API_TOKEN }} |