From d3603a72af7ddabd45fe8991383eaeafc7f6a9c1 Mon Sep 17 00:00:00 2001 From: Peter Downey Date: Tue, 24 Nov 2026 02:28:12 -0500 Subject: [PATCH 1/3] Upload the unit test coverage to Codacy The unit-coverage job wrote clover.xml but never sent it, so Codacy showed no coverage. The job now downloads Codacy's coverage reporter 14.1.3, checks it against its SHA-512, and uploads the report for the commit Codacy analyzes (a pull request's head commit). It reads the repository token from the CODACY_PROJECT_TOKEN secret. Dependabot's and forks' pull requests skip the upload; a failed upload fails the job on pushes and is reported without blocking a pull request. Co-Authored-By: Claude Opus 5.5 --- .../ISSUE_TEMPLATE/unit-coverage-failure.md | 5 +++- .github/workflows/wp-compatibility-test.yml | 30 ++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/unit-coverage-failure.md b/.github/ISSUE_TEMPLATE/unit-coverage-failure.md index 4655240..3445ee0 100644 --- a/.github/ISSUE_TEMPLATE/unit-coverage-failure.md +++ b/.github/ISSUE_TEMPLATE/unit-coverage-failure.md @@ -30,6 +30,9 @@ coverage" fails when the suite covers less than 30% of the production lines. The 2. If the stage is `run_unit_tests_with_coverage`, a unit test failed; fix the code or the test. 3. If the stage is `check_line_coverage`, add unit tests for the new or changed code. The coverage report is in the job log and in the `wp-compat-unit-coverage` artifact. -4. Re-run the workflow. +4. If the stage is `upload_coverage`, Codacy did not receive the coverage report. Check that the + `CODACY_PROJECT_TOKEN` secret holds the repository's token from Codacy (Settings > Coverage), and + read the step's log for the reporter's error. The tests and the minimum coverage passed. +5. Re-run the workflow. This issue was automatically created by the CI/CD pipeline. diff --git a/.github/workflows/wp-compatibility-test.yml b/.github/workflows/wp-compatibility-test.yml index 7e7da33..edb170c 100644 --- a/.github/workflows/wp-compatibility-test.yml +++ b/.github/workflows/wp-compatibility-test.yml @@ -1378,6 +1378,33 @@ jobs: } ' "$RUNNER_TEMP/es-optimizer-diagnostics/clover.xml" "$MINIMUM_LINE_COVERAGE" + - name: Upload coverage to Codacy + id: upload_coverage + # Dependabot's and forks' pull requests get no secrets, so they skip the upload. A failed + # upload fails the job on pushes; on a pull request it is reported without blocking it. + if: ${{ github.actor != 'dependabot[bot]' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }} + continue-on-error: ${{ github.event_name == 'pull_request' }} + env: + CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} + # Codacy's coverage reporter, pinned: update the version and the SHA-512 together, from + # the release's codacy-coverage-reporter-linux.SHA512SUM file + # (https://github.com/codacy/codacy-coverage-reporter/releases). Dependabot does not track it. + CODACY_REPORTER_VERSION: '14.1.3' + CODACY_REPORTER_SHA512: '73a6c93fc5db509fd0423d6e545759c3f61d8360ee12054e32a9277daab6add0da6c6639248f6ed6c0042366440293ebc0b6144325aef52c5d3d4b230d65eb17' + # Codacy analyzes a pull request's head commit, not the merge commit GitHub checks out + COMMIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} + run: | + if [ -z "$CODACY_PROJECT_TOKEN" ]; then + echo "::error::The CODACY_PROJECT_TOKEN secret is not set, so Codacy cannot receive this commit's coverage." + exit 1 + fi + reporter="$RUNNER_TEMP/codacy-coverage-reporter" + curl --fail --silent --show-error --location --retry 3 --output "$reporter" \ + "https://github.com/codacy/codacy-coverage-reporter/releases/download/$CODACY_REPORTER_VERSION/codacy-coverage-reporter-linux" + echo "$CODACY_REPORTER_SHA512 $reporter" | sha512sum --check --strict - + chmod +x "$reporter" + "$reporter" report --commit-uuid "$COMMIT_SHA" -r "$RUNNER_TEMP/es-optimizer-diagnostics/clover.xml" + - name: Preserve diagnostic summary id: preserve_diagnostics if: ${{ always() }} @@ -1389,6 +1416,7 @@ jobs: install_composer_dependencies=${{ steps.install_composer_dependencies.outcome }} run_unit_tests_with_coverage=${{ steps.run_unit_tests_with_coverage.outcome }} check_line_coverage=${{ steps.check_line_coverage.outcome }} + upload_coverage=${{ steps.upload_coverage.outcome }} run: | mkdir -p "$RUNNER_TEMP/es-optimizer-diagnostics" printf '%s\n' "$STEP_RESULTS" > "$RUNNER_TEMP/es-optimizer-diagnostics/steps.txt" @@ -1429,7 +1457,7 @@ jobs: uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5 # v2.9.2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - FAILURE_STAGE: ${{ steps.checkout_code.outcome == 'failure' && 'checkout_code' || steps.setup_php_8_4.outcome == 'failure' && 'setup_php_8_4' || steps.install_composer_dependencies.outcome == 'failure' && 'install_composer_dependencies' || steps.run_unit_tests_with_coverage.outcome == 'failure' && 'run_unit_tests_with_coverage' || steps.check_line_coverage.outcome == 'failure' && 'check_line_coverage' || 'unknown_or_canceled' }} + FAILURE_STAGE: ${{ steps.checkout_code.outcome == 'failure' && 'checkout_code' || steps.setup_php_8_4.outcome == 'failure' && 'setup_php_8_4' || steps.install_composer_dependencies.outcome == 'failure' && 'install_composer_dependencies' || steps.run_unit_tests_with_coverage.outcome == 'failure' && 'run_unit_tests_with_coverage' || steps.check_line_coverage.outcome == 'failure' && 'check_line_coverage' || steps.upload_coverage.outcome == 'failure' && 'upload_coverage' || 'unknown_or_canceled' }} PHP_VERSION: '8.4' RUN_ID: ${{ github.run_id }} WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} From a30e0a99e6fc407a6c4a954f2011164594d57691 Mon Sep 17 00:00:00 2001 From: Peter Downey Date: Tue, 24 Nov 2026 03:11:08 -0500 Subject: [PATCH 2/3] Name the Codacy page that issues repository tokens The coverage issue template sent readers to Settings > Coverage. Codacy creates repository API tokens under the repository's Settings > API tokens, shows each one once, and expires it within a year. Co-Authored-By: Claude Opus 5.5 --- .github/ISSUE_TEMPLATE/unit-coverage-failure.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/unit-coverage-failure.md b/.github/ISSUE_TEMPLATE/unit-coverage-failure.md index 3445ee0..98811ba 100644 --- a/.github/ISSUE_TEMPLATE/unit-coverage-failure.md +++ b/.github/ISSUE_TEMPLATE/unit-coverage-failure.md @@ -31,7 +31,8 @@ coverage" fails when the suite covers less than 30% of the production lines. The 3. If the stage is `check_line_coverage`, add unit tests for the new or changed code. The coverage report is in the job log and in the `wp-compat-unit-coverage` artifact. 4. If the stage is `upload_coverage`, Codacy did not receive the coverage report. Check that the - `CODACY_PROJECT_TOKEN` secret holds the repository's token from Codacy (Settings > Coverage), and + `CODACY_PROJECT_TOKEN` secret holds a current repository API token from Codacy (the repository's + Settings > API tokens; Codacy shows a new token once, and each one expires within a year), and read the step's log for the reporter's error. The tests and the minimum coverage passed. 5. Re-run the workflow. From 697342f57c3a88f313d632d06193d8539563b004 Mon Sep 17 00:00:00 2001 From: Peter Downey Date: Tue, 24 Nov 2026 03:21:16 -0500 Subject: [PATCH 3/3] Download Codacy's coverage reporter over HTTPS only curl followed redirects to any protocol (SonarCloud S6506). The reporter download now uses --proto '=https', which also limits the redirects curl follows. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/wp-compatibility-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wp-compatibility-test.yml b/.github/workflows/wp-compatibility-test.yml index edb170c..a94ff34 100644 --- a/.github/workflows/wp-compatibility-test.yml +++ b/.github/workflows/wp-compatibility-test.yml @@ -1399,7 +1399,7 @@ jobs: exit 1 fi reporter="$RUNNER_TEMP/codacy-coverage-reporter" - curl --fail --silent --show-error --location --retry 3 --output "$reporter" \ + curl --proto '=https' --fail --silent --show-error --location --retry 3 --output "$reporter" \ "https://github.com/codacy/codacy-coverage-reporter/releases/download/$CODACY_REPORTER_VERSION/codacy-coverage-reporter-linux" echo "$CODACY_REPORTER_SHA512 $reporter" | sha512sum --check --strict - chmod +x "$reporter"