Skip to content

Commit aa49604

Browse files
bjoernricksgreenbonebot
authored andcommitted
Add: Allow to use uv for the coverage-python action
Use the same pattern as in the lint-python action and allow to set a package manager that defaults to poetry.
1 parent 0ab5a1d commit aa49604

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

coverage-python/README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ jobs:
2222
2323
## Action Configuration
2424
25-
| Input | Description | |
26-
|-------|-------------|-|
27-
| python-version | Python version that should be installed | Optional (default: "3.10") |
28-
| test-command | Command to run the unit tests | Optional (default: `"-m unittest"`)
29-
| poetry-version | Use a specific poetry version. By default the latest release is used. | Optional (default `latest`) |
30-
| cache | Cache dependencies by setting it to `"true"`. | Optional |
31-
| cache-dependency-path | "Used to specify the path to dependency files. Supports wildcards or a list of file names for caching multiple dependencies. | Optional |
32-
| cache-poetry-installation | Cache poetry and its dependencies by setting it to `"true"`. | Optional |
33-
| install-dependencies | Install project dependencies. Default is `"true"`. Set to an other string then `"true"` to not install the dependencies. | Optional (default: `"true"`) |
34-
| working-directory | Working directory where to run the action | Optional (default is `${{ github.workspace }}`) |
35-
| codecov-upload | "Upload coverage to codecov.io. Default is `"true"`. Set to an other string then `"true"` to disable the upload. | Optional (default: `"true"`)
36-
| token | Upload token for codecov.io. | Required only if codecov-upload is `"true"` |
25+
| Input | Description | |
26+
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- |
27+
| python-version | Python version that should be installed | Optional (default: "3.10") |
28+
| package-manager | Package Manager to user. Either `uv` or `poetry` | Optional (default: `poetry`) |
29+
| test-command | Command to run the unit tests | Optional (default: `"-m unittest"`) |
30+
| poetry-version | Use a specific poetry version. By default the latest release is used. | Optional (default: `latest`) |
31+
| uv-version | Use a specific version of uv. By default the latest release is used. | Optional (default: `latest`) |
32+
| cache | Cache dependencies by setting it to `"true"`. | Optional |
33+
| cache-dependency-path | "Used to specify the path to dependency files. Supports wildcards or a list of file names for caching multiple dependencies. | Optional |
34+
| cache-poetry-installation | Cache poetry and its dependencies by setting it to `"true"`. | Optional |
35+
| install-dependencies | Install project dependencies. Default is `"true"`. Set to an other string then `"true"` to not install the dependencies. | Optional (default: `"true"`) |
36+
| working-directory | Working directory where to run the action | Optional (default is `${{ github.workspace }}`) |
37+
| codecov-upload | "Upload coverage to codecov.io. Default is `"true"`. Set to an other string then `"true"` to disable the upload. | Optional (default: `"true"`) |
38+
| token | Upload token for codecov.io. | Required only if codecov-upload is `"true"` |

coverage-python/action.yaml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ inputs:
66
python-version:
77
description: "Python version that should be installed"
88
default: "3.10"
9+
package-manager:
10+
description: "Package manager to use, either 'poetry' or 'uv'. Default is 'poetry'."
11+
default: "poetry"
912
test-command:
1013
description: "Command to run the tests"
1114
required: true
@@ -14,6 +17,8 @@ inputs:
1417
description: "Upload token for codecov.io. Required for private repositories."
1518
poetry-version:
1619
description: "Use a specific poetry version. By default the latest release is used."
20+
uv-version:
21+
description: "Use a specific uv version. By default the latest release is used."
1722
cache:
1823
description: "Cache dependencies by setting it to 'true'."
1924
cache-dependency-path:
@@ -38,6 +43,7 @@ runs:
3843
using: "composite"
3944
steps:
4045
- name: Install poetry
46+
if: ${{ inputs.package-manager == 'poetry' }}
4147
uses: greenbone/actions/poetry@v3
4248
with:
4349
python-version: ${{ inputs.python-version }}
@@ -47,17 +53,26 @@ runs:
4753
cache-poetry-installation: ${{ inputs.cache-poetry-installation }}
4854
install-dependencies: ${{ inputs.install-dependencies }}
4955
working-directory: ${{ inputs.working-directory }}
50-
- run: poetry run coverage run ${{ inputs.test-command }}
56+
- name: Install uv
57+
if: ${{ inputs.package-manager == 'uv' }}
58+
uses: greenbone/actions/uv@v3
59+
with:
60+
python-version: ${{ inputs.python-version }}
61+
uv-version: ${{ inputs.uv-version }}
62+
enable-cache: ${{ inputs.cache }}
63+
cache-dependency-glob: ${{ inputs.cache-dependency-path }}
64+
working-directory: ${{ inputs.working-directory }}
65+
- name: Run unit tests with coverage
66+
run: ${{ inputs.package-manager }} run coverage run ${{ inputs.test-command }}
5167
shell: bash
52-
name: Run unit tests with coverage
5368
working-directory: ${{ inputs.working-directory }}
54-
- run: poetry run coverage xml
69+
- name: Create coverage XML report
70+
run: ${{ inputs.package-manager }} run coverage xml
5571
shell: bash
56-
name: Create coverage XML report
5772
working-directory: ${{ inputs.working-directory }}
58-
- uses: codecov/codecov-action@v5
73+
- name: Upload coverage to codecov.io
5974
if: ${{ inputs.codecov-upload == 'true' }}
75+
uses: codecov/codecov-action@v5
6076
with:
6177
token: ${{ inputs.token }}
6278
fail_ci_if_error: true
63-
name: Upload coverage to codecov.io

0 commit comments

Comments
 (0)