Skip to content

Commit

Permalink
improve check action
Browse files Browse the repository at this point in the history
  • Loading branch information
getzze committed Sep 16, 2024
1 parent 5f7a3e8 commit d6bc87a
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 36 deletions.
133 changes: 101 additions & 32 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,88 +11,127 @@ concurrency:

jobs:
check-manifest:
if: github.event_name != 'schedule'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pipx run check-manifest

pre-commit:
if: github.event_name != 'schedule'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
python-version-file: .python-version-default
- uses: pre-commit/action@v3.0.1

typing:
if: github.event_name != 'schedule'
install-dev:
name: Verify dev env
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: install
python-version-file: .python-version-default
cache: pip

- name: Install in dev mode & import
run: |
python -m pip install -U pip
python -m pip install -e ".[test]"
python -Im pip install -e .[dev]
python -Ic 'import subliminal; print(subliminal.__version__)'
typing:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version-file: .python-version-default
- name: Install tox-uv
run: python -Im pip install tox-uv
- name: type-check
run: |
mypy --install-types --non-interactive --config-file pyproject.toml subliminal tests
run: python -Im tox run -e mypy

docs:
if: github.event_name != 'schedule'
name: Build docs and run doctests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- run: |
python -m venv venv
source ./venv/bin/activate
python -m pip install -e .[docs]
sphinx-build -b html docs/ docs/_build
# Keep in sync with tox/docs and .readthedocs.yaml.
python-version: "3.12"
cache: pip

- name: Install tox-uv
run: python -Im pip install tox-uv
- name: Build docs
run: python -Im tox run -e docs,changelog

- uses: actions/upload-artifact@v4
with:
name: docs
path: docs/_build/

build-package:
name: Build & verify package
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
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
if: github.event_name != 'schedule'
runs-on: ${{ matrix.os }}
needs: build-package
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
exclude:
# macos-latest only work with arm64
- os: macos-latest
python-version: ["3.8", "3.9"]
# Created by the build-and-inspect-python-package action above.
python-version: ${{ fromJson(needs.build-package.outputs.supported-python-versions) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
allow-prereleases: true
- name: Install tox-uv
run: python -Im pip install tox-uv
- name: install
run: python -Im pip install -e .[test]

- uses: hynek/setup-cached-uv@v2

- name: Prepare tox
run: |
python -m pip install --upgrade pip
pip install -e .[test]
- name: run pytest --cov
echo TOX_PYTHON=py$(echo ${{ matrix.python-version }} | tr -d .) >>$GITHUB_ENV
- run: >-
uvx --with=tox-uv
tox run
-e py${{ TOX_PYTHON }}-coverage
env:
COVERAGE_FILE: ".coverage.${{ matrix.os }}.${{ matrix.python-version }}"
# Alternatively you can run coverage with the --parallel flag or add
# `parallel = True` in the coverage config file.
# If using pytest-cov, you can also add the `--cov-append` flag
# directly or through PYTEST_ADD_OPTS.
run: |
pytest --cov --cov-report=xml
- name: Store coverage file
uses: actions/upload-artifact@v4
with:
Expand All @@ -107,10 +146,19 @@ jobs:
pull-requests: write
contents: write
steps:
- uses: actions/checkout@v4
- name: Download pre-built packages
uses: actions/download-artifact@v4
with:
name: Packages
path: dist
- run: tar -xf dist/*.tar.gz --strip-components=1
- uses: actions/setup-python@v5
with:
python-version-file: .python-version-default
- uses: hynek/setup-cached-uv@v2

- uses: actions/download-artifact@v4
id: download
- name: Download coverage data
uses: actions/download-artifact@v4
with:
pattern: coverage-*
merge-multiple: true
Expand All @@ -128,3 +176,24 @@ jobs:
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) }}
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ concurrency:
jobs:
test-api:
name: Test APIs
if: github.event_name == 'schedule'
if: github.repository == 'Diaoul/subliminal' && github.event_name == 'schedule'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ docs = [
"towncrier",
]
test = [
"coverage[toml]>=5.3",
"mypy",
"types-requests",
"types-beautifulsoup4",
"pytest>=6.0",
"pytest-cov",
"pytest-xdist",
Expand Down
3 changes: 0 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ setenv =


[testenv:docs]
package = wheel
wheel_build_env = .pkg
# Keep base_python in-sync with check.yaml/docs and .readthedocs.yaml.
base_python = py312
extras = docs
Expand All @@ -73,5 +71,4 @@ commands =
[testenv:changelog]
extras = docs
allowlist_externals = towncrier
skip_install = true
commands = towncrier build --version main --draft

0 comments on commit d6bc87a

Please sign in to comment.