-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: python test, lint and policy check workflows #18
Merged
sergiusens
merged 20 commits into
canonical:main
from
lengau:work/CRAFT-3602/test-workflows
Nov 18, 2024
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e982fea
feat: python test workflow
lengau b594ddd
fix: unit tests together
lengau b6f8699
fix: allow older jq
lengau f09b29d
fix: make directory names work on windows
lengau b3ec414
fix: always upload coverage
lengau b6fdf04
fix: remove TICS analysis from python testing job
lengau 4c98695
fix: rename `coverage` target to `test-coverage`
lengau 9878604
fix: replace unit/integration tests with fast/slow
lengau 18ee82c
fix: switch Linux runners to self-hosted
lengau 1708fcb
fix: readme
lengau a0d610e
fix: further adjustments to default platforms
lengau cc12cab
fix: test names
lengau 638279e
fix: pr suggestion
lengau a1c57a0
fix: pr suggestion
lengau 471867e
fix: pr suggestion
lengau 4eafed7
fix: pr feedback about input names
lengau e8b4a5c
fix: pr feedback
lengau f01b4e5
style: autoformat
lengau a5112a1
fix: make the lowest-dependencies platform configurable.
lengau 698fa3b
fix: hash runner info for cache
lengau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Lint Python | ||
on: | ||
workflow_call: | ||
# Because we have a uv.lock file, we can also use this workflow to lint ourselves. | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
files: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Begin snap installs of common linters | ||
id: snap-install | ||
run: | | ||
echo -n 'jobs="$(sudo snap install --no-wait codespell ruff shellcheck)"' >> $GITHUB_OUTPUT | ||
- name: Check out code | ||
uses: actions/checkout@v4 | ||
- name: Set up uv with caching | ||
id: setup-uv | ||
uses: astral-sh/setup-uv@v3 | ||
with: | ||
enable-cache: true | ||
- name: Set up linters | ||
run: | | ||
for job in ${{ steps.snap-install.outputs.jobs }}; do | ||
sudo snap watch $job | ||
done | ||
make setup-lint | ||
- name: Run linters | ||
run: make -k lint |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Check policy | ||
on: | ||
workflow_call: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
cla: | ||
name: Authors signed Canonical CLA | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check if CLA signed | ||
uses: canonical/has-signed-canonical-cla@v1 | ||
commits: | ||
name: Conventional Commits | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: webiny/[email protected] | ||
with: | ||
allowed-commit-types: "build,chore,ci,docs,feat,fix,perf,refactor,style,test" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: QA self-test | ||
on: | ||
pull_request: | ||
|
||
jobs: | ||
lint-python: | ||
uses: ./.github/workflows/lint-python.yaml | ||
test-python: | ||
uses: ./.github/workflows/test-python.yaml | ||
test-python-custom: | ||
uses: ./.github/workflows/test-python.yaml | ||
with: | ||
# Test on many OS's to ensure that these workflows work everywhere. | ||
# Also ensure we can add a list of tags for self-hosted runners. | ||
fast-test-platforms: '[["jammy", "amd64"], ["noble", "arm64"], "ubuntu-22.04", "windows-latest", "macos-latest"]' | ||
fast-test-python-versions: '["3.14"]' | ||
slow-test-platforms: '["ubuntu-latest"]' | ||
slow-test-python-versions: '["3.14"]' | ||
lowest-python-version: "3.0" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
name: Test Python | ||
on: | ||
workflow_call: | ||
inputs: | ||
fast-test-platforms: | ||
type: string | ||
default: '["jammy", "noble"]' | ||
description: | | ||
The platforms to run fast tests on, as a JSON array. | ||
fast-test-python-versions: | ||
type: string | ||
default: '["3.10", "3.11", "3.12", "3.13"]' | ||
description: | | ||
The python versions to run fast tests on, as a JSON array. | ||
slow-test-platforms: | ||
type: string | ||
default: '["jammy"]' | ||
description: | | ||
The platforms to run slow tests on, as a JSON array. | ||
slow-test-python-versions: | ||
type: string | ||
default: '["3.10"]' | ||
description: | | ||
The python versions to run slow tests on, as a JSON array. | ||
lowest-python-platform: | ||
type: string | ||
description: | | ||
The platform to run the lowest python version tests on. | ||
default: "ubuntu-20.04" | ||
lowest-python-version: | ||
type: string | ||
description: | | ||
The Python version to run when using "lowest" resolution for tests. | ||
default: "3.10" | ||
|
||
jobs: | ||
fast: | ||
name: Fast tests | ||
strategy: | ||
matrix: | ||
platform: ${{ fromJson(inputs.fast-test-platforms) }} | ||
runs-on: ${{ matrix.platform }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Hash runner info | ||
id: runner-info | ||
run: | | ||
echo "cache-hash=$(echo '${{ toJSON(matrix.platform) }}' | sha1sum | cut -f1 -d' ')" >> $GITHUB_OUTPUT | ||
- name: Set up uv with caching | ||
id: setup-uv | ||
uses: astral-sh/setup-uv@v3 | ||
with: | ||
enable-cache: true | ||
cache-suffix: ${{ steps.runner-info.outputs.cache-hash }} | ||
- name: Set up tests | ||
shell: bash | ||
run: | | ||
for python_version in $(echo '${{ inputs.fast-test-python-versions }}' | jq -r .[] | tr '\n' ' '); do | ||
python_dirname=$(echo ${{ runner.temp }} | tr '\\' /)/venv_$(echo $python_version | tr . _) | ||
make setup-tests UV_PROJECT_ENVIRONMENT="${python_dirname}" | ||
done | ||
- name: Run tests | ||
shell: bash | ||
run: | | ||
exit_code=0 | ||
for python_version in $(echo '${{ inputs.fast-test-python-versions }}' | jq -r .[] | tr '\n' ' '); do | ||
echo "::group::Python ${python_version}" | ||
python_dirname=$(echo ${{ runner.temp }} | tr '\\' /)/venv_$(echo $python_version | tr . _) | ||
if ! make test-coverage UV_PROJECT_ENVIRONMENT="${python_dirname}" PYTEST_ADDOPTS="-m 'not slow'" | ||
then | ||
exit_code=1 | ||
echo "::error title=TESTS FAILED::Tests failed with Python ${python_version}" | ||
fi | ||
echo "::endgroup::" | ||
done | ||
exit $exit_code | ||
- name: Upload test coverage | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: coverage-fast-${{ matrix.platform }} | ||
overwrite: true | ||
path: | | ||
./coverage.xml | ||
htmlcov/** | ||
slow: | ||
name: Slow tests | ||
strategy: | ||
matrix: | ||
platform: ${{ fromJson(inputs.slow-test-platforms) }} | ||
python-version: ${{ fromJson(inputs.slow-test-python-versions) }} | ||
runs-on: ${{ matrix.platform }} | ||
env: | ||
PYTEST_ADDOPTS: --no-header -v -rN -m 'slow' | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up uv with caching | ||
id: setup-uv | ||
uses: astral-sh/setup-uv@v3 | ||
with: | ||
enable-cache: true | ||
cache-suffix: ${{ toJSON(matrix.platform) }} | ||
- name: Install tools | ||
run: | | ||
make setup-tests | ||
- name: Run tests | ||
run: | | ||
make test-coverage | ||
- name: Upload test coverage | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: coverage-slow-${{ matrix.platform }}-${{ matrix.python-version }} | ||
overwrite: true | ||
path: | | ||
./coverage.xml | ||
htmlcov/** | ||
lowest: | ||
name: Minimum dependencies (all tests) | ||
if: ${{ inputs.lowest-python-version }} != '' | ||
runs-on: ${{ inputs.lowest-python-platform }} | ||
env: | ||
UV_PYTHON: ${{ inputs.lowest-python-version }} | ||
UV_RESOLUTION: lowest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up uv with caching | ||
id: setup-uv | ||
uses: astral-sh/setup-uv@v3 | ||
with: | ||
enable-cache: true | ||
cache-suffix: lowest-jammy | ||
- name: Install tools | ||
run: | | ||
make setup-tests | ||
- name: Run tests | ||
run: | | ||
make test-coverage | ||
- name: Upload test coverage | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: coverage-lowest-py${{ inputs.lowest-python-version }} | ||
overwrite: true | ||
path: | | ||
./coverage.xml | ||
htmlcov/** |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't we need to further restrict these to
amd64
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can and we needn't. I added the architectures in the self-test in order to check that we could add lists of tags, but I figured here it would be a good default to simply run the tests on the first available runner regardless of architecture.