From 8ac3e5eba7bb6c73e223d7e3579c9a92f9df245e Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Fri, 13 Mar 2026 13:08:41 +1100 Subject: [PATCH] Updated posting of coverage comments to replace existing comments. --- .circleci/config.yml | 13 +- .circleci/post-coverage-comment.sh | 69 ++++++++++ .circleci/vortex-test-common.yml | 13 +- .github/workflows/build-test-deploy.yml | 2 + .../continuous-integration/circleci.mdx | 5 +- .../continuous-integration/github-actions.mdx | 6 +- .vortex/docs/content/tools/phpunit.mdx | 8 +- .../.github/workflows/build-test-deploy.yml | 2 + .../ciprovider_circleci/.circleci/config.yml | 13 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.circleci/config.yml | 13 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.circleci/config.yml | 13 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.github/workflows/build-test-deploy.yml | 2 +- .../.circleci/config.yml | 13 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.circleci/config.yml | 13 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.circleci/config.yml | 13 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.github/workflows/build-test-deploy.yml | 2 +- .../timezone_circleci/.circleci/config.yml | 13 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.circleci/config.yml | 13 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.github/workflows/build-test-deploy.yml | 4 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.circleci/config.yml | 13 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.circleci/config.yml | 13 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.github/workflows/build-test-deploy.yml | 2 +- .../.circleci/config.yml | 13 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.circleci/config.yml | 13 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.circleci/config.yml | 13 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.circleci/config.yml | 13 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.circleci/config.yml | 13 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.github/workflows/build-test-deploy.yml | 4 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.circleci/config.yml | 13 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.circleci/config.yml | 13 +- .../.circleci/post-coverage-comment.sh | 69 ++++++++++ .../.github/workflows/build-test-deploy.yml | 4 +- .../bats/unit/post-coverage-comment.bats | 125 ++++++++++++++++++ 51 files changed, 1553 insertions(+), 240 deletions(-) create mode 100755 .circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/ciprovider_circleci/.circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/deploy_types_all_circleci/.circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/deploy_types_none_circleci/.circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/deps_updates_provider_ci_circleci/.circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/migration_disabled_circleci/.circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/migration_enabled_circleci/.circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/timezone_circleci/.circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/tools_groups_no_be_lint_circleci/.circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/tools_groups_no_be_tests_circleci/.circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/tools_groups_no_fe_lint_circleci/.circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/tools_groups_no_fe_lint_no_theme_circleci/.circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/tools_no_behat_circleci/.circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/tools_no_eslint_circleci/.circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/tools_no_phpcs_circleci/.circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/tools_no_phpmd_circleci/.circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/tools_no_phpstan_circleci/.circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/tools_no_phpunit_circleci/.circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/tools_no_rector_circleci/.circleci/post-coverage-comment.sh create mode 100755 .vortex/installer/tests/Fixtures/handler_process/tools_no_stylelint_circleci/.circleci/post-coverage-comment.sh create mode 100644 .vortex/tests/bats/unit/post-coverage-comment.bats diff --git a/.circleci/config.yml b/.circleci/config.yml index 866a10216..34ac90792 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -410,18 +410,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.circleci/post-coverage-comment.sh b/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.circleci/vortex-test-common.yml b/.circleci/vortex-test-common.yml index ca7da0961..417fd7028 100644 --- a/.circleci/vortex-test-common.yml +++ b/.circleci/vortex-test-common.yml @@ -276,18 +276,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.github/workflows/build-test-deploy.yml b/.github/workflows/build-test-deploy.yml index c1b05525b..c7c483eab 100644 --- a/.github/workflows/build-test-deploy.yml +++ b/.github/workflows/build-test-deploy.yml @@ -442,7 +442,9 @@ jobs: if: ${{ github.event_name == 'pull_request' && (matrix.instance == 0 || strategy.job-total == 1) && vars.VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP != '1' }} uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2 with: + header: coverage-gha message: | + **Code coverage (GitHub Actions)** ``` ${{ env.COVERAGE_CONTENT }} ``` diff --git a/.vortex/docs/content/continuous-integration/circleci.mdx b/.vortex/docs/content/continuous-integration/circleci.mdx index 532fe14cf..b85ae041b 100644 --- a/.vortex/docs/content/continuous-integration/circleci.mdx +++ b/.vortex/docs/content/continuous-integration/circleci.mdx @@ -224,5 +224,6 @@ environment variable in **Project Settings → Environment Variables**. Default is `90` (percent). Coverage reports can be posted as PR comments. This requires a `GITHUB_TOKEN` -environment variable with permission to post comments. To disable PR comments, -set `VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP` to `1`. +environment variable with permission to post comments. Each new report replaces +the previous one — older comments are minimized to keep the PR timeline clean. +To disable PR comments, set `VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP` to `1`. diff --git a/.vortex/docs/content/continuous-integration/github-actions.mdx b/.vortex/docs/content/continuous-integration/github-actions.mdx index 1ddb895e9..e0a2688f5 100644 --- a/.vortex/docs/content/continuous-integration/github-actions.mdx +++ b/.vortex/docs/content/continuous-integration/github-actions.mdx @@ -192,5 +192,7 @@ Configure the threshold by setting the `VORTEX_CI_CODE_COVERAGE_THRESHOLD` variable in **Settings → Secrets and variables → Actions → Variables**. Default is `90` (percent). -Coverage reports are automatically posted as PR comments. To disable this, set -`VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP` to `1`. +Coverage reports are automatically posted as PR comments. Each new report +replaces the previous one — older comments are minimized to keep the PR +timeline clean. To disable this, set `VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP` +to `1`. diff --git a/.vortex/docs/content/tools/phpunit.mdx b/.vortex/docs/content/tools/phpunit.mdx index 31ca614f1..f535cae2e 100644 --- a/.vortex/docs/content/tools/phpunit.mdx +++ b/.vortex/docs/content/tools/phpunit.mdx @@ -153,8 +153,12 @@ minimum percentage (default: `90`). ### PR comments -Coverage reports are posted as PR comments automatically. Set -`VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP` to `1` to disable. +Coverage reports are posted as PR comments automatically. Each new report +replaces the previous one — older comments are minimized to keep the PR +timeline clean. The comment includes a header indicating the CI source +(GitHub Actions or CircleCI). + +Set `VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP` to `1` to disable. ### Ignoring lines from coverage diff --git a/.vortex/installer/tests/Fixtures/handler_process/_baseline/.github/workflows/build-test-deploy.yml b/.vortex/installer/tests/Fixtures/handler_process/_baseline/.github/workflows/build-test-deploy.yml index 607e0c112..e8f0d2e7d 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/_baseline/.github/workflows/build-test-deploy.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/_baseline/.github/workflows/build-test-deploy.yml @@ -394,7 +394,9 @@ jobs: if: ${{ github.event_name == 'pull_request' && (matrix.instance == 0 || strategy.job-total == 1) && vars.VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP != '1' }} uses: marocchino/sticky-pull-request-comment@__HASH__ # __VERSION__ with: + header: coverage-gha message: | + **Code coverage (GitHub Actions)** ``` ${{ env.COVERAGE_CONTENT }} ``` diff --git a/.vortex/installer/tests/Fixtures/handler_process/ciprovider_circleci/.circleci/config.yml b/.vortex/installer/tests/Fixtures/handler_process/ciprovider_circleci/.circleci/config.yml index 4694d69d7..d6fa3a565 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/ciprovider_circleci/.circleci/config.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/ciprovider_circleci/.circleci/config.yml @@ -365,18 +365,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.vortex/installer/tests/Fixtures/handler_process/ciprovider_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/ciprovider_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/ciprovider_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/deploy_types_all_circleci/.circleci/config.yml b/.vortex/installer/tests/Fixtures/handler_process/deploy_types_all_circleci/.circleci/config.yml index 4694d69d7..d6fa3a565 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/deploy_types_all_circleci/.circleci/config.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/deploy_types_all_circleci/.circleci/config.yml @@ -365,18 +365,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.vortex/installer/tests/Fixtures/handler_process/deploy_types_all_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/deploy_types_all_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/deploy_types_all_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/deploy_types_none_circleci/.circleci/config.yml b/.vortex/installer/tests/Fixtures/handler_process/deploy_types_none_circleci/.circleci/config.yml index de047a5ec..924d47e70 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/deploy_types_none_circleci/.circleci/config.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/deploy_types_none_circleci/.circleci/config.yml @@ -365,18 +365,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.vortex/installer/tests/Fixtures/handler_process/deploy_types_none_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/deploy_types_none_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/deploy_types_none_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/deploy_types_none_gha/.github/workflows/build-test-deploy.yml b/.vortex/installer/tests/Fixtures/handler_process/deploy_types_none_gha/.github/workflows/build-test-deploy.yml index 1eb62f15f..effe39a19 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/deploy_types_none_gha/.github/workflows/build-test-deploy.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/deploy_types_none_gha/.github/workflows/build-test-deploy.yml @@ -1,4 +1,4 @@ -@@ -465,79 +465,3 @@ +@@ -467,79 +467,3 @@ timeout-minutes: 120 # Cancel the action after 15 minutes, regardless of whether a connection has been established. with: detached: true diff --git a/.vortex/installer/tests/Fixtures/handler_process/deps_updates_provider_ci_circleci/.circleci/config.yml b/.vortex/installer/tests/Fixtures/handler_process/deps_updates_provider_ci_circleci/.circleci/config.yml index 4694d69d7..d6fa3a565 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/deps_updates_provider_ci_circleci/.circleci/config.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/deps_updates_provider_ci_circleci/.circleci/config.yml @@ -365,18 +365,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.vortex/installer/tests/Fixtures/handler_process/deps_updates_provider_ci_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/deps_updates_provider_ci_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/deps_updates_provider_ci_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/migration_disabled_circleci/.circleci/config.yml b/.vortex/installer/tests/Fixtures/handler_process/migration_disabled_circleci/.circleci/config.yml index 4694d69d7..d6fa3a565 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/migration_disabled_circleci/.circleci/config.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/migration_disabled_circleci/.circleci/config.yml @@ -365,18 +365,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.vortex/installer/tests/Fixtures/handler_process/migration_disabled_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/migration_disabled_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/migration_disabled_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_circleci/.circleci/config.yml b/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_circleci/.circleci/config.yml index 0a96df21a..93f6a46bf 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_circleci/.circleci/config.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_circleci/.circleci/config.yml @@ -374,18 +374,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/migration_enabled_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/provision_profile/.github/workflows/build-test-deploy.yml b/.vortex/installer/tests/Fixtures/handler_process/provision_profile/.github/workflows/build-test-deploy.yml index 40b1d9790..40811a217 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/provision_profile/.github/workflows/build-test-deploy.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/provision_profile/.github/workflows/build-test-deploy.yml @@ -175,7 +175,7 @@ - name: Login to container registry run: ./scripts/vortex/login-container-registry.sh -@@ -469,7 +329,6 @@ +@@ -471,7 +331,6 @@ deploy: runs-on: ubuntu-latest needs: [build, lint] diff --git a/.vortex/installer/tests/Fixtures/handler_process/timezone_circleci/.circleci/config.yml b/.vortex/installer/tests/Fixtures/handler_process/timezone_circleci/.circleci/config.yml index 4694d69d7..d6fa3a565 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/timezone_circleci/.circleci/config.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/timezone_circleci/.circleci/config.yml @@ -365,18 +365,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.vortex/installer/tests/Fixtures/handler_process/timezone_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/timezone_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/timezone_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_be_lint_circleci/.circleci/config.yml b/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_be_lint_circleci/.circleci/config.yml index 00df02ad5..61e18627c 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_be_lint_circleci/.circleci/config.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_be_lint_circleci/.circleci/config.yml @@ -349,18 +349,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_be_lint_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_be_lint_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_be_lint_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_be_tests/.github/workflows/build-test-deploy.yml b/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_be_tests/.github/workflows/build-test-deploy.yml index 9e1cd8bba..1d99d14b3 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_be_tests/.github/workflows/build-test-deploy.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_be_tests/.github/workflows/build-test-deploy.yml @@ -9,7 +9,7 @@ - name: Lint module code with NodeJS linters run: docker compose exec -T cli bash -c "yarn run lint" continue-on-error: ${{ vars.VORTEX_CI_NODEJS_LINT_IGNORE_FAILURE == '1' }} -@@ -364,72 +360,6 @@ +@@ -364,74 +360,6 @@ docker compose cp -L .data/db.sql cli:/app/.data/db.sql fi docker compose exec $(env | cut -f1 -d= | sed 's/^/-e /') -T cli ./scripts/vortex/provision.sh @@ -43,7 +43,9 @@ - if: ${{ github.event_name == 'pull_request' && (matrix.instance == 0 || strategy.job-total == 1) && vars.VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP != '1' }} - uses: marocchino/sticky-pull-request-comment@__HASH__ # __VERSION__ - with: +- header: coverage-gha - message: | +- **Code coverage (GitHub Actions)** - ``` - ${{ env.COVERAGE_CONTENT }} - ``` diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_be_tests_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_be_tests_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_be_tests_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_fe_lint_circleci/.circleci/config.yml b/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_fe_lint_circleci/.circleci/config.yml index bd41e4dc4..1d1757698 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_fe_lint_circleci/.circleci/config.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_fe_lint_circleci/.circleci/config.yml @@ -360,18 +360,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_fe_lint_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_fe_lint_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_fe_lint_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_fe_lint_no_theme_circleci/.circleci/config.yml b/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_fe_lint_no_theme_circleci/.circleci/config.yml index ef8da94e5..68ca5ebe0 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_fe_lint_no_theme_circleci/.circleci/config.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_fe_lint_no_theme_circleci/.circleci/config.yml @@ -354,18 +354,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_fe_lint_no_theme_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_fe_lint_no_theme_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_groups_no_fe_lint_no_theme_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_no_behat/.github/workflows/build-test-deploy.yml b/.vortex/installer/tests/Fixtures/handler_process/tools_no_behat/.github/workflows/build-test-deploy.yml index 0307118f1..d46db57b6 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/tools_no_behat/.github/workflows/build-test-deploy.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_no_behat/.github/workflows/build-test-deploy.yml @@ -9,7 +9,7 @@ - name: Lint module code with NodeJS linters run: docker compose exec -T cli bash -c "yarn run lint" continue-on-error: ${{ vars.VORTEX_CI_NODEJS_LINT_IGNORE_FAILURE == '1' }} -@@ -419,18 +415,6 @@ +@@ -421,18 +417,6 @@ fi env: VORTEX_CI_CODE_COVERAGE_THRESHOLD: ${{ vars.VORTEX_CI_CODE_COVERAGE_THRESHOLD || '90' }} diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_no_behat_circleci/.circleci/config.yml b/.vortex/installer/tests/Fixtures/handler_process/tools_no_behat_circleci/.circleci/config.yml index ffd4756dd..c15652b01 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/tools_no_behat_circleci/.circleci/config.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_no_behat_circleci/.circleci/config.yml @@ -361,18 +361,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_no_behat_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/tools_no_behat_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_no_behat_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_no_eslint_circleci/.circleci/config.yml b/.vortex/installer/tests/Fixtures/handler_process/tools_no_eslint_circleci/.circleci/config.yml index bd41e4dc4..1d1757698 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/tools_no_eslint_circleci/.circleci/config.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_no_eslint_circleci/.circleci/config.yml @@ -360,18 +360,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_no_eslint_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/tools_no_eslint_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_no_eslint_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpcs_circleci/.circleci/config.yml b/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpcs_circleci/.circleci/config.yml index acc01b294..4e0f8a8fc 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpcs_circleci/.circleci/config.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpcs_circleci/.circleci/config.yml @@ -361,18 +361,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpcs_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpcs_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpcs_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpmd_circleci/.circleci/config.yml b/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpmd_circleci/.circleci/config.yml index 69501a577..c9c5df218 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpmd_circleci/.circleci/config.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpmd_circleci/.circleci/config.yml @@ -361,18 +361,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpmd_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpmd_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpmd_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpstan_circleci/.circleci/config.yml b/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpstan_circleci/.circleci/config.yml index 9d7ed0015..cecaf305f 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpstan_circleci/.circleci/config.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpstan_circleci/.circleci/config.yml @@ -361,18 +361,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpstan_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpstan_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpstan_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpunit/.github/workflows/build-test-deploy.yml b/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpunit/.github/workflows/build-test-deploy.yml index 6e37120de..080601734 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpunit/.github/workflows/build-test-deploy.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpunit/.github/workflows/build-test-deploy.yml @@ -1,4 +1,4 @@ -@@ -366,60 +366,6 @@ +@@ -366,62 +366,6 @@ docker compose exec $(env | cut -f1 -d= | sed 's/^/-e /') -T cli ./scripts/vortex/provision.sh timeout-minutes: 30 @@ -30,7 +30,9 @@ - if: ${{ github.event_name == 'pull_request' && (matrix.instance == 0 || strategy.job-total == 1) && vars.VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP != '1' }} - uses: marocchino/sticky-pull-request-comment@__HASH__ # __VERSION__ - with: +- header: coverage-gha - message: | +- **Code coverage (GitHub Actions)** - ``` - ${{ env.COVERAGE_CONTENT }} - ``` diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpunit_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpunit_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_no_phpunit_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_no_rector_circleci/.circleci/config.yml b/.vortex/installer/tests/Fixtures/handler_process/tools_no_rector_circleci/.circleci/config.yml index 5d91f3141..a5eb315b5 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/tools_no_rector_circleci/.circleci/config.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_no_rector_circleci/.circleci/config.yml @@ -361,18 +361,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_no_rector_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/tools_no_rector_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_no_rector_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_no_stylelint_circleci/.circleci/config.yml b/.vortex/installer/tests/Fixtures/handler_process/tools_no_stylelint_circleci/.circleci/config.yml index 4694d69d7..d6fa3a565 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/tools_no_stylelint_circleci/.circleci/config.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_no_stylelint_circleci/.circleci/config.yml @@ -365,18 +365,7 @@ jobs: command: | [ "${CIRCLE_NODE_TOTAL:-1}" -gt 1 ] && [ "${CIRCLE_NODE_INDEX:-0}" -ne 0 ] && exit 0 [ "${VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP:-0}" = "1" ] && exit 0 - [ -z "${CIRCLE_PULL_REQUEST}" ] && exit 0 - [ -z "${GITHUB_TOKEN}" ] && exit 0 - COVERAGE_CONTENT=$(sed '/./,$!d' /tmp/artifacts/coverage/phpunit/coverage.txt) - PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) - REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" - curl -s -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ - -d "$(jq -n --arg body "\`\`\` - ${COVERAGE_CONTENT} - \`\`\`" '{body: $body}')" + .circleci/post-coverage-comment.sh /tmp/artifacts/coverage/phpunit/coverage.txt - run: name: Upload code coverage reports to Codecov diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_no_stylelint_circleci/.circleci/post-coverage-comment.sh b/.vortex/installer/tests/Fixtures/handler_process/tools_no_stylelint_circleci/.circleci/post-coverage-comment.sh new file mode 100755 index 000000000..505bedb89 --- /dev/null +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_no_stylelint_circleci/.circleci/post-coverage-comment.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +## +## Post code coverage summary as a PR comment on GitHub. +## +## Minimizes previous coverage comments before posting a new one. +## +## Environment variables: +## CIRCLE_PULL_REQUEST - CircleCI PR URL. +## GITHUB_TOKEN - GitHub token for API access. +## CIRCLE_PROJECT_USERNAME - GitHub org/user. +## CIRCLE_PROJECT_REPONAME - GitHub repo name. +## +## Usage: +## .circleci/post-coverage-comment.sh /path/to/coverage.txt + +set -euo pipefail + +COVERAGE_FILE="${1:-}" + +if [ -z "${COVERAGE_FILE}" ] || [ ! -f "${COVERAGE_FILE}" ]; then + echo "ERROR: Coverage file not found: ${COVERAGE_FILE}" >&2 + exit 1 +fi + +if [ -z "${CIRCLE_PULL_REQUEST:-}" ]; then + echo "Not a pull request. Skipping." + exit 0 +fi + +if [ -z "${GITHUB_TOKEN:-}" ]; then + echo "GITHUB_TOKEN is not set. Skipping." + exit 0 +fi + +COVERAGE_CONTENT=$(sed '/./,$!d' "${COVERAGE_FILE}") +PR_NUMBER=$(echo "${CIRCLE_PULL_REQUEST}" | cut -d'/' -f 7) +REPO_SLUG="${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}" + +MARKER="" + +BODY=$(jq -n --arg body "**Code coverage (CircleCI)** +\`\`\` +${COVERAGE_CONTENT} +\`\`\` +${MARKER}" '{body: $body}') + +# Minimize previous coverage comments. +COMMENTS_JSON=$(curl -s \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments?per_page=100") + +EXISTING_IDS=$(echo "${COMMENTS_JSON}" | jq -r '.[] | select(.body | contains("")) | .node_id') + +for NODE_ID in ${EXISTING_IDS}; do + GRAPHQL_BODY=$(jq -n --arg id "${NODE_ID}" '{query: "mutation($id:ID!){minimizeComment(input:{subjectId:$id,classifier:OUTDATED}){minimizedComment{isMinimized}}}", variables: {id: $id}}') + curl -s -X POST \ + -H "Authorization: bearer ${GITHUB_TOKEN}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/graphql" \ + -d "${GRAPHQL_BODY}" +done + +# Post new coverage comment. +curl -s -X POST \ + -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO_SLUG}/issues/${PR_NUMBER}/comments" \ + -d "${BODY}" diff --git a/.vortex/installer/tests/Fixtures/handler_process/tools_none/.github/workflows/build-test-deploy.yml b/.vortex/installer/tests/Fixtures/handler_process/tools_none/.github/workflows/build-test-deploy.yml index 9f0aa463c..34a64ce2d 100644 --- a/.vortex/installer/tests/Fixtures/handler_process/tools_none/.github/workflows/build-test-deploy.yml +++ b/.vortex/installer/tests/Fixtures/handler_process/tools_none/.github/workflows/build-test-deploy.yml @@ -41,7 +41,7 @@ - name: Lint theme code with NodeJS linters if: ${{ vars.VORTEX_FRONTEND_BUILD_SKIP != '1' }} run: docker compose exec -T cli bash -c "yarn --cwd=\${WEBROOT}/themes/custom/\${DRUPAL_THEME} run lint" -@@ -364,72 +339,6 @@ +@@ -364,74 +339,6 @@ docker compose cp -L .data/db.sql cli:/app/.data/db.sql fi docker compose exec $(env | cut -f1 -d= | sed 's/^/-e /') -T cli ./scripts/vortex/provision.sh @@ -75,7 +75,9 @@ - if: ${{ github.event_name == 'pull_request' && (matrix.instance == 0 || strategy.job-total == 1) && vars.VORTEX_CI_CODE_COVERAGE_PR_COMMENT_SKIP != '1' }} - uses: marocchino/sticky-pull-request-comment@__HASH__ # __VERSION__ - with: +- header: coverage-gha - message: | +- **Code coverage (GitHub Actions)** - ``` - ${{ env.COVERAGE_CONTENT }} - ``` diff --git a/.vortex/tests/bats/unit/post-coverage-comment.bats b/.vortex/tests/bats/unit/post-coverage-comment.bats new file mode 100644 index 000000000..1c963afc0 --- /dev/null +++ b/.vortex/tests/bats/unit/post-coverage-comment.bats @@ -0,0 +1,125 @@ +#!/usr/bin/env bats +## +# Unit tests for .circleci/post-coverage-comment.sh +# +# shellcheck disable=SC2030,SC2031,SC2034 + +load ../_helper.bash + +@test "post-coverage-comment: missing coverage file" { + pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 + + export CIRCLE_PULL_REQUEST="https://github.com/myorg/myrepo/pull/123" + export GITHUB_TOKEN="token12345" + export CIRCLE_PROJECT_USERNAME="myorg" + export CIRCLE_PROJECT_REPONAME="myrepo" + + run .circleci/post-coverage-comment.sh /nonexistent/file.txt + assert_failure + assert_output_contains "ERROR: Coverage file not found" + + popd >/dev/null || exit 1 +} + +@test "post-coverage-comment: no arguments" { + pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 + + export CIRCLE_PULL_REQUEST="https://github.com/myorg/myrepo/pull/123" + export GITHUB_TOKEN="token12345" + + run .circleci/post-coverage-comment.sh + assert_failure + assert_output_contains "ERROR: Coverage file not found" + + popd >/dev/null || exit 1 +} + +@test "post-coverage-comment: skip when not a pull request" { + pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 + + mkdir -p .logs/coverage/phpunit + echo "Lines: 100.00%" >.logs/coverage/phpunit/coverage.txt + + unset CIRCLE_PULL_REQUEST + export GITHUB_TOKEN="token12345" + + run .circleci/post-coverage-comment.sh .logs/coverage/phpunit/coverage.txt + assert_success + assert_output_contains "Not a pull request. Skipping." + + popd >/dev/null || exit 1 +} + +@test "post-coverage-comment: skip when no GITHUB_TOKEN" { + pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 + + mkdir -p .logs/coverage/phpunit + echo "Lines: 100.00%" >.logs/coverage/phpunit/coverage.txt + + export CIRCLE_PULL_REQUEST="https://github.com/myorg/myrepo/pull/123" + unset GITHUB_TOKEN + + run .circleci/post-coverage-comment.sh .logs/coverage/phpunit/coverage.txt + assert_success + assert_output_contains "GITHUB_TOKEN is not set. Skipping." + + popd >/dev/null || exit 1 +} + +@test "post-coverage-comment: post with no existing comments" { + pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 + + mkdir -p .logs/coverage/phpunit + printf "Code Coverage Report:\n Lines: 100.00%%\n" >.logs/coverage/phpunit/coverage.txt + + declare -a STEPS=( + # GET existing comments - return empty array. + '@curl * # []' + # POST new comment. + '@curl * # {"id": 1}' + ) + + mocks="$(run_steps "setup")" + + export CIRCLE_PULL_REQUEST="https://github.com/myorg/myrepo/pull/123" + export GITHUB_TOKEN="token12345" + export CIRCLE_PROJECT_USERNAME="myorg" + export CIRCLE_PROJECT_REPONAME="myrepo" + + run .circleci/post-coverage-comment.sh .logs/coverage/phpunit/coverage.txt + assert_success + + run_steps "assert" "${mocks[@]}" + + popd >/dev/null || exit 1 +} + +@test "post-coverage-comment: minimize existing comments before posting" { + pushd "${LOCAL_REPO_DIR}" >/dev/null || exit 1 + + mkdir -p .logs/coverage/phpunit + printf "Code Coverage Report:\n Lines: 95.00%%\n" >.logs/coverage/phpunit/coverage.txt + + declare -a STEPS=( + # GET existing comments - return one with marker. + '@curl * # [{"node_id": "MDEyOklzc3VlQ29tbWVudDE=", "body": "old coverage "}]' + # POST GraphQL to minimize existing comment. + '@curl * # {"data":{"minimizeComment":{"minimizedComment":{"isMinimized":true}}}}' + # POST new comment. + '@curl * # {"id": 2}' + ) + + mocks="$(run_steps "setup")" + + export CIRCLE_PULL_REQUEST="https://github.com/myorg/myrepo/pull/456" + export GITHUB_TOKEN="token12345" + export CIRCLE_PROJECT_USERNAME="myorg" + export CIRCLE_PROJECT_REPONAME="myrepo" + + run .circleci/post-coverage-comment.sh .logs/coverage/phpunit/coverage.txt + assert_success + + run_steps "assert" "${mocks[@]}" + + popd >/dev/null || exit 1 +}