Skip to content

Commit

Permalink
Adjust to upstream.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed May 11, 2024
1 parent 569a022 commit 3874a87
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 49 deletions.
12 changes: 4 additions & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
3 changes: 3 additions & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
name: 🧪

on: # yamllint disable-line rule:truthy
merge_group:
push:
branches-ignore:
- gh-readonly-queue/** # Temporary merge queue-related GH-made branches
pull_request:
# Run once per week (Monday at 10:00 UTC)
schedule:
Expand Down
18 changes: 9 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ ci:

repos:
- repo: https://github.com/asottile/add-trailing-comma.git
rev: v2.4.0
rev: v3.1.0
hooks:
- id: add-trailing-comma

- repo: https://github.com/PyCQA/isort.git
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
args:
- --honor-noqa

- repo: https://github.com/Lucas-C/pre-commit-hooks.git
rev: v1.3.1
rev: v1.5.5
hooks:
- id: remove-tabs

- repo: https://github.com/python-jsonschema/check-jsonschema.git
rev: 0.19.2
rev: 0.28.1
hooks:
- id: check-github-actions
- id: check-github-workflows
Expand All @@ -36,7 +36,7 @@ repos:
- id: check-readthedocs

- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: v4.4.0
rev: v4.5.0
hooks:
# Side-effects:
- id: end-of-file-fixer
Expand All @@ -62,12 +62,12 @@ repos:
language_version: python3

- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
rev: v2.2.6
hooks:
- id: codespell

- repo: https://github.com/adrienverge/yamllint.git
rev: v1.28.0
rev: v1.35.1
hooks:
- id: yamllint
files: \.(yaml|yml)$
Expand All @@ -78,7 +78,7 @@ repos:
- --strict

- repo: https://github.com/PyCQA/flake8.git
rev: 6.0.0
rev: 7.0.0
hooks:
- id: flake8
alias: flake8-no-wps
Expand Down Expand Up @@ -123,7 +123,7 @@ repos:
language_version: python3

- repo: https://github.com/PyCQA/pylint.git
rev: v2.15.9
rev: v3.1.0
hooks:
- id: pylint
args:
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To use the action add the following step to your workflow file (e.g.
with:
ansible-core-version: stable-2.14
pre-test-cmd: echo This runs before the ansible-test invocation
target-python-version: 3.9
target-python-version: 3.11
controller-python-version: auto
testing-type: integration
test-deps: ansible.netcommon
Expand All @@ -32,7 +32,7 @@ To use the action add the following step to your workflow file (e.g.
with:
ansible-core-version: stable-2.14
pre-test-cmd: echo This runs before the ansible-test invocation
target-python-version: 3.9
target-python-version: 3.11
testing-type: units
test-deps: >-
ansible.netcommon
Expand Down Expand Up @@ -89,6 +89,11 @@ Whether to collect and upload coverage information. Can be set to
information except when `pull-request-change-detection` is set to `true`
and the action is called from a Pull Request. **(DEFAULT: `auto`)**

> [!NOTE]
> Coverage is only generated for modules and plugins. If your collection does
> not contain any modules or plugins, set this to `never` to avoid errors in
> the codecov upload step due to no coverage information being available.


### `docker-image`

Expand Down Expand Up @@ -226,7 +231,8 @@ Comma-separated list of sanity tests to skip.

### `sanity-allow-disabled`

Allow sanity tests to run which are disabled by default.
Allow running sanity tests that are disabled by default.
**(DEFAULT: `false`)**


## Related community projects
Expand Down
103 changes: 74 additions & 29 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ inputs:
Replace `python-version` with `origin-python-version`.
It is scheduled to be removed in version 3 of this action.
sanity-tests:
description: Comma-separated list of sanity tests to run. If not present, all applicable tests are run.
description: >-
Comma-separated list of sanity tests to run.
If not present, all applicable tests are run.
sanity-skip-tests:
description: Comma-separated list of sanity tests to skip.
sanity-allow-disabled:
description: Allow sanity tests to run which are disabled by default.
default: false
default: 'false'
target:
description: ansible-test TARGET
target-python-version:
Expand All @@ -101,7 +103,6 @@ inputs:
required: true
test-deps:
description: Test dependencies to install along with this collection

outputs:
ansible-playbook-executable:
description: Path to the auto-installed `ansible-playbook` executable
Expand Down Expand Up @@ -178,22 +179,27 @@ runs:
if origin_python_version == 'auto':
# Determine the maximum Python version supported by the
# given ansible-core version.
python_version_fallback_for_devel = '3.11'
python_version_map = {
'stable-2.9': '3.8',
'stable-2.10': '3.9',
'stable-2.11': '3.9',
'stable-2.12': '3.10',
'stable-2.13': '3.10',
'stable-2.14': '3.11',
'stable-2.15': '3.11',
'stable-2.9': (3, 8),
'stable-2.10': (3, 9),
'stable-2.11': (3, 9),
'stable-2.12': (3, 10),
'stable-2.13': (3, 10),
'stable-2.14': (3, 11),
'stable-2.15': (3, 11),
}
origin_python_version = python_version_map.get(
python_version_fallback_for_devel = max(
set(python_version_map.values()),
)
origin_python_version_tuple = python_version_map.get(
ansible_core_version,
# For any non-stable branch, we assume
# the latest version supported by 'devel':
python_version_fallback_for_devel,
)
origin_python_version = '.'.join(
map(str, origin_python_version_tuple),
)
# Set computed origin-python-version
set_output('origin-python-version', origin_python_version)
Expand Down Expand Up @@ -228,6 +234,7 @@ runs:
pip install
PyYAML
--disable-pip-version-check
--prefer-binary
--user
;
set +x
Expand All @@ -245,11 +252,13 @@ runs:
GHA_CONTROLLER_PYTHON_VERSION: ${{ inputs.controller-python-version }}
GHA_COVERAGE: ${{ inputs.coverage }}
GHA_DOCKER_IMAGE: ${{ inputs.docker-image }}
GHA_INTEGRATION_CONTINUE_ON_ERROR: ${{ inputs.integration-continue-on-error }}
GHA_INTEGRATION_CONTINUE_ON_ERROR: >-
${{ inputs.integration-continue-on-error }}
GHA_INTEGRATION_DIFF: ${{ inputs.integration-diff }}
GHA_INTEGRATION_RETRY_ON_ERROR: ${{ inputs.integration-retry-on-error }}
GHA_PULL_REQUEST_BASE_REF: ${{ github.event.pull_request.base.ref || '' }}
GHA_PULL_REQUEST_CHANGE_DETECTION: ${{ inputs.pull-request-change-detection }}
GHA_PULL_REQUEST_CHANGE_DETECTION: >-
${{ inputs.pull-request-change-detection }}
GHA_SANITY_TESTS: ${{ inputs.sanity-tests }}
GHA_SANITY_SKIP_TESTS: ${{ inputs.sanity-skip-tests }}
GHA_SANITY_ALLOW_DISABLED: ${{ inputs.sanity-allow-disabled }}
Expand All @@ -269,22 +278,33 @@ runs:
def set_output(name, value):
with OUTPUTS_FILE_PATH.open(FILE_APPEND_MODE) as outputs_file:
outputs_file.writelines(f'{name}={value}{os.linesep}')
print(f'GHA output {name}: {value}')
# Input from GHA
gha_ansible_core_version = os.environ['GHA_ANSIBLE_CORE_VERSION']
gha_container_network = os.environ['GHA_CONTAINER_NETWORK']
gha_controller_python_version = os.environ['GHA_CONTROLLER_PYTHON_VERSION']
gha_controller_python_version = (
os.environ['GHA_CONTROLLER_PYTHON_VERSION']
)
gha_coverage = os.environ['GHA_COVERAGE']
gha_docker_image = os.environ['GHA_DOCKER_IMAGE']
gha_integration_continue_on_error = json.loads(os.environ['GHA_INTEGRATION_CONTINUE_ON_ERROR'])
gha_integration_diff = json.loads(os.environ['GHA_INTEGRATION_DIFF'])
gha_integration_retry_on_error = json.loads(os.environ['GHA_INTEGRATION_RETRY_ON_ERROR'])
gha_integration_continue_on_error = json.loads(
os.environ['GHA_INTEGRATION_CONTINUE_ON_ERROR']
)
gha_integration_diff = json.loads(
os.environ['GHA_INTEGRATION_DIFF']
)
gha_integration_retry_on_error = json.loads(
os.environ['GHA_INTEGRATION_RETRY_ON_ERROR']
)
gha_pull_request_branch = os.environ['GHA_PULL_REQUEST_BASE_REF']
gha_pull_request_change_detection = json.loads(os.environ['GHA_PULL_REQUEST_CHANGE_DETECTION'])
gha_pull_request_change_detection = json.loads(
os.environ['GHA_PULL_REQUEST_CHANGE_DETECTION']
)
gha_sanity_tests = os.environ['GHA_SANITY_TESTS']
gha_sanity_skip_tests = os.environ['GHA_SANITY_SKIP_TESTS']
gha_sanity_allow_disabled = json.loads(os.environ['GHA_SANITY_ALLOW_DISABLED'])
gha_sanity_allow_disabled = json.loads(
os.environ['GHA_SANITY_ALLOW_DISABLED']
) is True
gha_target = os.environ['GHA_TARGET']
gha_target_python_version = os.environ['GHA_TARGET_PYTHON_VERSION']
gha_testing_type = os.environ['GHA_TESTING_TYPE']
Expand All @@ -301,7 +321,9 @@ runs:
command = [gha_testing_type, '-v', '--color']
# Compute coverage and change detection arguments
has_change_detection = gha_pull_request_branch and gha_pull_request_change_detection
has_change_detection = (
gha_pull_request_branch and gha_pull_request_change_detection
)
if has_change_detection:
if gha_coverage == 'auto':
print(
Expand Down Expand Up @@ -348,15 +370,20 @@ runs:
if (
gha_testing_type == 'integration'
and gha_ansible_core_version not in {'stable-2.9', 'stable-2.10', 'stable-2.11'}
and gha_ansible_core_version not in {
'stable-2.9', 'stable-2.10', 'stable-2.11'
}
and gha_target_python_version
and gha_controller_python_version not in {'auto', gha_target_python_version}
and gha_controller_python_version not in {
'auto', gha_target_python_version
}
):
command.extend([
'--controller',
f"docker:default,python={gha_controller_python_version}",
'--target',
f"docker:{gha_docker_image or 'default'},python={gha_target_python_version}",
f"docker:{gha_docker_image or 'default'},"
f"python={gha_target_python_version}",
])
else:
command.extend([
Expand Down Expand Up @@ -620,6 +647,24 @@ runs:

- name: Log the next step action
if: steps.ansible-test-command.outputs.has-coverage == 'true'
run: >-
echo ▷ Generating a coverage report only grouped by command...
shell: bash
- name: Generate a coverage report only grouped by command
if: steps.ansible-test-flags.outputs.coverage-arg != ''
run: >-
set -x
;
~/.local/bin/ansible-test coverage xml
-v --requirements
--group-by command
;
set +x
shell: bash
working-directory: ${{ steps.collection-metadata.outputs.checkout-path }}

- name: Log the next step action
if: steps.ansible-test-flags.outputs.coverage-arg != ''
run: >-
echo ▷ Sending the coverage data over to
https://codecov.io/gh/${{ github.repository }}...
Expand Down Expand Up @@ -659,12 +704,12 @@ runs:
run: >-
set +x
;
compgen -G "${{
ls -1 '${{
steps.collection-metadata.outputs.checkout-path
}}/tests/output/reports/coverage=${{
inputs.testing-type
}}=*.xml"
&& ( echo "present=true" >> ${GITHUB_OUTPUT} )
}}.xml'
&& ( echo "present=true" >> "${GITHUB_OUTPUT}" )
;
exit 0
shell: bash
Expand All @@ -678,7 +723,7 @@ runs:
steps.collection-metadata.outputs.checkout-path
}}/tests/output/reports/coverage=${{
inputs.testing-type
}}=python-*.xml
}}.xml
format: markdown
output: both
# Ref: https://github.com/irongut/CodeCoverageSummary/issues/66
Expand Down

0 comments on commit 3874a87

Please sign in to comment.