Skip to content

Commit

Permalink
V2 (#8)
Browse files Browse the repository at this point in the history
* testing v2

* back to uuid

* change path

* map site packages

* remove ending wildcard

* disable pip version

* trim down

* cleanup

* tweaks

* update default

* fix

* remove inline comment

* readme
  • Loading branch information
tlambert03 authored May 6, 2024
1 parent 1924a14 commit c993a64
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 132 deletions.
6 changes: 3 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
- package-ecosystem: github-actions
directory: /
schedule:
interval: "weekly"
interval: weekly
17 changes: 6 additions & 11 deletions .github/workflows/test-dependents.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,38 @@ on:
dependency-ref:
required: false
type: string
default: ""
description: Ref to checkout in dependency-repo. Defaults to HEAD in default branch.
python-version:
required: false
type: string
default: "3.x"
description: "Python version to use. Passed to `actions/setup-python`."
default: 3.x
description: Python version to use. Passed to `actions/setup-python`.
os:
required: false
type: string
default: ubuntu-latest
description: "Operating system to use. Passed to `runs-on:`."
description: Operating system to use. Passed to `runs-on:`.
host-extras:
required: false
type: string
default: ""
description: Extras to use when installing host (package running this workflow).
dependency-extras:
required: false
type: string
default: "test"
default: test
description: Extras to use when installing dependency-repo.
qt:
required: false
type: string
default: ""
description: "Version of Qt to install."
description: Version of Qt to install.
post-install-cmd:
required: false
type: string
default: ""
description: Command(s) to run after installing dependencies.
pytest-args:
required: false
type: string
default: ""
description: "Additional arguments to pass to pytest. Can be used to specify paths or for for `-k`, `-x`, etc."
description: Additional arguments to pass to pytest. Can be used to specify paths or for for `-k`, `-x`, etc.

jobs:
test:
Expand Down
152 changes: 82 additions & 70 deletions .github/workflows/test-pyrepo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,109 +7,122 @@ on:
python-version:
required: false
type: string
default: "3.x"
description: "Python version to use. Passed to `actions/setup-python`."
default: 3.x
description: Python version to use. Passed to `actions/setup-python`.
os:
required: false
type: string
default: ubuntu-latest
description: "Operating system to use. Passed to `runs-on:`."
description: Operating system to use. Passed to `runs-on:`.
extras:
required: false
type: string
default: test
description: "Package extras to install (may use commas for multiples `'test,docs'`). If you don't have an extra named 'test' you should change this."
description: >
Package extras to install (may use commas for multiples `'test,docs'`).
If you don't have an extra named 'test' you should change this.
pip-install-flags:
required: false
type: string
default: ""
description: "Additional flags to pass to pip install. Can be used for `--editable`, `--no-deps`, etc."
description: >
Additional flags to pass to pip install.
Can be used for `--editable`, `--no-deps`, etc.
pip-install-pre-release:
required: false
type: boolean
default: false
description: "Whether to install pre-releases in the pip install phase with `--pre`."
description: Whether to install pre-releases in the pip install phase with `--pre`.
# example >>> pip-install-pre-release: github.event_name == 'schedule'
pip-install-min-reqs:
required: false
type: boolean
default: false
description: "Whether to install the *minimum* declared dependency versions."
description: >
Whether to install the *minimum* declared dependency versions.
pip-pre-installs:
required: false
type: string
default: ""
description: "Packages to install *before* calling `pip install .`"
default: ''
description: >
Packages to install *before* calling `pip install .`
pip-post-installs:
required: false
type: string
default: ""
description: "Packages to install *after* `pip install .`. (these are called with `--force-reinstall`.)"
description: >
Packages to install *after* `pip install .`.
(these are called with `--force-reinstall`.)
qt:
required: false
type: string
default: ""
description: "Version of qt to install (or none if blank). Will also install qt-libs and run tests headlessly if not blank."
description: >
Version of qt to install (or none if blank).
Will also install qt-libs and run tests headlessly if not blank.
fetch-depth:
required: false
type: number
default: 1
description: "The number of commits to fetch. 0 indicates all history for all branches and tags."
description: >
The number of commits to fetch. 0 indicates all history for all branches and tags.
python-cache-dependency-path:
required: false
type: string
default: "pyproject.toml"
description: "passed to `actions/setup-python`"
default: pyproject.toml
description: >
passed to `actions/setup-python`
pytest-args:
required: false
type: string
default: ""
description: "Additional arguments to pass to pytest. Can be used to specify paths or for for `-k`, `-x`, etc."
pytest-cov-flags:
required: false
type: string
default: "--cov --cov-report=xml --cov-report=term-missing"
description: "Flags to pass to pytest-cov. Can be used for `--cov-fail-under`, `--cov-branch`, etc. Note: it's best to specify `[tool.coverage.run] source = ['your_package']`."
description: >
Additional arguments to pass to pytest.
Can be used to specify paths or for for `-k`, `-x`, etc.
fail-on-coverage-error:
required: false
type: boolean
default: true
description: "Fail the build if codecov action fails."
description: >
Fail the build if codecov action fails.
hatch-build-hooks-enable:
required: false
type: boolean
default: false
description: "Value for [`HATCH_BUILD_HOOKS_ENABLE`](https://hatch.pypa.io/latest/config/build/#environment-variables)."
description: >
Value for
[`HATCH_BUILD_HOOKS_ENABLE`](https://hatch.pypa.io/latest/config/build/#environment-variables).
report-failures:
required: false
type: boolean
default: false
description: "Whether to create a GitHub issue when a test fails. Good for cron jobs."
# example >>> report-failures: github.event_name == 'schedule'
type: string
description: >
(true or false). Whether to create a GitHub issue when a test fails.
If not set, will be true for scheduled runs, and false otherwise.
cache-key:
required: false
type: string
default: ""
description: "Cache key to use for caching. If not set, no caching will be used."
description: >
Cache key to use for caching. If not set, no caching will be used.
cache-path:
required: false
type: string
default: ""
description: "Path to cache. If not set, no caching will be used."
description: >
Path to cache. If not set, no caching will be used.
cache-script:
required: false
type: string
default: ""
description: "Script to run to create the cache. If not set, no caching will be used."
description: >
Script to run to create the cache. If not set, no caching will be used.
coverage-upload:
required: false
type: string
default: "codecov"
description: "Where to upload coverage data. Options: `'artifact'`, `'codecov'`. If using 'artifact', coverage must be sent to codecov in a separate workflow. (*see upload-coverage.yml*)"
default: codecov
description: >
How to upload coverage data. Options are `'artifact'`, `'codecov'`.
If using 'artifact', coverage must be sent to codecov in a separate
workflow. (*see upload-coverage.yml*)
secrets:
codecov-token:
codecov_token:
required: false
description: "Token for codecov-action. Only used if `pytest-cov-flags` is not empty and coverage-upload is 'codecov'."
description: >
Token for codecov-action. Only used if `pytest-cov-flags`
is not empty and coverage-upload is 'codecov'.
jobs:
test:
Expand All @@ -119,29 +132,9 @@ jobs:
HATCH_BUILD_HOOKS_ENABLE: ${{ inputs.hatch-build-hooks-enable }}
MIN_REQS_TEST: ${{ inputs.pip-install-min-reqs }}
USE_CACHE: ${{ inputs.cache-key != '' && inputs.cache-path != '' && 'true' || 'false' }}
PIP_DISABLE_PIP_VERSION_CHECK: 1
REPORT_FAIL: ${{ inputs.report-failures && inputs.report-failures || (github.event_name == 'schedule' && 'true' || 'false')}}
steps:
- name: Generate UUID
shell: bash
run: |
if [[ "$RUNNER_OS" == "Windows" ]]; then
echo "UUID=$(powershell -Command "[guid]::NewGuid().ToString()")" >> $GITHUB_ENV
else
echo "UUID=$(uuidgen)" >> $GITHUB_ENV
fi
- name: Set COVERAGE_FILE
shell: bash
run: echo "COVERAGE_FILE=.coverage.$UUID" >> $GITHUB_ENV

- name: Set CODECOV_TOKEN
shell: bash
run: |
if [ -n "${{ secrets.codecov-token }}" ]; then
echo "CODECOV_TOKEN=${{ secrets.codecov-token }}" >> $GITHUB_ENV
else
echo "CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }}" >> $GITHUB_ENV
fi
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v4
with:
Expand All @@ -152,7 +145,7 @@ jobs:
with:
python-version: ${{ inputs.python-version }}
cache-dependency-path: ${{ inputs.python-cache-dependency-path }}
cache: "pip"
cache: pip

- run: python -m pip install --upgrade pip

Expand Down Expand Up @@ -198,19 +191,21 @@ jobs:
if: ${{ inputs.pip-post-installs != '' }}
run: python -m pip install ${{ inputs.pip-post-installs }} --force-reinstall

- name: Install coverage
run: python -m pip install coverage

- name: Run tests
if: ${{ inputs.qt == '' }}
run: python -m pytest --color=yes ${{ inputs.pytest-cov-flags }} ${{ inputs.pytest-args }}
run: coverage run -p -m pytest --color=yes ${{ inputs.pytest-args }}

- name: Run tests (headless)
if: ${{ inputs.qt != '' }}
uses: aganders3/headless-gui@v2
with:
run: python -m pytest --color=yes ${{ inputs.pytest-cov-flags }} ${{ inputs.pytest-args }}
run: coverage run -p -m pytest --color=yes ${{ inputs.pytest-args }}

- name: Report failure
# common usage might be: report-failures: github.event_name == 'schedule'
if: ${{ failure() && inputs.report-failures }}
if: ${{ failure() && env.REPORT_FAIL == 'true'}}
uses: actions/github-script@v7
env:
ACTION_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
Expand Down Expand Up @@ -246,17 +241,34 @@ jobs:
console.log('A new issue was created to report a failing test.');
}
- name: Generage coverage report
if: inputs.coverage-upload == 'codecov'
run: |
python -m coverage combine --append
python -m coverage xml -o coverage.xml
python -m coverage report
- name: codecov v4
if: inputs.pytest-cov-flags != '' && inputs.coverage-upload == 'codecov'
if: inputs.coverage-upload == 'codecov'
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: ${{ inputs.fail-on-coverage-error }}
verbose: true
token: ${{ env.CODECOV_TOKEN }}
token: ${{ secrets.codecov_token }}

- name: Generate UUID
if: inputs.coverage-upload == 'artifact'
shell: bash
run: |
if [[ "$RUNNER_OS" == "Windows" ]]; then
echo "UUID=$(powershell -Command "[guid]::NewGuid().ToString()")" >> $GITHUB_ENV
else
echo "UUID=$(uuidgen)" >> $GITHUB_ENV
fi
- name: Upload coverage data
uses: actions/upload-artifact@v4
if: inputs.pytest-cov-flags != '' && inputs.coverage-upload == 'artifact'
if: inputs.coverage-upload == 'artifact'
with:
name: covreport-${{ inputs.os }}-py${{ inputs.python-version }}-${{ env.UUID }}
path: ./.coverage*
Loading

0 comments on commit c993a64

Please sign in to comment.