Update pre-commit (#17) #73
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: Lint, Type-Check, Test, Build and Publish Package | |
on: | |
pull_request: | |
branches: [main] | |
push: | |
branches: [main] | |
tags: ["v*"] | |
jobs: | |
convert-readme: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 18 | |
- name: Convert Project README | |
run: npx downdoc README.adoc | |
- name: Save Converted README | |
uses: actions/upload-artifact@v4 | |
with: | |
name: converted-readme | |
path: README.md | |
uv-check: | |
runs-on: ubuntu-latest | |
outputs: | |
project_name: ${{steps.store-project-name.outputs.project_name}} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Create Blank README.md | |
run: touch README.md | |
- name: Install uv | |
uses: astral-sh/setup-uv@v5 | |
with: | |
enable-cache: true | |
- name: Install jq | |
run: sudo apt-get install jq | |
- name: Store Project Name | |
id: store-project-name | |
run: echo "project_name=$(cat pyproject.toml | uvx --from yq tomlq .project.name -M | |
-r)" >> $GITHUB_OUTPUT | |
- name: Update local package only | |
run: uv lock --upgrade-package ${{steps.store-project-name.outputs.project_name}} | |
- name: Check uv.lock (ensure all dependencies up to date) | |
run: uv lock --check | |
mypy: | |
needs: [uv-check] | |
runs-on: ubuntu-latest | |
env: | |
UV_NO_SYNC: true | |
UV_FROZEN: true | |
UV_PYTHON_DOWNLOADS: never | |
strategy: | |
matrix: | |
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Create Blank README.md | |
run: touch README.md | |
- name: Set Up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{matrix.python-version}} | |
- name: Install uv | |
uses: astral-sh/setup-uv@v5 | |
with: | |
python-version: ${{matrix.python-version}} | |
enable-cache: true | |
- name: Install mypy From Locked Dependencies | |
run: uv sync --no-group dev --group type-check | |
- name: Store Hashed Python Version | |
id: store-hashed-python-version | |
run: echo "hashed_python_version=$(uv run -- python -VV | sha256sum | cut -d' ' -f1)" | |
>> $GITHUB_OUTPUT | |
- uses: actions/cache@v4 | |
with: | |
path: ./.mypy_cache | |
key: mypy|${{steps.store-hashed-python-version.outputs.hashed_python_version}} | |
- name: Run mypy | |
run: uv run -- mypy . # TODO: Add GitHub workflows output format | |
pre-commit: | |
runs-on: ubuntu-latest | |
env: | |
UV_NO_SYNC: true | |
UV_FROZEN: true | |
UV_PYTHON_DOWNLOADS: never | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set Up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version-file: .python-version | |
- name: Install uv | |
uses: astral-sh/setup-uv@v5 | |
with: | |
enable-cache: true | |
- name: Install pre-commit From Locked Dependencies | |
run: uv sync --only-group pre-commit | |
- name: Store Hashed Python Version | |
id: store-hashed-python-version | |
run: echo "hashed_python_version=$(uv run -- python -VV | sha256sum | cut -d' ' -f1)" | |
>> $GITHUB_OUTPUT | |
- uses: actions/cache@v4 | |
with: | |
path: ~/.cache/pre-commit | |
key: pre-commit|${{steps.store-hashed-python-version.outputs.hashed_python_version}}|${{hashFiles('.pre-commit-config.yaml')}} | |
- name: Setup pre-commit Environments | |
run: uv run -- pre-commit install-hooks | |
- name: Store pre-commit Checks Which Require Skipping | |
run: echo "SKIP=check-github-workflows,ruff,uv-lock" >> $GITHUB_ENV | |
- name: Run pre-commit | |
run: uv run -- pre-commit run --all-files --hook-stage manual # TODO: Add GitHub workflows output format | |
pytest: | |
needs: [uv-check] | |
runs-on: ubuntu-latest | |
env: | |
UV_NO_SYNC: true | |
UV_FROZEN: true | |
UV_PYTHON_DOWNLOADS: never | |
strategy: | |
matrix: | |
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Create Blank README.md | |
run: touch README.md | |
- name: Set Up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install uv | |
uses: astral-sh/setup-uv@v5 | |
with: | |
python-version: ${{matrix.python-version}} | |
enable-cache: true | |
- name: Install pytest From Locked Dependencies | |
run: uv sync --no-group dev --group test | |
- name: Store Hashed Python Version | |
id: store-hashed-python-version | |
run: echo "hashed_python_version=$(uv run -- python -VV | sha256sum | cut -d' ' -f1)" | |
>> $GITHUB_OUTPUT | |
- uses: actions/cache@v4 | |
with: | |
path: ./.pytest_cache | |
key: pytest|${{steps.store-hashed-python-version.outputs.hashed_python_version}} | |
- name: Run pytest | |
run: uv run -- pytest # TODO: Add GitHub workflows output format | |
ruff-lint: | |
runs-on: ubuntu-latest | |
env: | |
UV_NO_SYNC: true | |
UV_FROZEN: true | |
UV_PYTHON_DOWNLOADS: never | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set Up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version-file: .python-version | |
- name: Install uv | |
uses: astral-sh/setup-uv@v5 | |
with: | |
enable-cache: true | |
- name: Install ruff From Locked Dependencies | |
run: uv sync --only-group lint-format | |
- name: Store Hashed Python Version | |
id: store-hashed-python-version | |
run: echo "hashed_python_version=$(uv run -- python -VV | sha256sum | cut -d' ' -f1)" | |
>> $GITHUB_OUTPUT | |
- uses: actions/cache@v4 | |
with: | |
path: ./.ruff_cache | |
key: ruff|${{steps.store-hashed-python-version.outputs.hashed_python_version}} | |
- name: Run Ruff | |
run: uv run -- ruff check --no-fix --output-format=github | |
build: | |
needs: [mypy, pre-commit, pytest, ruff-lint, uv-check, convert-readme] | |
runs-on: ubuntu-latest | |
env: | |
UV_NO_SYNC: true | |
UV_FROZEN: true | |
UV_PYTHON_DOWNLOADS: never | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Download Converted README | |
uses: actions/download-artifact@v4 | |
with: | |
name: converted-readme | |
- name: Set Up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version-file: .python-version | |
- name: Install uv | |
uses: astral-sh/setup-uv@v5 | |
with: | |
enable-cache: true | |
- name: Update local package only | |
if: github.ref_type != 'tag' | |
run: uv lock --upgrade-package ${{needs.uv-check.outputs.project_name}} | |
- name: Build Package | |
run: uv build --no-sources --build | |
- name: Save Build Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: built-typed_classproperties-package | |
path: dist/ | |
publish: | |
needs: [build] | |
runs-on: ubuntu-latest | |
environment: publish | |
permissions: | |
id-token: write | |
if: github.ref_type == 'tag' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install uv | |
uses: astral-sh/setup-uv@v5 | |
with: | |
enable-cache: true | |
- name: Download Build Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: built-typed_classproperties-package | |
path: dist/ | |
- name: Publish to PyPI | |
run: uv publish | |
test-publish: | |
needs: [build] | |
runs-on: ubuntu-latest | |
environment: test-publish | |
permissions: | |
id-token: write | |
if: github.ref_type != 'tag' && github.event_name != 'pull_request' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install uv | |
uses: astral-sh/setup-uv@v5 | |
with: | |
enable-cache: true | |
- name: Download Build Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: built-typed_classproperties-package | |
path: dist/ | |
- name: Publish to Test-PyPI | |
run: uv publish --index Test-PyPI | |
release: | |
needs: [publish] | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
id-token: write | |
if: github.ref_type == 'tag' | |
steps: | |
- name: Download Build Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: built-typed_classproperties-package | |
path: dist/ | |
- name: Sign Build Artifacts | |
uses: sigstore/[email protected] | |
with: | |
inputs: ./dist/typed_classproperties-*.tar.gz ./dist/typed_classproperties-*.whl | |
- name: Create GitHub Release | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
run: gh release create '${{ github.ref_name }}' dist/** --repo '${{github.repository}}' | |
--verify-tag --generate-notes |