-
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
Changes from 19 commits
e982fea
b594ddd
b6f8699
f09b29d
b3ec414
b6fdf04
4c98695
9878604
18ee82c
1708fcb
a0d610e
cc12cab
638279e
a1c57a0
471867e
4eafed7
e8b4a5c
f01b4e5
a5112a1
698fa3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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.
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" |
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" |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,146 @@ | ||||||
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: Set up uv with caching | ||||||
id: setup-uv | ||||||
uses: astral-sh/setup-uv@v3 | ||||||
with: | ||||||
enable-cache: true | ||||||
cache-suffix: ${{ toJSON(matrix.platform) }} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the errors in https://github.com/canonical/starflow/actions/runs/11824136927 I think the conversion back to a JSON is giving an invalid cache key. We could try with:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The path doesn't exist because we're not actually using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, I see. Thank you! Fixed :-) |
||||||
- 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.
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.