Skip to content
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

Allow to control code coverage #50

Merged
merged 2 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:
- ''
testing-type:
- ''
coverage:
- auto
exclude:
- ansible-core-version: ''
include:
Expand All @@ -54,31 +56,36 @@ jobs:
testing-type: sanity
collection-root: .
collection-src-directory: ./.tmp-action-checkout
coverage: auto
pre-action-cmd: >-
mv -v
.internal/ansible/ansible_collections/internal/test/galaxy.yml .
pre-test-cmd: rm -rfv .internal/
- ansible-core-version: stable-2.12
collection-root: .internal/ansible/ansible_collections/internal/test
collection-src-directory: ./.tmp-action-checkout
coverage: never
origin-python-version: auto
testing-type: sanity
- ansible-core-version: devel
collection-root: .internal/ansible/ansible_collections/internal/test
collection-src-directory: ./.tmp-action-checkout
coverage: always
origin-python-version: auto
testing-type: units
- ansible-core-version: stable-2.13
collection-root: .internal/ansible/ansible_collections/internal/test
# NOTE: A missing `collection-src-directory` input causes
# NOTE: fetching the repo from GitHub.
coverage: auto
origin-python-version: '3.9'
pull-request-change-detection: 'true'
testing-type: integration
- ansible-core-version: stable-2.13
collection-root: .internal/ansible/ansible_collections/internal/test
# NOTE: A missing `collection-src-directory` input causes
# NOTE: fetching the repo from GitHub.
coverage: auto
origin-python-version: auto
testing-type: integration
test-deps: >-
Expand All @@ -87,6 +94,7 @@ jobs:
- ansible-core-version: stable-2.14
collection-root: .internal/ansible/ansible_collections/internal/test
collection-src-directory: ./.tmp-action-checkout
coverage: auto
origin-python-version: >-
3.10
testing-type: integration
Expand All @@ -111,6 +119,7 @@ jobs:
ansible-core-version: ${{ matrix.ansible-core-version }}
collection-root: ${{ matrix.collection-root }}
collection-src-directory: ${{ matrix.collection-src-directory }}
coverage: ${{ matrix.coverage }}
docker-image: ${{ matrix.docker-image }}
git-checkout-ref: ${{ matrix.git-checkout-ref }}
origin-python-version: ${{ matrix.origin-python-version }}
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ repository if set, also this action will not attempt to mutate
its contents)**


### `coverage`

Whether to collect and upload coverage information. Can be set to
`always`, `never`, and `auto`. The value `auto` will upload coverage
information except when `pull-request-change-detection` is set to `true`
and the action is called from a Pull Request. **(DEFAULT: `auto`)**


### `docker-image`

A container image spawned by `ansible-test` **(OPTIONAL)**
Expand Down
21 changes: 19 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ inputs:
A pre-checked out collection directory that's already on disk,
substitutes getting the source from the remote Git repository if
set. This action will not attempt to mutate its contents
coverage:
description: >-
Whether to collect and upload coverage information. Can be set to
`always`, `never`, and `auto`. The value `auto` will upload coverage
information except when `pull-request-change-detection` is set to `true`
and the action is called from a Pull Request.
default: auto
docker-image:
description: Docker image used by ansible-test
git-checkout-ref:
Expand Down Expand Up @@ -226,12 +233,22 @@ runs:
inputs.pull-request-change-detection
}}')
pull_request_branch = '${{ github.event.pull_request.base.ref || '' }}'
coverage = '${{ inputs.coverage }}'

# Validate GHA inputs
if coverage not in {'always', 'never', 'auto'}:
print(
'::error ::`coverage` must have one of the values `always`,'
felixfontein marked this conversation as resolved.
Show resolved Hide resolved
f' `never`, or `auto`. The current value is `{coverage}`.'
)
sys.exit(1)

# Compute coverage and change detection arguments
coverage_arg = '--coverage'
coverage_arg = '' if coverage == 'never' else '--coverage'
change_detection_arg = ''
if pull_request_branch and pull_request_change_detection:
coverage_arg = ''
if coverage == 'auto':
coverage_arg = ''
change_detection_arg = (
f'--changed --base-branch {pull_request_branch}'
)
Expand Down