From 40cb17b5b62c44caa119a006f5edb00cac709bdf Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 27 Nov 2022 20:08:11 +0100 Subject: [PATCH] Implement toggles for integration tests flags Currently, all of `--retry-on-error`, `--continue-on-error` and `--diff` are always passed to `ansible-test` when this action is running integration tests. This patch converts each of them into individual inputs that are enabled by default but can be set to `false` when it's useful to the tested collection. The new input names are: * `integration-continue-on-error` * `integration-diff` * `integration-retry-on-error` --- .github/workflows/test-action.yml | 29 +++++++++++++++++++++++ README.md | 21 +++++++++++++++++ action.yml | 38 ++++++++++++++++++++++++++++++- 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index 5d7b028..4980866 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -30,6 +30,12 @@ jobs: - default git-checkout-ref: - '' + integration-continue-on-error: + - '' + integration-diff: + - '' + integration-retry-on-error: + - '' origin-python-version: - '' pre-action-cmd: @@ -57,6 +63,9 @@ jobs: collection-root: . collection-src-directory: ./.tmp-action-checkout coverage: auto + integration-continue-on-error: true + integration-diff: true + integration-retry-on-error: true pre-action-cmd: >- mv -v .internal/ansible/ansible_collections/internal/test/galaxy.yml . @@ -65,12 +74,18 @@ jobs: collection-root: .internal/ansible/ansible_collections/internal/test collection-src-directory: ./.tmp-action-checkout coverage: never + integration-continue-on-error: true + integration-diff: true + integration-retry-on-error: true 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 + integration-continue-on-error: true + integration-diff: true + integration-retry-on-error: true origin-python-version: auto testing-type: units - ansible-core-version: stable-2.13 @@ -78,6 +93,9 @@ jobs: # NOTE: A missing `collection-src-directory` input causes # NOTE: fetching the repo from GitHub. coverage: auto + integration-continue-on-error: false + integration-diff: true + integration-retry-on-error: true origin-python-version: '3.9' pull-request-change-detection: 'true' testing-type: integration @@ -86,6 +104,9 @@ jobs: # NOTE: A missing `collection-src-directory` input causes # NOTE: fetching the repo from GitHub. coverage: auto + integration-continue-on-error: true + integration-diff: true + integration-retry-on-error: false origin-python-version: auto testing-type: integration test-deps: >- @@ -95,6 +116,9 @@ jobs: collection-root: .internal/ansible/ansible_collections/internal/test collection-src-directory: ./.tmp-action-checkout coverage: auto + integration-continue-on-error: true + integration-diff: false + integration-retry-on-error: true origin-python-version: >- 3.10 testing-type: integration @@ -122,6 +146,11 @@ jobs: coverage: ${{ matrix.coverage }} docker-image: ${{ matrix.docker-image }} git-checkout-ref: ${{ matrix.git-checkout-ref }} + integration-continue-on-error: >- + ${{ matrix.integration-continue-on-error || 'true' }} + integration-diff: ${{ matrix.integration-diff || 'true' }} + integration-retry-on-error: >- + ${{ matrix.integration-retry-on-error || 'true' }} origin-python-version: ${{ matrix.origin-python-version }} pre-test-cmd: ${{ matrix.pre-test-cmd }} pull-request-change-detection: >- diff --git a/README.md b/README.md index 9f9b9de..103e522 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,27 @@ Committish to check out, unused if `collection-src-directory` is set **(OPTIONAL)** +### `integration-continue-on-error` + +Whether the continue with the other integration tests when an error occurs. +If set to `false`, will stop on the first error. When set to `false` and +`coverage=auto`, code coverage uploading will be disabled. +**(DEFAULT: `true`)** + + +### `integration-diff` + +Whether to show diff output when calling actions in integration tests. +Actions can override this by specifying `diff: false` or `diff: true`. +**(DEFAULT: `true`)** + + +### `integration-retry-on-error` + +Whether to retry the current integration test once when an error happens. +**(DEFAULT: `true`)** + + ### `origin-python-version` Environment Python version. The value `auto` uses the maximum Python diff --git a/action.yml b/action.yml index 4d21db6..e62bc46 100644 --- a/action.yml +++ b/action.yml @@ -45,6 +45,21 @@ inputs: description: >- Committish to check out, unused if `collection-src-directory` is set + integration-continue-on-error: + description: >- + Whether the continue with the other integration tests when an error + occurs. If set to `false`, will stop on the first error. When set to + `false` and `coverage=auto`, code coverage uploading will be disabled. + default: 'true' + integration-diff: + description: >- + Whether to show diff output when calling actions in integration tests. + Actions can override this by specifying `diff: false` or `diff: true`. + default: 'true' + integration-retry-on-error: + description: >- + Whether to retry the current integration test once when an error happens. + default: 'true' origin-python-version: description: >- Environment Python version. The value `auto` uses the maximum Python @@ -234,6 +249,13 @@ runs: }}') pull_request_branch = '${{ github.event.pull_request.base.ref || '' }}' coverage = '${{ inputs.coverage }}' + integration_continue_on_error = json.loads('${{ + inputs.integration-continue-on-error + }}') + integration_diff = json.loads('${{ inputs.integration-diff }}') + integration_retry_on_error = json.loads('${{ + inputs.integration-retry-on-error + }}') # Validate GHA inputs if coverage not in {'always', 'never', 'auto'}: @@ -248,14 +270,28 @@ runs: change_detection_arg = '' if pull_request_branch and pull_request_change_detection: if coverage == 'auto': + print( + 'Disabling coverage reporting due to pull request ' + 'change detection being enabled.', + ) coverage_arg = '' change_detection_arg = ( f'--changed --base-branch {pull_request_branch}' ) + # Determine integration test flags + integration_flags = [] + if integration_retry_on_error: + integration_flags.append('--retry-on-error') + if integration_continue_on_error: + integration_flags.append('--continue-on-error') + if integration_diff: + integration_flags.append('--diff') + # Set computed coverage-arg and change-detection-arg set_output('coverage-arg', coverage_arg) set_output('change-detection-arg', change_detection_arg) + set_output('integration-flags', ' '.join(integration_flags)) shell: python - name: Log the next step action @@ -485,7 +521,7 @@ runs: }} ${{ inputs.testing-type == 'integration' - && '--retry-on-error --continue-on-error --diff' + && steps.ansible-test-flags.outputs.integration-flags || '' }} ${{