Skip to content

Use hatch and hatch-vcs #139

Use hatch and hatch-vcs

Use hatch and hatch-vcs #139

Workflow file for this run

name: CI
on:
push:
branches: [main]
pull_request: {}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
FORCE_COLOR: "1"
PIP_DISABLE_PIP_VERSION_CHECK: "1"
PIP_NO_PYTHON_VERSION_WARNING: "1"
jobs:
check-manifest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- run: pipx run check-manifest --ignore "_version.py"
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version-file: .python-version-default
- uses: pre-commit/action@v3.0.1
typing:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version-file: .python-version-default
- name: Install hatch
run: python -Im pip install hatch
- name: type-check
run: hatch run types:run
docs:
name: Build docs and run doctests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
# Keep in sync with tox/docs, hatch.toml and .readthedocs.yaml.
python-version: "3.12"
cache: pip
- name: Install hatch
run: python -Im pip install hatch
- name: Build and check docs
run: hatch run docs:run
- name: Run doctests
run: hatch run docs:doctest
- name: Check changelog
run: hatch run changelog:run
- uses: actions/upload-artifact@v4
with:
name: docs
path: docs/_build/
install-dev:
name: Verify install env
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version-file: .python-version-default
cache: pip
- name: Install in dev mode & import
run: |
python -Im pip install -e .[dev]
python -Ic 'import subliminal; print(subliminal.__version__)'
build-package:
name: Build & verify package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
- uses: hynek/build-and-inspect-python-package@v2
id: baipp
outputs:
# Used to define the matrix for tests below. The value is based on
# packaging metadata (trove classifiers).
supported-python-versions: ${{ steps.baipp.outputs.supported_python_classifiers_json_array }}
test:
name: Test
runs-on: ${{ matrix.os }}
needs: build-package
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
# Created by the build-and-inspect-python-package action above.
py: ${{ fromJson(needs.build-package.outputs.supported-python-versions) }}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.py }}
cache: 'pip'
allow-prereleases: true
- name: Install hatch
run: python -Im pip install hatch
- name: Pick environment to run
env:
PYTHON_VERSION: ${{ matrix.py }}
run: |
import codecs; import os
py = f"tests.py{os.environ.get('PYTHON_VERSION')}"
print(f"Picked {py}")
with codecs.open(os.environ["GITHUB_ENV"], mode="a", encoding="utf-8") as file_handler:
file_handler.write(f"FORCE_COLOR=1\nENV={py}\n")
shell: python
- name: Setup test environment
run: |
hatch -v env create ${ENV}
shell: bash
- name: Run test suite
env:
# Make sure to add `passenv=COVERAGE_FILE` to `[testenv]` in tox.ini
# Make sure to add `overrides = { env.COVERAGE_FILE.env-vars = "COVERAGE_FILE" }` to `[tests]` in hatch.toml
COVERAGE_FILE: ".coverage.${{ matrix.os }}.${{ matrix.py }}"
CI_RUN: "yes"
run: hatch -v run ${ENV}:test-cov
shell: bash
- name: Store coverage file
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.os }}-${{ matrix.py }}
path: .coverage*
include-hidden-files: true
if-no-files-found: error
coverage:
name: Coverage
runs-on: ubuntu-latest
needs: test
permissions:
pull-requests: write
contents: write
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: actions/setup-python@v5
with:
python-version-file: .python-version-default
- uses: hynek/setup-cached-uv@v2
- name: Download coverage data
uses: actions/download-artifact@v4
with:
pattern: coverage-*
merge-multiple: true
- name: Combine coverage
run: |
uv tool install 'coverage[toml]>7'
coverage combine
coverage html --skip-covered --skip-empty
# Report and write to summary.
coverage report --skip-covered --skip-empty --show-missing --format=markdown >> $GITHUB_STEP_SUMMARY
## Report again and fail if under 100%.
#coverage report --fail-under=100
- name: Upload HTML report if check failed.
uses: actions/upload-artifact@v4
with:
name: html-report
path: htmlcov
#if: ${{ failure() }}
- name: Coverage comment
id: coverage_comment
if: github.event_name == 'pull_request'
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Store Pull Request comment to be posted
uses: actions/upload-artifact@v4
if: |
github.event_name == 'pull_request'
&& steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
with:
name: python-coverage-comment-action
path: python-coverage-comment-action.txt
# Ensure everything required is passing for branch protection.
required-checks-pass:
if: always()
needs:
- coverage
- docs
- install-dev
- typing
- pre-commit
- check-manifest
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}