From cf25a093230865fdce94e07f5376c4e948288b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sviatoslav=20Sydorenko=20=28=D0=A1=D0=B2=D1=8F=D1=82=D0=BE?= =?UTF-8?q?=D1=81=D0=BB=D0=B0=D0=B2=20=D0=A1=D0=B8=D0=B4=D0=BE=D1=80=D0=B5?= =?UTF-8?q?=D0=BD=D0=BA=D0=BE=29?= Date: Tue, 17 Sep 2024 22:45:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Upload=20ansible-test=20coverage?= =?UTF-8?q?=20to=20Codecov=20(#15527)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 66 +++++++++++++++++++++++++++++++++++++++- Makefile | 19 ++++++++++-- 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6da76033b53d..72eac92a0186 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -210,8 +210,50 @@ jobs: run: python3 -m pip install --upgrade ansible-core - name: Run sanity tests + id: make-run run: make test_collection_sanity + - name: Upload test coverage to Codecov + if: >- + !cancelled() + && steps.make-run.outputs.cov-report-files != '' + uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: >- + ${{ + toJSON(env.UPSTREAM_REPOSITORY_ID == github.repository_id) + }} + files: >- + ${{ steps.make-run.outputs.cov-report-files }} + flags: >- + CI-GHA, + ansible-test, + sanity, + OS-${{ + runner.os + }} + token: ${{ secrets.CODECOV_TOKEN }} + - name: Upload test results to Codecov + if: >- + !cancelled() + && steps.make-run.outputs.test-result-files != '' + uses: codecov/test-results-action@v1 + with: + fail_ci_if_error: >- + ${{ + toJSON(env.UPSTREAM_REPOSITORY_ID == github.repository_id) + }} + files: >- + ${{ steps.make-run.outputs.test-result-files }} + flags: >- + CI-GHA, + ansible-test, + sanity, + OS-${{ + runner.os + }} + token: ${{ secrets.CODECOV_TOKEN }} + collection-integration: name: awx_collection integration runs-on: ubuntu-latest @@ -243,6 +285,7 @@ jobs: python3 -m pip install -r awx_collection/requirements.txt - name: Run integration tests + id: make-run run: | echo "::remove-matcher owner=python::" # Disable annoying annotations from setup-python echo '[general]' > ~/.tower_cli.cfg @@ -250,10 +293,31 @@ jobs: echo 'oauth_token = ${{ steps.awx.outputs.admin-token }}' >> ~/.tower_cli.cfg echo 'verify_ssl = false' >> ~/.tower_cli.cfg TARGETS="$(ls awx_collection/tests/integration/targets | grep '${{ matrix.target-regex.regex }}' | tr '\n' ' ')" - make COLLECTION_VERSION=100.100.100-git COLLECTION_TEST_TARGET="--coverage --requirements $TARGETS" test_collection_integration + make COLLECTION_VERSION=100.100.100-git COLLECTION_TEST_TARGET="--requirements $TARGETS" test_collection_integration env: ANSIBLE_TEST_PREFER_PODMAN: 1 + - name: Upload test coverage to Codecov + if: >- + !cancelled() + && steps.make-run.outputs.cov-report-files != '' + uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: >- + ${{ + toJSON(env.UPSTREAM_REPOSITORY_ID == github.repository_id) + }} + files: >- + ${{ steps.make-run.outputs.cov-report-files }} + flags: >- + CI-GHA, + ansible-test, + integration, + OS-${{ + runner.os + }} + token: ${{ secrets.CODECOV_TOKEN }} + # Upload coverage report as artifact - uses: actions/upload-artifact@v3 if: always() diff --git a/Makefile b/Makefile index 124119ce703b..252b3c6982a2 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ COLLECTION_TEST_TARGET ?= # args for collection install COLLECTION_PACKAGE ?= awx COLLECTION_NAMESPACE ?= awx -COLLECTION_INSTALL = ~/.ansible/collections/ansible_collections/$(COLLECTION_NAMESPACE)/$(COLLECTION_PACKAGE) +COLLECTION_INSTALL = $(HOME)/.ansible/collections/ansible_collections/$(COLLECTION_NAMESPACE)/$(COLLECTION_PACKAGE) COLLECTION_TEMPLATE_VERSION ?= false # NOTE: This defaults the container image version to the branch that's active @@ -424,10 +424,23 @@ test_collection_sanity: if ! [ -x "$(shell command -v ansible-test)" ]; then pip install ansible-core; fi ansible --version COLLECTION_VERSION=1.0.0 $(MAKE) install_collection - cd $(COLLECTION_INSTALL) && ansible-test sanity $(COLLECTION_SANITY_ARGS) + cd $(COLLECTION_INSTALL) && \ + ansible-test sanity $(COLLECTION_SANITY_ARGS) --coverage --junit && \ + ansible-test coverage xml --requirements --group-by command --group-by version + @if [ "${GITHUB_ACTIONS}" = "true" ]; \ + then \ + echo cov-report-files="$$(find "$(COLLECTION_INSTALL)/tests/output/reports/" -type f -name 'coverage=sanity*.xml' -print0 | tr '\0' ',' | sed 's#,$$##')" >> "${GITHUB_OUTPUT}"; \ + echo test-result-files="$$(find "$(COLLECTION_INSTALL)/tests/output/junit/" -type f -name '*.xml' -print0 | tr '\0' ',' | sed 's#,$$##')" >> "${GITHUB_OUTPUT}"; \ + fi test_collection_integration: install_collection - cd $(COLLECTION_INSTALL) && ansible-test integration -vvv $(COLLECTION_TEST_TARGET) + cd $(COLLECTION_INSTALL) && \ + ansible-test integration --coverage -vvv $(COLLECTION_TEST_TARGET) && \ + ansible-test coverage xml --requirements --group-by command --group-by version + @if [ "${GITHUB_ACTIONS}" = "true" ]; \ + then \ + echo cov-report-files="$$(find "$(COLLECTION_INSTALL)/tests/output/reports/" -type f -name 'coverage=integration*.xml' -print0 | tr '\0' ',' | sed 's#,$$##')" >> "${GITHUB_OUTPUT}"; \ + fi test_unit: @if [ "$(VENV_BASE)" ]; then \