From d6bc87a9c06bc991ab1a0713cb85e547735268a6 Mon Sep 17 00:00:00 2001 From: getzze Date: Mon, 16 Sep 2024 22:46:08 +0100 Subject: [PATCH] improve check action --- .github/workflows/check.yaml | 133 +++++++++++++++++++++++-------- .github/workflows/run-tests.yaml | 2 +- pyproject.toml | 3 + tox.ini | 3 - 4 files changed, 105 insertions(+), 36 deletions(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 2f3376ca..353f507e 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -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: @@ -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 @@ -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) }} diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index fc7370e1..2e8c24f5 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 34bbb323..86b69094 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,7 +62,10 @@ docs = [ "towncrier", ] test = [ + "coverage[toml]>=5.3", "mypy", + "types-requests", + "types-beautifulsoup4", "pytest>=6.0", "pytest-cov", "pytest-xdist", diff --git a/tox.ini b/tox.ini index 32f48887..60c7d85d 100644 --- a/tox.ini +++ b/tox.ini @@ -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 @@ -73,5 +71,4 @@ commands = [testenv:changelog] extras = docs allowlist_externals = towncrier -skip_install = true commands = towncrier build --version main --draft