From aa4693bf5ebcc2ed1381591e2ff12b5fa0a76624 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Fri, 28 Feb 2025 10:53:47 -0700 Subject: [PATCH 01/75] ci(MM-63199): code coverage tracking --- .github/actions/test/action.yaml | 7 ++++++- jest.config.js | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index 4ee3d61c3e..89d611b9ff 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -17,8 +17,13 @@ runs: shell: bash run: | echo "::group::run-tests" - npm test + npm run test:coverage echo "::endgroup::" + - name: ci/upload-coverage + uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 + with: + name: test-coverage-result + path: coverage/coverage-summary.json - name: ci/check-i18n shell: bash run: | diff --git a/jest.config.js b/jest.config.js index 022dfb171f..b1ec8e4047 100644 --- a/jest.config.js +++ b/jest.config.js @@ -13,7 +13,7 @@ module.exports = { clearMocks: true, setupFilesAfterEnv: ['/test/setup.ts'], collectCoverageFrom: ['app/**/*.{js,jsx,ts,tsx}'], - coverageReporters: ['lcov', 'text-summary'], + coverageReporters: ['lcov', 'text-summary', 'json-summary'], testPathIgnorePatterns: ['/node_modules/'], coveragePathIgnorePatterns: ['/node_modules/', '/components/', '/screens/'], transformIgnorePatterns: [ From 05847ce2d20d2fb3da438f40f525392ba40c237a Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Fri, 28 Feb 2025 14:29:15 -0700 Subject: [PATCH 02/75] try to download existing coverage file --- .github/actions/test/action.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index 89d611b9ff..5519570f13 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -19,6 +19,11 @@ runs: echo "::group::run-tests" npm run test:coverage echo "::endgroup::" + - name: ci/download-current-coverage + uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4 + with: + path: current-coverage/coverage-summary.json + - name: ci/upload-coverage uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 with: From ece130b0d4f109caea986319b02000d96d69b127 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Fri, 28 Feb 2025 15:11:30 -0700 Subject: [PATCH 03/75] read coverage --- .github/actions/test/action.yaml | 11 ++++++++++ scripts/read-coverage.sh | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100755 scripts/read-coverage.sh diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index 5519570f13..dc073559a2 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -19,16 +19,27 @@ runs: echo "::group::run-tests" npm run test:coverage echo "::endgroup::" + - name: ci/download-current-coverage uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4 with: + name: test-coverage-result path: current-coverage/coverage-summary.json + - name: ci/read-coverage + shell: bash + run: | + echo "::group::read-coverage" + ./scripts/read-coverage.sh ./current-coverage/coverage-summary.json + echo "::endgroup::" + - name: ci/upload-coverage uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 with: name: test-coverage-result path: coverage/coverage-summary.json + overwrite: true + - name: ci/check-i18n shell: bash run: | diff --git a/scripts/read-coverage.sh b/scripts/read-coverage.sh new file mode 100755 index 0000000000..8758797609 --- /dev/null +++ b/scripts/read-coverage.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +set -e # Exit on any error + +# Check if an argument is provided +if [ -z "$1" ]; then + echo "❌ Error: No coverage file provided." + echo "Usage: $0 " + exit 1 +fi + +COVERAGE_FILE="$1" + +# Check if the coverage file exists +if [ ! -f "$COVERAGE_FILE" ]; then + echo "❌ Error: Coverage summary file not found: $COVERAGE_FILE" + exit 1 +fi + +# Extract coverage values from JSON +BRANCHES=$(jq '.total.branches.pct' $COVERAGE_FILE) +FUNCTIONS=$(jq '.total.functions.pct' $COVERAGE_FILE) +LINES=$(jq '.total.lines.pct' $COVERAGE_FILE) +STATEMENTS=$(jq '.total.statements.pct' $COVERAGE_FILE) + +# Print extracted values +echo "📊 Extracted Coverage Values:" +echo " - Branches: $BRANCHES%" +echo " - Functions: $FUNCTIONS%" +echo " - Lines: $LINES%" +echo " - Statements: $STATEMENTS%" + +# Export values for GitHub Actions (if needed) +echo "BRANCHES=$BRANCHES" >> $GITHUB_ENV +echo "FUNCTIONS=$FUNCTIONS" >> $GITHUB_ENV +echo "LINES=$LINES" >> $GITHUB_ENV +echo "STATEMENTS=$STATEMENTS" >> $GITHUB_ENV From 137bee6e0fa20686b0cd9713b74fd2b898093bbd Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Fri, 28 Feb 2025 15:18:32 -0700 Subject: [PATCH 04/75] add token --- .github/actions/test/action.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index dc073559a2..3ee9642e9d 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -25,6 +25,7 @@ runs: with: name: test-coverage-result path: current-coverage/coverage-summary.json + token: ${{ secrets.MM_MOBILE_GITHUB_TOKEN }} - name: ci/read-coverage shell: bash From 88fdcc553f381a2e1192625eacdcd026b269a5e8 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Sat, 1 Mar 2025 07:13:03 -0700 Subject: [PATCH 05/75] use github.token instead --- .github/actions/test/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index 3ee9642e9d..e29197f7f3 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -25,7 +25,7 @@ runs: with: name: test-coverage-result path: current-coverage/coverage-summary.json - token: ${{ secrets.MM_MOBILE_GITHUB_TOKEN }} + token: ${{ github.token }} - name: ci/read-coverage shell: bash From 22b2320b8a9c89854a12c5cee467b8ebc1dffdba Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Sat, 1 Mar 2025 07:23:58 -0700 Subject: [PATCH 06/75] passing github token --- .github/actions/test/action.yaml | 7 ++++++- .github/workflows/build-android-release.yml | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index e29197f7f3..5d5ab8c927 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -1,6 +1,11 @@ name: test description: Common tests for mobile repo +inputs: + github_token: + description: The token to use to download the coverage result + required: true + runs: using: composite steps: @@ -25,7 +30,7 @@ runs: with: name: test-coverage-result path: current-coverage/coverage-summary.json - token: ${{ github.token }} + token: ${{ inputs.github_token }} - name: ci/read-coverage shell: bash diff --git a/.github/workflows/build-android-release.yml b/.github/workflows/build-android-release.yml index 2fe85f2bcc..3ea53a53e3 100644 --- a/.github/workflows/build-android-release.yml +++ b/.github/workflows/build-android-release.yml @@ -19,6 +19,8 @@ jobs: uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: ci/test uses: ./.github/actions/test + with: + github_token: ${{ secrets.MM_MOBILE_GITHUB_TOKEN }} build-and-deploy-android-release: runs-on: ubuntu-22.04 From 12013da245e71906796e26dada03f6a165ea8b14 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Sat, 1 Mar 2025 07:25:38 -0700 Subject: [PATCH 07/75] github_token passing from workflow --- .github/workflows/build-android-release.yml | 2 -- .github/workflows/ci.yml | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-android-release.yml b/.github/workflows/build-android-release.yml index 3ea53a53e3..2fe85f2bcc 100644 --- a/.github/workflows/build-android-release.yml +++ b/.github/workflows/build-android-release.yml @@ -19,8 +19,6 @@ jobs: uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: ci/test uses: ./.github/actions/test - with: - github_token: ${{ secrets.MM_MOBILE_GITHUB_TOKEN }} build-and-deploy-android-release: runs-on: ubuntu-22.04 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4a4e84af4f..00a414fa55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,3 +19,5 @@ jobs: uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: ci/test uses: ./.github/actions/test + with: + github_token: ${{ secrets.MM_MOBILE_GITHUB_TOKEN }} From 6f4bc8eecc58008884cc2dc98fb8677dce03a10e Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Sat, 1 Mar 2025 07:36:36 -0700 Subject: [PATCH 08/75] remove download --- .github/actions/test/action.yaml | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index 5d5ab8c927..9f35db9fba 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -18,6 +18,21 @@ runs: echo "::group::check-styles" npm run check echo "::endgroup::" + + # - name: ci/download-current-coverage + # uses: actions/download-artifact@v4 + # with: + # name: test-coverage-result + # path: current-coverage/coverage-summary.json + # token: ${{ inputs.github_token }} + + # - name: ci/read-coverage + # shell: bash + # run: | + # echo "::group::read-coverage" + # ./scripts/read-coverage.sh ./current-coverage/coverage-summary.json + # echo "::endgroup::" + - name: ci/run-tests shell: bash run: | @@ -25,22 +40,8 @@ runs: npm run test:coverage echo "::endgroup::" - - name: ci/download-current-coverage - uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4 - with: - name: test-coverage-result - path: current-coverage/coverage-summary.json - token: ${{ inputs.github_token }} - - - name: ci/read-coverage - shell: bash - run: | - echo "::group::read-coverage" - ./scripts/read-coverage.sh ./current-coverage/coverage-summary.json - echo "::endgroup::" - - name: ci/upload-coverage - uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 + uses: actions/upload-artifact@v4 with: name: test-coverage-result path: coverage/coverage-summary.json From a805c7f82923caaacba69a7d58887f51c7189c45 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Sat, 1 Mar 2025 07:44:31 -0700 Subject: [PATCH 09/75] re-add download --- .github/actions/test/action.yaml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index 9f35db9fba..68178756b9 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -19,19 +19,19 @@ runs: npm run check echo "::endgroup::" - # - name: ci/download-current-coverage - # uses: actions/download-artifact@v4 - # with: - # name: test-coverage-result - # path: current-coverage/coverage-summary.json - # token: ${{ inputs.github_token }} - - # - name: ci/read-coverage - # shell: bash - # run: | - # echo "::group::read-coverage" - # ./scripts/read-coverage.sh ./current-coverage/coverage-summary.json - # echo "::endgroup::" + - name: ci/download-current-coverage + uses: actions/download-artifact@v4 + with: + name: test-coverage-result + path: current-coverage/coverage-summary.json + token: ${{ inputs.github_token }} + + - name: ci/read-coverage + shell: bash + run: | + echo "::group::read-coverage" + ./scripts/read-coverage.sh ./current-coverage/coverage-summary.json + echo "::endgroup::" - name: ci/run-tests shell: bash From 9040a95e1b45a85924e5d62d4360e854e6c2be6c Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Sat, 1 Mar 2025 08:17:47 -0700 Subject: [PATCH 10/75] wrong param --- .github/actions/test/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index 68178756b9..d4e8869720 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -24,7 +24,7 @@ runs: with: name: test-coverage-result path: current-coverage/coverage-summary.json - token: ${{ inputs.github_token }} + github-token: ${{ inputs.github_token }} - name: ci/read-coverage shell: bash From 594bf0d9f6757ea74c16d1d2f2bdbb1fddce133e Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Sat, 1 Mar 2025 08:25:24 -0700 Subject: [PATCH 11/75] try download all artifacts --- .github/actions/test/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index d4e8869720..8e53b7f8af 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -22,7 +22,7 @@ runs: - name: ci/download-current-coverage uses: actions/download-artifact@v4 with: - name: test-coverage-result + # name: test-coverage-result path: current-coverage/coverage-summary.json github-token: ${{ inputs.github_token }} From c67a2b12d28889d363fc7c5600a3c6bfe885eed5 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 07:09:16 -0600 Subject: [PATCH 12/75] add run-id so to retrieve with download later --- .github/actions/test/action.yaml | 18 +++++++++++------- .github/workflows/ci.yml | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index 8e53b7f8af..09869472dd 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -5,6 +5,9 @@ inputs: github_token: description: The token to use to download the coverage result required: true + run-id: + description: The run id to use to download the coverage result + required: true runs: using: composite @@ -19,12 +22,13 @@ runs: npm run check echo "::endgroup::" - - name: ci/download-current-coverage - uses: actions/download-artifact@v4 - with: - # name: test-coverage-result - path: current-coverage/coverage-summary.json - github-token: ${{ inputs.github_token }} + # - name: ci/download-current-coverage + # uses: actions/download-artifact@v4 + # with: + # name: test-coverage-result + # path: current-coverage/coverage-summary.json + # github-token: ${{ inputs.github_token }} + # run-id: - name: ci/read-coverage shell: bash @@ -43,7 +47,7 @@ runs: - name: ci/upload-coverage uses: actions/upload-artifact@v4 with: - name: test-coverage-result + name: test-coverage-result-${{ inputs.run-id }} path: coverage/coverage-summary.json overwrite: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 00a414fa55..e161334df4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,3 +21,4 @@ jobs: uses: ./.github/actions/test with: github_token: ${{ secrets.MM_MOBILE_GITHUB_TOKEN }} + run-id: ${{ github.run_id }} From 2a770697a160b89698192cf0022b86efa398e087 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 07:15:35 -0600 Subject: [PATCH 13/75] remove read coverage temp --- .github/actions/test/action.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index 09869472dd..f96ec0e7a2 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -30,12 +30,12 @@ runs: # github-token: ${{ inputs.github_token }} # run-id: - - name: ci/read-coverage - shell: bash - run: | - echo "::group::read-coverage" - ./scripts/read-coverage.sh ./current-coverage/coverage-summary.json - echo "::endgroup::" + # - name: ci/read-coverage + # shell: bash + # run: | + # echo "::group::read-coverage" + # ./scripts/read-coverage.sh ./current-coverage/coverage-summary.json + # echo "::endgroup::" - name: ci/run-tests shell: bash From 0f02944398e919891ded34480d1ffdbf1428b584 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 07:41:56 -0600 Subject: [PATCH 14/75] use run-id to download --- .github/actions/test/action.yaml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index f96ec0e7a2..55bcd967b6 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -22,20 +22,20 @@ runs: npm run check echo "::endgroup::" - # - name: ci/download-current-coverage - # uses: actions/download-artifact@v4 - # with: - # name: test-coverage-result - # path: current-coverage/coverage-summary.json - # github-token: ${{ inputs.github_token }} - # run-id: - - # - name: ci/read-coverage - # shell: bash - # run: | - # echo "::group::read-coverage" - # ./scripts/read-coverage.sh ./current-coverage/coverage-summary.json - # echo "::endgroup::" + - name: ci/download-current-coverage + uses: actions/download-artifact@v4 + with: + name: test-coverage-result-13765601687 + path: current-coverage/coverage-summary.json + github-token: ${{ inputs.github_token }} + run-id: 13765601687 + + - name: ci/read-coverage + shell: bash + run: | + echo "::group::read-coverage" + ./scripts/read-coverage.sh ./current-coverage/coverage-summary.json + echo "::endgroup::" - name: ci/run-tests shell: bash From 74ed15f4d273a4e4bfaa8e58692f6df2a9b01ab1 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 07:47:57 -0600 Subject: [PATCH 15/75] put files into current-coverage --- .github/actions/test/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index 55bcd967b6..d5114c6012 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -26,7 +26,7 @@ runs: uses: actions/download-artifact@v4 with: name: test-coverage-result-13765601687 - path: current-coverage/coverage-summary.json + path: current-coverage/ github-token: ${{ inputs.github_token }} run-id: 13765601687 From 0a2e7f4677e05c71635a26742ebf6cb4bff3fc8e Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 09:45:04 -0600 Subject: [PATCH 16/75] using last run id --- .github/actions/test/action.yaml | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index d5114c6012..1d9ebd0066 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -22,13 +22,27 @@ runs: npm run check echo "::endgroup::" + - name: ci/get-last-run-id + uses: actions/cache/restore@0c907a75c2c80ebcb7f088228285e798b750cf8f + continue-on-error: true + with: + path: run-id.txt + key: last-run-id + + - name: ci/put-last-run-id-into-env + shell: bash + run: | + echo "::group::put-last-run-id-into-env" + export LAST_RUN_ID=$(cat run-id.txt) + echo "::endgroup::" + - name: ci/download-current-coverage uses: actions/download-artifact@v4 with: name: test-coverage-result-13765601687 path: current-coverage/ github-token: ${{ inputs.github_token }} - run-id: 13765601687 + run-id: ${{ env.LAST_RUN_ID }} - name: ci/read-coverage shell: bash @@ -51,6 +65,19 @@ runs: path: coverage/coverage-summary.json overwrite: true + - name: ci/generate-run-id-file + shell: bash + run: | + echo "::group::generate-last-run-id" + echo "${{ inputs.run-id }}" > run-id.txt + echo "::endgroup::" + + - name: ci/cache-run-id-file + uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f + with: + path: run-id.txt + key: last-run-id + - name: ci/check-i18n shell: bash run: | From 362b3e0060c1427dd9182a2b6874b4f5b8fb2e13 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 09:45:38 -0600 Subject: [PATCH 17/75] temporary comment --- .github/actions/test/action.yaml | 38 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index 1d9ebd0066..bb7d9b5a60 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -29,27 +29,27 @@ runs: path: run-id.txt key: last-run-id - - name: ci/put-last-run-id-into-env - shell: bash - run: | - echo "::group::put-last-run-id-into-env" - export LAST_RUN_ID=$(cat run-id.txt) - echo "::endgroup::" + # - name: ci/put-last-run-id-into-env + # shell: bash + # run: | + # echo "::group::put-last-run-id-into-env" + # export LAST_RUN_ID=$(cat run-id.txt) + # echo "::endgroup::" - - name: ci/download-current-coverage - uses: actions/download-artifact@v4 - with: - name: test-coverage-result-13765601687 - path: current-coverage/ - github-token: ${{ inputs.github_token }} - run-id: ${{ env.LAST_RUN_ID }} + # - name: ci/download-current-coverage + # uses: actions/download-artifact@v4 + # with: + # name: test-coverage-result-13765601687 + # path: current-coverage/ + # github-token: ${{ inputs.github_token }} + # run-id: ${{ env.LAST_RUN_ID }} - - name: ci/read-coverage - shell: bash - run: | - echo "::group::read-coverage" - ./scripts/read-coverage.sh ./current-coverage/coverage-summary.json - echo "::endgroup::" + # - name: ci/read-coverage + # shell: bash + # run: | + # echo "::group::read-coverage" + # ./scripts/read-coverage.sh ./current-coverage/coverage-summary.json + # echo "::endgroup::" - name: ci/run-tests shell: bash From 439280364cece6379b4102829de5ce4201d78fd0 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 10:44:22 -0600 Subject: [PATCH 18/75] can retrieve last run id? --- .github/actions/test/action.yaml | 38 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index bb7d9b5a60..1d9ebd0066 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -29,27 +29,27 @@ runs: path: run-id.txt key: last-run-id - # - name: ci/put-last-run-id-into-env - # shell: bash - # run: | - # echo "::group::put-last-run-id-into-env" - # export LAST_RUN_ID=$(cat run-id.txt) - # echo "::endgroup::" + - name: ci/put-last-run-id-into-env + shell: bash + run: | + echo "::group::put-last-run-id-into-env" + export LAST_RUN_ID=$(cat run-id.txt) + echo "::endgroup::" - # - name: ci/download-current-coverage - # uses: actions/download-artifact@v4 - # with: - # name: test-coverage-result-13765601687 - # path: current-coverage/ - # github-token: ${{ inputs.github_token }} - # run-id: ${{ env.LAST_RUN_ID }} + - name: ci/download-current-coverage + uses: actions/download-artifact@v4 + with: + name: test-coverage-result-13765601687 + path: current-coverage/ + github-token: ${{ inputs.github_token }} + run-id: ${{ env.LAST_RUN_ID }} - # - name: ci/read-coverage - # shell: bash - # run: | - # echo "::group::read-coverage" - # ./scripts/read-coverage.sh ./current-coverage/coverage-summary.json - # echo "::endgroup::" + - name: ci/read-coverage + shell: bash + run: | + echo "::group::read-coverage" + ./scripts/read-coverage.sh ./current-coverage/coverage-summary.json + echo "::endgroup::" - name: ci/run-tests shell: bash From 680cf035318e4ec3bf152491c27c556bbd6d89c9 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 10:50:23 -0600 Subject: [PATCH 19/75] remove hard-coding --- .github/actions/test/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index 1d9ebd0066..f3032ab87b 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -39,7 +39,7 @@ runs: - name: ci/download-current-coverage uses: actions/download-artifact@v4 with: - name: test-coverage-result-13765601687 + name: test-coverage-result-${{ env.LAST_RUN_ID }} path: current-coverage/ github-token: ${{ inputs.github_token }} run-id: ${{ env.LAST_RUN_ID }} From 1f7237c8229d77d1e27e298408d10c6fc0f868fb Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 10:55:08 -0600 Subject: [PATCH 20/75] echo into github_env vs export --- .github/actions/test/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index f3032ab87b..6279f371a4 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -33,7 +33,7 @@ runs: shell: bash run: | echo "::group::put-last-run-id-into-env" - export LAST_RUN_ID=$(cat run-id.txt) + echo "LAST_RUN_ID=$(cat run-id.txt)" >> $GITHUB_ENV echo "::endgroup::" - name: ci/download-current-coverage From bda32c8b2d04ec8e97323d390b0cff532b7f1f4b Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 12:55:22 -0600 Subject: [PATCH 21/75] comparing new and old --- .github/actions/test/action.yaml | 8 ++++++++ scripts/compare-coverage.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100755 scripts/compare-coverage.sh diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index 6279f371a4..de2e72ad90 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -58,6 +58,14 @@ runs: npm run test:coverage echo "::endgroup::" + # compare coverage between current-coverage and recent coverage + - name: ci/compare-coverage + shell: bash + run: | + echo "::group::compare-coverage" + ./scripts/compare-coverage.sh ./current-coverage ./coverage + echo "::endgroup::" + - name: ci/upload-coverage uses: actions/upload-artifact@v4 with: diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh new file mode 100755 index 0000000000..9194a1bbe8 --- /dev/null +++ b/scripts/compare-coverage.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +CURRENT_COVERAGE_FILE="$1/coverage-summary.json" +RECENT_COVERAGE_FILE="$2/coverage-summary.json" + +if [ ! -f "$CURRENT_COVERAGE_FILE" ] || [ ! -f "$RECENT_COVERAGE_FILE" ]; then + echo "One or both coverage files not found" + exit 0 +fi + +# Extract total coverage percentages +CURRENT_COVERAGE=$(jq '.total.lines.pct' "$CURRENT_COVERAGE_FILE") +RECENT_COVERAGE=$(jq '.total.lines.pct' "$RECENT_COVERAGE_FILE") + +# Calculate difference +DIFFERENCE=$(echo "$CURRENT_COVERAGE - $RECENT_COVERAGE" | bc) + +echo "Current coverage: $CURRENT_COVERAGE%" +echo "Previous coverage: $RECENT_COVERAGE%" +echo "Difference: $DIFFERENCE%" + +# Check if coverage decreased by more than 1% +if (( $(echo "$DIFFERENCE < -1" | bc -l) )); then + echo "::error::Test coverage has decreased by more than 1% (${DIFFERENCE}%)" + exit 1 +fi From deeb5a3980f26944b65da56df41e78011027a457 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 13:07:31 -0600 Subject: [PATCH 22/75] comparison improvement --- scripts/compare-coverage.sh | 53 ++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index 9194a1bbe8..c3e6a17edc 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -8,19 +8,40 @@ if [ ! -f "$CURRENT_COVERAGE_FILE" ] || [ ! -f "$RECENT_COVERAGE_FILE" ]; then exit 0 fi -# Extract total coverage percentages -CURRENT_COVERAGE=$(jq '.total.lines.pct' "$CURRENT_COVERAGE_FILE") -RECENT_COVERAGE=$(jq '.total.lines.pct' "$RECENT_COVERAGE_FILE") - -# Calculate difference -DIFFERENCE=$(echo "$CURRENT_COVERAGE - $RECENT_COVERAGE" | bc) - -echo "Current coverage: $CURRENT_COVERAGE%" -echo "Previous coverage: $RECENT_COVERAGE%" -echo "Difference: $DIFFERENCE%" - -# Check if coverage decreased by more than 1% -if (( $(echo "$DIFFERENCE < -1" | bc -l) )); then - echo "::error::Test coverage has decreased by more than 1% (${DIFFERENCE}%)" - exit 1 -fi +# Function to print a horizontal line +print_line() { + printf "+-----------------+------------+------------+-----------+\n" +} + +# Function to print table row +print_row() { + printf "| %-15s | %10.2f%% | %10.2f%% | %9.2f%% |\n" "$1" "$2" "$3" "$4" +} + +# Track if any metric has decreased +HAS_DECREASE=0 + +echo "Coverage Comparison Report" +echo "=========================" +print_line +printf "| %-15s | %-10s | %-10s | %-9s |\n" "Metric" "Current" "Previous" "Diff" +print_line + +# Compare each metric +for metric in lines statements branches functions; do + current=$(jq ".total.${metric}.pct" "$CURRENT_COVERAGE_FILE") + recent=$(jq ".total.${metric}.pct" "$RECENT_COVERAGE_FILE") + diff=$(echo "$current - $recent" | bc) + + print_row "${metric^}" "$current" "$recent" "$diff" + + # Check if coverage decreased by more than 1% + if (( $(echo "$diff < -1" | bc -l) )); then + echo "::error::${metric^} coverage has decreased by more than 1% ($diff%)" + HAS_DECREASE=1 + fi +done + +print_line + +exit $HAS_DECREASE From 81d33964deeafe8adfb1363d58772aad449d45ba Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 14:07:50 -0600 Subject: [PATCH 23/75] post to github --- .github/actions/test/action.yaml | 6 ++++- scripts/compare-coverage.sh | 42 ++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index de2e72ad90..ffbaad7679 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -63,7 +63,11 @@ runs: shell: bash run: | echo "::group::compare-coverage" - ./scripts/compare-coverage.sh ./current-coverage ./coverage + ./scripts/compare-coverage.sh \ + ./current-coverage \ + ./coverage \ + ${{ github.event.pull_request.number }} \ + ${{ inputs.github_token }} echo "::endgroup::" - name: ci/upload-coverage diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index c3e6a17edc..36c47e2d26 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -2,6 +2,8 @@ CURRENT_COVERAGE_FILE="$1/coverage-summary.json" RECENT_COVERAGE_FILE="$2/coverage-summary.json" +PR_NUMBER="$3" +GITHUB_TOKEN="$4" if [ ! -f "$CURRENT_COVERAGE_FILE" ] || [ ! -f "$RECENT_COVERAGE_FILE" ]; then echo "One or both coverage files not found" @@ -18,22 +20,28 @@ print_row() { printf "| %-15s | %10.2f%% | %10.2f%% | %9.2f%% |\n" "$1" "$2" "$3" "$4" } +# Capture the output in a variable using a heredoc +COMMENT_BODY=$(cat << 'EOF' +### Coverage Comparison Report +\`\`\` +EOF +) + +# Add the table header +COMMENT_BODY+=$(print_line) +COMMENT_BODY+=$(printf "| %-15s | %-10s | %-10s | %-9s |\n" "Metric" "Current" "Previous" "Diff") +COMMENT_BODY+=$(print_line) + # Track if any metric has decreased HAS_DECREASE=0 -echo "Coverage Comparison Report" -echo "=========================" -print_line -printf "| %-15s | %-10s | %-10s | %-9s |\n" "Metric" "Current" "Previous" "Diff" -print_line - # Compare each metric for metric in lines statements branches functions; do current=$(jq ".total.${metric}.pct" "$CURRENT_COVERAGE_FILE") recent=$(jq ".total.${metric}.pct" "$RECENT_COVERAGE_FILE") diff=$(echo "$current - $recent" | bc) - print_row "${metric^}" "$current" "$recent" "$diff" + COMMENT_BODY+=$(print_row "${metric^}" "$current" "$recent" "$diff") # Check if coverage decreased by more than 1% if (( $(echo "$diff < -1" | bc -l) )); then @@ -42,6 +50,24 @@ for metric in lines statements branches functions; do fi done -print_line +COMMENT_BODY+=$(print_line) +COMMENT_BODY+="\n\`\`\`" + +# Add warning message if coverage decreased +if [ "$HAS_DECREASE" -eq 1 ]; then + COMMENT_BODY+="\n\n⚠️ **Warning:** One or more coverage metrics have decreased by more than 1%" +fi + +# Post comment to GitHub PR +if [ -n "$PR_NUMBER" ] && [ -n "$GITHUB_TOKEN" ]; then + curl -X POST \ + -H "Authorization: token $GITHUB_TOKEN" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" \ + -d "{\"body\":$(echo "$COMMENT_BODY" | jq -R -s .)}" +fi + +# Also print to console +echo "$COMMENT_BODY" exit $HAS_DECREASE From efa86a6ea9fae5f2c116e1968f3265b2ed59298e Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 14:16:06 -0600 Subject: [PATCH 24/75] fix coverage text --- scripts/compare-coverage.sh | 39 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index 36c47e2d26..dfd8df8142 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -10,50 +10,35 @@ if [ ! -f "$CURRENT_COVERAGE_FILE" ] || [ ! -f "$RECENT_COVERAGE_FILE" ]; then exit 0 fi -# Function to print a horizontal line -print_line() { - printf "+-----------------+------------+------------+-----------+\n" -} +# Create the comment body with proper newlines +COMMENT_BODY="### Coverage Comparison Report -# Function to print table row -print_row() { - printf "| %-15s | %10.2f%% | %10.2f%% | %9.2f%% |\n" "$1" "$2" "$3" "$4" -} - -# Capture the output in a variable using a heredoc -COMMENT_BODY=$(cat << 'EOF' -### Coverage Comparison Report \`\`\` -EOF -) - -# Add the table header -COMMENT_BODY+=$(print_line) -COMMENT_BODY+=$(printf "| %-15s | %-10s | %-10s | %-9s |\n" "Metric" "Current" "Previous" "Diff") -COMMENT_BODY+=$(print_line) - -# Track if any metric has decreased -HAS_DECREASE=0 ++-----------------+------------+------------+-----------+ +| Metric | Current | Previous | Diff | ++-----------------+------------+------------+-----------+ +" # Compare each metric +HAS_DECREASE=0 for metric in lines statements branches functions; do current=$(jq ".total.${metric}.pct" "$CURRENT_COVERAGE_FILE") recent=$(jq ".total.${metric}.pct" "$RECENT_COVERAGE_FILE") diff=$(echo "$current - $recent" | bc) - COMMENT_BODY+=$(print_row "${metric^}" "$current" "$recent" "$diff") + # Add row to table with proper formatting + printf -v row "| %-15s | %10.2f%% | %10.2f%% | %9.2f%% |\n" "${metric^}" "$current" "$recent" "$diff" + COMMENT_BODY+="$row" - # Check if coverage decreased by more than 1% if (( $(echo "$diff < -1" | bc -l) )); then echo "::error::${metric^} coverage has decreased by more than 1% ($diff%)" HAS_DECREASE=1 fi done -COMMENT_BODY+=$(print_line) -COMMENT_BODY+="\n\`\`\`" +COMMENT_BODY+="+-----------------+------------+------------+-----------+ +\`\`\`" -# Add warning message if coverage decreased if [ "$HAS_DECREASE" -eq 1 ]; then COMMENT_BODY+="\n\n⚠️ **Warning:** One or more coverage metrics have decreased by more than 1%" fi From a211c78d240627da7b993114be953aed456f1f0e Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 14:36:26 -0600 Subject: [PATCH 25/75] refactor to main from current-coverage --- .github/actions/test/action.yaml | 9 ++++----- scripts/compare-coverage.sh | 14 +++++++------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index ffbaad7679..e581e5ca88 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -36,11 +36,11 @@ runs: echo "LAST_RUN_ID=$(cat run-id.txt)" >> $GITHUB_ENV echo "::endgroup::" - - name: ci/download-current-coverage + - name: ci/download-main-coverage uses: actions/download-artifact@v4 with: name: test-coverage-result-${{ env.LAST_RUN_ID }} - path: current-coverage/ + path: main-coverage/ github-token: ${{ inputs.github_token }} run-id: ${{ env.LAST_RUN_ID }} @@ -48,7 +48,7 @@ runs: shell: bash run: | echo "::group::read-coverage" - ./scripts/read-coverage.sh ./current-coverage/coverage-summary.json + ./scripts/read-coverage.sh ./main-coverage/coverage-summary.json echo "::endgroup::" - name: ci/run-tests @@ -58,13 +58,12 @@ runs: npm run test:coverage echo "::endgroup::" - # compare coverage between current-coverage and recent coverage - name: ci/compare-coverage shell: bash run: | echo "::group::compare-coverage" ./scripts/compare-coverage.sh \ - ./current-coverage \ + ./main-coverage \ ./coverage \ ${{ github.event.pull_request.number }} \ ${{ inputs.github_token }} diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index dfd8df8142..a5d6e0ffc4 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -1,11 +1,11 @@ #!/bin/bash -CURRENT_COVERAGE_FILE="$1/coverage-summary.json" +MAIN_COVERAGE_FILE="$1/coverage-summary.json" RECENT_COVERAGE_FILE="$2/coverage-summary.json" PR_NUMBER="$3" GITHUB_TOKEN="$4" -if [ ! -f "$CURRENT_COVERAGE_FILE" ] || [ ! -f "$RECENT_COVERAGE_FILE" ]; then +if [ ! -f "$MAIN_COVERAGE_FILE" ] || [ ! -f "$RECENT_COVERAGE_FILE" ]; then echo "One or both coverage files not found" exit 0 fi @@ -15,19 +15,19 @@ COMMENT_BODY="### Coverage Comparison Report \`\`\` +-----------------+------------+------------+-----------+ -| Metric | Current | Previous | Diff | +| Metric | Main | This PR | Diff | +-----------------+------------+------------+-----------+ " # Compare each metric HAS_DECREASE=0 for metric in lines statements branches functions; do - current=$(jq ".total.${metric}.pct" "$CURRENT_COVERAGE_FILE") - recent=$(jq ".total.${metric}.pct" "$RECENT_COVERAGE_FILE") - diff=$(echo "$current - $recent" | bc) + main=$(jq ".total.${metric}.pct" "$MAIN_COVERAGE_FILE") + pr=$(jq ".total.${metric}.pct" "$RECENT_COVERAGE_FILE") + diff=$(echo "$pr - $main" | bc) # Add row to table with proper formatting - printf -v row "| %-15s | %10.2f%% | %10.2f%% | %9.2f%% |\n" "${metric^}" "$current" "$recent" "$diff" + printf -v row "| %-15s | %10.2f%% | %10.2f%% | %9.2f%% |\n" "${metric^}" "$main" "$pr" "$diff" COMMENT_BODY+="$row" if (( $(echo "$diff < -1" | bc -l) )); then From 80c5ef04aec075afe219c2d0f88ebf0dbea90715 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 14:51:20 -0600 Subject: [PATCH 26/75] formatting changes --- scripts/compare-coverage.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index a5d6e0ffc4..43679c94ce 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -10,14 +10,13 @@ if [ ! -f "$MAIN_COVERAGE_FILE" ] || [ ! -f "$RECENT_COVERAGE_FILE" ]; then exit 0 fi -# Create the comment body with proper newlines +# Create the comment body with proper newlines and no extra spaces COMMENT_BODY="### Coverage Comparison Report \`\`\` +-----------------+------------+------------+-----------+ | Metric | Main | This PR | Diff | -+-----------------+------------+------------+-----------+ -" ++-----------------+------------+------------+-----------+" # Compare each metric HAS_DECREASE=0 @@ -26,9 +25,8 @@ for metric in lines statements branches functions; do pr=$(jq ".total.${metric}.pct" "$RECENT_COVERAGE_FILE") diff=$(echo "$pr - $main" | bc) - # Add row to table with proper formatting - printf -v row "| %-15s | %10.2f%% | %10.2f%% | %9.2f%% |\n" "${metric^}" "$main" "$pr" "$diff" - COMMENT_BODY+="$row" + # Add row to table with exact spacing + COMMENT_BODY+=$'\n'"| %-15s | %10.2f%% | %10.2f%% | %9.2f%% |" "${metric^}" "$main" "$pr" "$diff" if (( $(echo "$diff < -1" | bc -l) )); then echo "::error::${metric^} coverage has decreased by more than 1% ($diff%)" @@ -36,7 +34,7 @@ for metric in lines statements branches functions; do fi done -COMMENT_BODY+="+-----------------+------------+------------+-----------+ +COMMENT_BODY+=$'\n'+"+-----------------+------------+------------+-----------+ \`\`\`" if [ "$HAS_DECREASE" -eq 1 ]; then From e100fe0d8541788f454fb90e769d967130e394a9 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 16:31:30 -0600 Subject: [PATCH 27/75] fix missing content --- scripts/compare-coverage.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index 43679c94ce..e9260a15b8 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -26,7 +26,8 @@ for metric in lines statements branches functions; do diff=$(echo "$pr - $main" | bc) # Add row to table with exact spacing - COMMENT_BODY+=$'\n'"| %-15s | %10.2f%% | %10.2f%% | %9.2f%% |" "${metric^}" "$main" "$pr" "$diff" + row=$(printf "| %-15s | %10.2f%% | %10.2f%% | %9.2f%% |" "${metric^}" "$main" "$pr" "$diff") + COMMENT_BODY+=$'\n'"$row" if (( $(echo "$diff < -1" | bc -l) )); then echo "::error::${metric^} coverage has decreased by more than 1% ($diff%)" @@ -34,7 +35,7 @@ for metric in lines statements branches functions; do fi done -COMMENT_BODY+=$'\n'+"+-----------------+------------+------------+-----------+ +COMMENT_BODY+=$'\n'"+-----------------+------------+------------+-----------+ \`\`\`" if [ "$HAS_DECREASE" -eq 1 ]; then From f8ee286e8ddd448447b1596ed27d65d9be2dd141 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 16:41:18 -0600 Subject: [PATCH 28/75] small tweaking --- scripts/compare-coverage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index e9260a15b8..79501ead96 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -15,7 +15,7 @@ COMMENT_BODY="### Coverage Comparison Report \`\`\` +-----------------+------------+------------+-----------+ -| Metric | Main | This PR | Diff | +| Metric | Main | This PR | Diff | +-----------------+------------+------------+-----------+" # Compare each metric @@ -26,7 +26,7 @@ for metric in lines statements branches functions; do diff=$(echo "$pr - $main" | bc) # Add row to table with exact spacing - row=$(printf "| %-15s | %10.2f%% | %10.2f%% | %9.2f%% |" "${metric^}" "$main" "$pr" "$diff") + row=$(printf "| %-15s | %9.2f%% | %9.2f%% | %9.2f%% |" "${metric^}" "$main" "$pr" "$diff") COMMENT_BODY+=$'\n'"$row" if (( $(echo "$diff < -1" | bc -l) )); then From 68203a86140abcf6aad3a629b71e70b41caae880 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 17:25:49 -0600 Subject: [PATCH 29/75] showing the Warning to make sure --- scripts/compare-coverage.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index 79501ead96..874bcb2583 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -26,7 +26,7 @@ for metric in lines statements branches functions; do diff=$(echo "$pr - $main" | bc) # Add row to table with exact spacing - row=$(printf "| %-15s | %9.2f%% | %9.2f%% | %9.2f%% |" "${metric^}" "$main" "$pr" "$diff") + row=$(printf "| %-15s | %9.2f%% | %9.2f%% | %8.2f%% |" "${metric^}" "$main" "$pr" "$diff") COMMENT_BODY+=$'\n'"$row" if (( $(echo "$diff < -1" | bc -l) )); then @@ -38,7 +38,7 @@ done COMMENT_BODY+=$'\n'"+-----------------+------------+------------+-----------+ \`\`\`" -if [ "$HAS_DECREASE" -eq 1 ]; then +if [ "$HAS_DECREASE" -eq 0 ]; then COMMENT_BODY+="\n\n⚠️ **Warning:** One or more coverage metrics have decreased by more than 1%" fi @@ -54,4 +54,5 @@ fi # Also print to console echo "$COMMENT_BODY" -exit $HAS_DECREASE +# Not failing the build for now +# exit $HAS_DECREASE From f6a76789f9313f364f2756880958f74d8d7417fa Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 17:37:46 -0600 Subject: [PATCH 30/75] formatting --- scripts/compare-coverage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index 874bcb2583..a8c21ddfb0 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -39,7 +39,7 @@ COMMENT_BODY+=$'\n'"+-----------------+------------+------------+-----------+ \`\`\`" if [ "$HAS_DECREASE" -eq 0 ]; then - COMMENT_BODY+="\n\n⚠️ **Warning:** One or more coverage metrics have decreased by more than 1%" + COMMENT_BODY+=$'\n\n' + "⚠️ **Warning:** One or more coverage metrics have decreased by more than 1%" fi # Post comment to GitHub PR From 12166207b63821cddeeeac448ae9fc6556d813e3 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 17:38:17 -0600 Subject: [PATCH 31/75] remove + --- scripts/compare-coverage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index a8c21ddfb0..5a305afe78 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -39,7 +39,7 @@ COMMENT_BODY+=$'\n'"+-----------------+------------+------------+-----------+ \`\`\`" if [ "$HAS_DECREASE" -eq 0 ]; then - COMMENT_BODY+=$'\n\n' + "⚠️ **Warning:** One or more coverage metrics have decreased by more than 1%" + COMMENT_BODY+=$'\n\n'"⚠️ **Warning:** One or more coverage metrics have decreased by more than 1%" fi # Post comment to GitHub PR From 3875f7508a017dfab0e2c27d11bb5c2ac5243db4 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 17:45:48 -0600 Subject: [PATCH 32/75] checking to see if the error shows via echo --- scripts/compare-coverage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index 5a305afe78..20111d4844 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -29,7 +29,7 @@ for metric in lines statements branches functions; do row=$(printf "| %-15s | %9.2f%% | %9.2f%% | %8.2f%% |" "${metric^}" "$main" "$pr" "$diff") COMMENT_BODY+=$'\n'"$row" - if (( $(echo "$diff < -1" | bc -l) )); then + if (( $(echo "$diff > -1" | bc -l) )); then echo "::error::${metric^} coverage has decreased by more than 1% ($diff%)" HAS_DECREASE=1 fi @@ -38,7 +38,7 @@ done COMMENT_BODY+=$'\n'"+-----------------+------------+------------+-----------+ \`\`\`" -if [ "$HAS_DECREASE" -eq 0 ]; then +if [ "$HAS_DECREASE" -eq 1 ]; then COMMENT_BODY+=$'\n\n'"⚠️ **Warning:** One or more coverage metrics have decreased by more than 1%" fi From 45de65301d3c705ea025b8a79dc7ef85ba245557 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 19:54:18 -0600 Subject: [PATCH 33/75] revert the change to error --- scripts/compare-coverage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index 20111d4844..c985e2124b 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -29,7 +29,7 @@ for metric in lines statements branches functions; do row=$(printf "| %-15s | %9.2f%% | %9.2f%% | %8.2f%% |" "${metric^}" "$main" "$pr" "$diff") COMMENT_BODY+=$'\n'"$row" - if (( $(echo "$diff > -1" | bc -l) )); then + if (( $(echo "$diff < -1" | bc -l) )); then echo "::error::${metric^} coverage has decreased by more than 1% ($diff%)" HAS_DECREASE=1 fi From eef25930682a8144cc534b0fac70abe48dc23a8e Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 20:08:41 -0600 Subject: [PATCH 34/75] separate to a new file --- .github/actions/test-coverage/action.yml | 80 ++++++++++++++++++++++++ .github/actions/test/action.yaml | 70 +-------------------- .github/workflows/ci.yml | 4 +- 3 files changed, 84 insertions(+), 70 deletions(-) create mode 100644 .github/actions/test-coverage/action.yml diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml new file mode 100644 index 0000000000..03b73aea2c --- /dev/null +++ b/.github/actions/test-coverage/action.yml @@ -0,0 +1,80 @@ +name: test-coverage +description: Test coverage tracking for mobile repo + +inputs: + github_token: + description: The token to use to download the coverage result + required: true + run_id: + description: The run id to use to download the coverage result + required: true + +runs: + using: composite + steps: + - name: ci/get-last-run-id + uses: actions/cache/restore@0c907a75c2c80ebcb7f088228285e798b750cf8f + continue-on-error: true + with: + path: run-id.txt + key: last-run-id + + - name: ci/put-last-run-id-into-env + shell: bash + run: | + echo "::group::put-last-run-id-into-env" + echo "LAST_RUN_ID=$(cat run-id.txt)" >> $GITHUB_ENV + echo "::endgroup::" + + - name: ci/download-main-coverage + uses: actions/download-artifact@v4 + with: + name: test-coverage-result-${{ env.LAST_RUN_ID }} + path: main-coverage/ + github-token: ${{ inputs.github_token }} + run-id: ${{ env.LAST_RUN_ID }} + + - name: ci/read-coverage + shell: bash + run: | + echo "::group::read-coverage" + ./scripts/read-coverage.sh ./main-coverage/coverage-summary.json + echo "::endgroup::" + + - name: ci/run-tests + shell: bash + run: | + echo "::group::run-tests" + npm run test:coverage + echo "::endgroup::" + + - name: ci/compare-coverage + shell: bash + run: | + echo "::group::compare-coverage" + ./scripts/compare-coverage.sh \ + ./main-coverage \ + ./coverage \ + ${{ github.event.pull_request.number }} \ + ${{ inputs.github_token }} + echo "::endgroup::" + + - name: ci/upload-coverage + uses: actions/upload-artifact@v4 + with: + name: test-coverage-result-${{ inputs.run_id }} + path: coverage/coverage-summary.json + overwrite: true + + - name: ci/generate-run-id-file + shell: bash + run: | + echo "::group::generate-last-run-id" + echo "${{ inputs.run_id }}" > run-id.txt + echo "::endgroup::" + + - name: ci/cache-run-id-file + uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f + with: + path: run-id.txt + key: last-run-id diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index e581e5ca88..370c25c37d 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -1,14 +1,6 @@ name: test description: Common tests for mobile repo -inputs: - github_token: - description: The token to use to download the coverage result - required: true - run-id: - description: The run id to use to download the coverage result - required: true - runs: using: composite steps: @@ -22,73 +14,13 @@ runs: npm run check echo "::endgroup::" - - name: ci/get-last-run-id - uses: actions/cache/restore@0c907a75c2c80ebcb7f088228285e798b750cf8f - continue-on-error: true - with: - path: run-id.txt - key: last-run-id - - - name: ci/put-last-run-id-into-env - shell: bash - run: | - echo "::group::put-last-run-id-into-env" - echo "LAST_RUN_ID=$(cat run-id.txt)" >> $GITHUB_ENV - echo "::endgroup::" - - - name: ci/download-main-coverage - uses: actions/download-artifact@v4 - with: - name: test-coverage-result-${{ env.LAST_RUN_ID }} - path: main-coverage/ - github-token: ${{ inputs.github_token }} - run-id: ${{ env.LAST_RUN_ID }} - - - name: ci/read-coverage - shell: bash - run: | - echo "::group::read-coverage" - ./scripts/read-coverage.sh ./main-coverage/coverage-summary.json - echo "::endgroup::" - - name: ci/run-tests shell: bash run: | echo "::group::run-tests" - npm run test:coverage + npm test echo "::endgroup::" - - name: ci/compare-coverage - shell: bash - run: | - echo "::group::compare-coverage" - ./scripts/compare-coverage.sh \ - ./main-coverage \ - ./coverage \ - ${{ github.event.pull_request.number }} \ - ${{ inputs.github_token }} - echo "::endgroup::" - - - name: ci/upload-coverage - uses: actions/upload-artifact@v4 - with: - name: test-coverage-result-${{ inputs.run-id }} - path: coverage/coverage-summary.json - overwrite: true - - - name: ci/generate-run-id-file - shell: bash - run: | - echo "::group::generate-last-run-id" - echo "${{ inputs.run-id }}" > run-id.txt - echo "::endgroup::" - - - name: ci/cache-run-id-file - uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f - with: - path: run-id.txt - key: last-run-id - - name: ci/check-i18n shell: bash run: | diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e161334df4..2abcd09d51 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,8 @@ jobs: uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: ci/test uses: ./.github/actions/test + - name: ci/test-coverage + uses: ./.github/actions/test-coverage with: github_token: ${{ secrets.MM_MOBILE_GITHUB_TOKEN }} - run-id: ${{ github.run_id }} + run_id: ${{ github.run_id }} From 69c394d9752a44bc892c7aeb44db91da1eab3520 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 20:11:44 -0600 Subject: [PATCH 35/75] comment the actual test for now --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2abcd09d51..8932cb3066 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,8 +17,8 @@ jobs: steps: - name: ci/checkout-repo uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: ci/test - uses: ./.github/actions/test + # - name: ci/test + # uses: ./.github/actions/test - name: ci/test-coverage uses: ./.github/actions/test-coverage with: From 7da6cc77dccc3a7385540de8e6ea039329806e2d Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Mon, 10 Mar 2025 20:19:26 -0600 Subject: [PATCH 36/75] prep node deps --- .github/actions/test-coverage/action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index 03b73aea2c..609ec3ff86 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -12,6 +12,9 @@ inputs: runs: using: composite steps: + - name: ci/prepare-node-deps + uses: ./.github/actions/prepare-node-deps + - name: ci/get-last-run-id uses: actions/cache/restore@0c907a75c2c80ebcb7f088228285e798b750cf8f continue-on-error: true From 2319e3c6d75ee6efd2e3df2502c775b575954ef5 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Tue, 11 Mar 2025 07:13:15 -0600 Subject: [PATCH 37/75] only run certain things on main --- .github/actions/test-coverage/action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index 609ec3ff86..16787c28d2 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -63,6 +63,7 @@ runs: echo "::endgroup::" - name: ci/upload-coverage + if: github.ref_name == 'main' uses: actions/upload-artifact@v4 with: name: test-coverage-result-${{ inputs.run_id }} @@ -70,6 +71,7 @@ runs: overwrite: true - name: ci/generate-run-id-file + if: github.ref_name == 'main' shell: bash run: | echo "::group::generate-last-run-id" @@ -77,6 +79,7 @@ runs: echo "::endgroup::" - name: ci/cache-run-id-file + if: github.ref_name == 'main' uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f with: path: run-id.txt From 86e573cde6266e9ac6e3ba50d4e1700d82e2a2b2 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Tue, 11 Mar 2025 07:44:35 -0600 Subject: [PATCH 38/75] trying cache-hit --- .github/actions/test-coverage/action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index 16787c28d2..df32f1a8e8 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -63,7 +63,7 @@ runs: echo "::endgroup::" - name: ci/upload-coverage - if: github.ref_name == 'main' + if: github.ref_name == 'mainX' uses: actions/upload-artifact@v4 with: name: test-coverage-result-${{ inputs.run_id }} @@ -71,7 +71,7 @@ runs: overwrite: true - name: ci/generate-run-id-file - if: github.ref_name == 'main' + if: github.ref_name == 'mainX' shell: bash run: | echo "::group::generate-last-run-id" @@ -79,7 +79,7 @@ runs: echo "::endgroup::" - name: ci/cache-run-id-file - if: github.ref_name == 'main' + if: github.ref_name == 'mainX' uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f with: path: run-id.txt From 2375276f588bf9e7bad395cdb7775aadcdfb8cbc Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Tue, 11 Mar 2025 07:44:56 -0600 Subject: [PATCH 39/75] real trying cache-hit --- .github/actions/test-coverage/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index df32f1a8e8..f53241aebf 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -84,3 +84,4 @@ runs: with: path: run-id.txt key: last-run-id + cache-hit: write From 55f1c08979bf70f7bb4b134efec45cc537e57f44 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Tue, 11 Mar 2025 10:03:01 -0600 Subject: [PATCH 40/75] testing to make sure cache-run-id runs --- .github/actions/test-coverage/action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index f53241aebf..4a4c578fe4 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -63,7 +63,7 @@ runs: echo "::endgroup::" - name: ci/upload-coverage - if: github.ref_name == 'mainX' + if: github.ref_name != 'main' uses: actions/upload-artifact@v4 with: name: test-coverage-result-${{ inputs.run_id }} @@ -71,7 +71,7 @@ runs: overwrite: true - name: ci/generate-run-id-file - if: github.ref_name == 'mainX' + if: github.ref_name != 'main' shell: bash run: | echo "::group::generate-last-run-id" @@ -79,7 +79,7 @@ runs: echo "::endgroup::" - name: ci/cache-run-id-file - if: github.ref_name == 'mainX' + if: github.ref_name != 'main' uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f with: path: run-id.txt From c2ef26568e03ed094db31932daacd9376c04b387 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Tue, 11 Mar 2025 10:09:39 -0600 Subject: [PATCH 41/75] save-always true --- .github/actions/test-coverage/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index 4a4c578fe4..558c6079e9 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -84,4 +84,4 @@ runs: with: path: run-id.txt key: last-run-id - cache-hit: write + save-always: true From 6a7fa0521fa16b81040440e589ee2d163e87f865 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Tue, 11 Mar 2025 10:16:03 -0600 Subject: [PATCH 42/75] save-always deprecated --- .github/actions/test-coverage/action.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index 558c6079e9..62dbaa7a89 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -79,9 +79,8 @@ runs: echo "::endgroup::" - name: ci/cache-run-id-file - if: github.ref_name != 'main' - uses: actions/cache@0c907a75c2c80ebcb7f088228285e798b750cf8f + if: github.ref_name != 'main' && always() + uses: actions/cache/save@0c907a75c2c80ebcb7f088228285e798b750cf8f with: path: run-id.txt key: last-run-id - save-always: true From e2f5d1912edbbd79b3959cc2cc1e114ff889107f Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Tue, 11 Mar 2025 11:01:53 -0600 Subject: [PATCH 43/75] let's try different strategy --- .github/actions/test-coverage/action.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index 62dbaa7a89..e37b31691a 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -20,7 +20,8 @@ runs: continue-on-error: true with: path: run-id.txt - key: last-run-id + restore-keys: | + last-run-id - name: ci/put-last-run-id-into-env shell: bash @@ -79,8 +80,8 @@ runs: echo "::endgroup::" - name: ci/cache-run-id-file - if: github.ref_name != 'main' && always() + if: github.ref_name != 'main' uses: actions/cache/save@0c907a75c2c80ebcb7f088228285e798b750cf8f with: path: run-id.txt - key: last-run-id + key: last-run-id-${{ inputs.run_id }} From 3fe2f16759b86f8f3d7656b368c64cbbeb886d8b Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Tue, 11 Mar 2025 11:25:38 -0600 Subject: [PATCH 44/75] add key --- .github/actions/test-coverage/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index e37b31691a..3c6dd0537f 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -20,6 +20,7 @@ runs: continue-on-error: true with: path: run-id.txt + key: last-run-id-${{ inputs.run_id }} restore-keys: | last-run-id From 9e2631b24ac7ff2938e5dc53974b8b738ee153df Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Tue, 11 Mar 2025 15:08:25 -0600 Subject: [PATCH 45/75] restore-key adding a - --- .github/actions/test-coverage/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index 3c6dd0537f..fdde4c7ff0 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -22,7 +22,7 @@ runs: path: run-id.txt key: last-run-id-${{ inputs.run_id }} restore-keys: | - last-run-id + last-run-id- - name: ci/put-last-run-id-into-env shell: bash From 5d6a287e2481a9b6793444ff361973989b7d6660 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Tue, 11 Mar 2025 15:45:24 -0600 Subject: [PATCH 46/75] only perform on `main` --- .github/actions/test-coverage/action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index fdde4c7ff0..5c5db9b161 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -65,7 +65,7 @@ runs: echo "::endgroup::" - name: ci/upload-coverage - if: github.ref_name != 'main' + if: github.ref_name == 'main' uses: actions/upload-artifact@v4 with: name: test-coverage-result-${{ inputs.run_id }} @@ -73,7 +73,7 @@ runs: overwrite: true - name: ci/generate-run-id-file - if: github.ref_name != 'main' + if: github.ref_name == 'main' shell: bash run: | echo "::group::generate-last-run-id" @@ -81,7 +81,7 @@ runs: echo "::endgroup::" - name: ci/cache-run-id-file - if: github.ref_name != 'main' + if: github.ref_name == 'main' uses: actions/cache/save@0c907a75c2c80ebcb7f088228285e798b750cf8f with: path: run-id.txt From 22fc24eab6ab3546d6e5965756e1853920e42e0e Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Tue, 11 Mar 2025 16:26:43 -0600 Subject: [PATCH 47/75] only run on main or if its a PR --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8932cb3066..0622ffc04a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,9 +17,10 @@ jobs: steps: - name: ci/checkout-repo uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - # - name: ci/test - # uses: ./.github/actions/test + - name: ci/test + uses: ./.github/actions/test - name: ci/test-coverage + if: github.event_name == 'pull_request' || github.ref_name == 'main' uses: ./.github/actions/test-coverage with: github_token: ${{ secrets.MM_MOBILE_GITHUB_TOKEN }} From aecc5b63fc101c245b7e1755676f5821ceee5c5d Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 07:09:47 -0600 Subject: [PATCH 48/75] coverage_threshold --- scripts/compare-coverage.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index c985e2124b..a4dd596df8 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -1,5 +1,6 @@ #!/bin/bash +COVERAGE_THRESHOLD=1.0 MAIN_COVERAGE_FILE="$1/coverage-summary.json" RECENT_COVERAGE_FILE="$2/coverage-summary.json" PR_NUMBER="$3" @@ -29,8 +30,8 @@ for metric in lines statements branches functions; do row=$(printf "| %-15s | %9.2f%% | %9.2f%% | %8.2f%% |" "${metric^}" "$main" "$pr" "$diff") COMMENT_BODY+=$'\n'"$row" - if (( $(echo "$diff < -1" | bc -l) )); then - echo "::error::${metric^} coverage has decreased by more than 1% ($diff%)" + if (( $(echo "$diff < -$COVERAGE_THRESHOLD" | bc -l) )); then + echo "::error::${metric^} coverage has decreased by more than ${COVERAGE_THRESHOLD}% ($diff%)" HAS_DECREASE=1 fi done @@ -39,7 +40,7 @@ COMMENT_BODY+=$'\n'"+-----------------+------------+------------+-----------+ \`\`\`" if [ "$HAS_DECREASE" -eq 1 ]; then - COMMENT_BODY+=$'\n\n'"⚠️ **Warning:** One or more coverage metrics have decreased by more than 1%" + COMMENT_BODY+=$'\n\n'"⚠️ **Warning:** One or more coverage metrics have decreased by more than ${COVERAGE_THRESHOLD}%" fi # Post comment to GitHub PR From 47992ea2109a0634d88a0817c3fc26e4126a6daf Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 07:20:23 -0600 Subject: [PATCH 49/75] remove comments --- scripts/compare-coverage.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index a4dd596df8..86ddafd088 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -11,7 +11,6 @@ if [ ! -f "$MAIN_COVERAGE_FILE" ] || [ ! -f "$RECENT_COVERAGE_FILE" ]; then exit 0 fi -# Create the comment body with proper newlines and no extra spaces COMMENT_BODY="### Coverage Comparison Report \`\`\` @@ -19,14 +18,12 @@ COMMENT_BODY="### Coverage Comparison Report | Metric | Main | This PR | Diff | +-----------------+------------+------------+-----------+" -# Compare each metric HAS_DECREASE=0 for metric in lines statements branches functions; do main=$(jq ".total.${metric}.pct" "$MAIN_COVERAGE_FILE") pr=$(jq ".total.${metric}.pct" "$RECENT_COVERAGE_FILE") diff=$(echo "$pr - $main" | bc) - # Add row to table with exact spacing row=$(printf "| %-15s | %9.2f%% | %9.2f%% | %8.2f%% |" "${metric^}" "$main" "$pr" "$diff") COMMENT_BODY+=$'\n'"$row" @@ -43,7 +40,6 @@ if [ "$HAS_DECREASE" -eq 1 ]; then COMMENT_BODY+=$'\n\n'"⚠️ **Warning:** One or more coverage metrics have decreased by more than ${COVERAGE_THRESHOLD}%" fi -# Post comment to GitHub PR if [ -n "$PR_NUMBER" ] && [ -n "$GITHUB_TOKEN" ]; then curl -X POST \ -H "Authorization: token $GITHUB_TOKEN" \ @@ -52,7 +48,6 @@ if [ -n "$PR_NUMBER" ] && [ -n "$GITHUB_TOKEN" ]; then -d "{\"body\":$(echo "$COMMENT_BODY" | jq -R -s .)}" fi -# Also print to console echo "$COMMENT_BODY" # Not failing the build for now From a38547b80a4eb78b3c66dbf4664a593e5c64fb18 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 08:01:03 -0600 Subject: [PATCH 50/75] add total --- scripts/compare-coverage.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index 86ddafd088..e3619fbcc0 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -19,6 +19,7 @@ COMMENT_BODY="### Coverage Comparison Report +-----------------+------------+------------+-----------+" HAS_DECREASE=0 + for metric in lines statements branches functions; do main=$(jq ".total.${metric}.pct" "$MAIN_COVERAGE_FILE") pr=$(jq ".total.${metric}.pct" "$RECENT_COVERAGE_FILE") @@ -33,6 +34,17 @@ for metric in lines statements branches functions; do fi done +# Add separator line +COMMENT_BODY+=$'\n'"+-----------------+------------+------------+-----------+" + +# Add total row using the total from JSON +main_total=$(jq ".total.total.pct" "$MAIN_COVERAGE_FILE") +pr_total=$(jq ".total.total.pct" "$RECENT_COVERAGE_FILE") +total_diff=$(echo "$pr_total - $main_total" | bc) + +row=$(printf "| %-15s | %9.2f%% | %9.2f%% | %8.2f%% |" "Total" "$main_total" "$pr_total" "$total_diff") +COMMENT_BODY+=$'\n'"$row" + COMMENT_BODY+=$'\n'"+-----------------+------------+------------+-----------+ \`\`\`" From fb1088bad75b92c0c37033e1b5d3a83aca80ff1c Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 08:06:13 -0600 Subject: [PATCH 51/75] removing unneeded comments --- scripts/compare-coverage.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index e3619fbcc0..02601f3069 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -34,10 +34,8 @@ for metric in lines statements branches functions; do fi done -# Add separator line COMMENT_BODY+=$'\n'"+-----------------+------------+------------+-----------+" -# Add total row using the total from JSON main_total=$(jq ".total.total.pct" "$MAIN_COVERAGE_FILE") pr_total=$(jq ".total.total.pct" "$RECENT_COVERAGE_FILE") total_diff=$(echo "$pr_total - $main_total" | bc) From 199d8f627444c58bac8a8232e55a605c71f67481 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 08:19:28 -0600 Subject: [PATCH 52/75] calculate total --- scripts/compare-coverage.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index 02601f3069..04e7279865 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -20,11 +20,22 @@ COMMENT_BODY="### Coverage Comparison Report HAS_DECREASE=0 +# Initialize variables for calculating average total coverage +# since the coverage summary doesn't provide an overall total +main_total=0 +pr_total=0 +metric_count=0 + for metric in lines statements branches functions; do main=$(jq ".total.${metric}.pct" "$MAIN_COVERAGE_FILE") pr=$(jq ".total.${metric}.pct" "$RECENT_COVERAGE_FILE") diff=$(echo "$pr - $main" | bc) + # Add to totals for average calculation + main_total=$(echo "$main_total + $main" | bc) + pr_total=$(echo "$pr_total + $pr" | bc) + metric_count=$((metric_count + 1)) + row=$(printf "| %-15s | %9.2f%% | %9.2f%% | %8.2f%% |" "${metric^}" "$main" "$pr" "$diff") COMMENT_BODY+=$'\n'"$row" @@ -34,13 +45,15 @@ for metric in lines statements branches functions; do fi done +# Add separator line COMMENT_BODY+=$'\n'"+-----------------+------------+------------+-----------+" -main_total=$(jq ".total.total.pct" "$MAIN_COVERAGE_FILE") -pr_total=$(jq ".total.total.pct" "$RECENT_COVERAGE_FILE") -total_diff=$(echo "$pr_total - $main_total" | bc) +# Calculate the average coverage across all metrics +main_avg=$(echo "scale=2; $main_total / $metric_count" | bc) +pr_avg=$(echo "scale=2; $pr_total / $metric_count" | bc) +total_diff=$(echo "$pr_avg - $main_avg" | bc) -row=$(printf "| %-15s | %9.2f%% | %9.2f%% | %8.2f%% |" "Total" "$main_total" "$pr_total" "$total_diff") +row=$(printf "| %-15s | %9.2f%% | %9.2f%% | %8.2f%% |" "Total" "$main_avg" "$pr_avg" "$total_diff") COMMENT_BODY+=$'\n'"$row" COMMENT_BODY+=$'\n'"+-----------------+------------+------------+-----------+ From 5095eaec07f17e2a4078f6e87336f8dac0a4621e Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 08:24:28 -0600 Subject: [PATCH 53/75] run test in `release-*` only --- .github/actions/test/action.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/actions/test/action.yaml b/.github/actions/test/action.yaml index 370c25c37d..2ea363324c 100644 --- a/.github/actions/test/action.yaml +++ b/.github/actions/test/action.yaml @@ -15,6 +15,8 @@ runs: echo "::endgroup::" - name: ci/run-tests + # main and PR will run test:coverage + if: startsWith(github.ref_name, 'release-') shell: bash run: | echo "::group::run-tests" From 957bd6c73361afc00cff8888090bdeecac7235a7 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 08:43:41 -0600 Subject: [PATCH 54/75] making sure that only PR will run --- .github/actions/test-coverage/action.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index 5c5db9b161..f52c8c82cc 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -16,6 +16,8 @@ runs: uses: ./.github/actions/prepare-node-deps - name: ci/get-last-run-id + if: github.event_name == 'pull_request' + id: get-last-run-id uses: actions/cache/restore@0c907a75c2c80ebcb7f088228285e798b750cf8f continue-on-error: true with: @@ -24,7 +26,13 @@ runs: restore-keys: | last-run-id- + - name: Set PR condition + if: github.event_name == 'pull_request' && steps.get-last-run-id.outcome == 'success' + shell: bash + run: echo "IS_PR_WITH_CACHE=true" >> $GITHUB_ENV + - name: ci/put-last-run-id-into-env + if: env.IS_PR_WITH_CACHE == 'true' shell: bash run: | echo "::group::put-last-run-id-into-env" @@ -32,6 +40,7 @@ runs: echo "::endgroup::" - name: ci/download-main-coverage + if: env.IS_PR_WITH_CACHE == 'true' uses: actions/download-artifact@v4 with: name: test-coverage-result-${{ env.LAST_RUN_ID }} @@ -40,13 +49,14 @@ runs: run-id: ${{ env.LAST_RUN_ID }} - name: ci/read-coverage + if: env.IS_PR_WITH_CACHE == 'true' shell: bash run: | echo "::group::read-coverage" ./scripts/read-coverage.sh ./main-coverage/coverage-summary.json echo "::endgroup::" - - name: ci/run-tests + - name: ci/run-tests-with-coverage shell: bash run: | echo "::group::run-tests" @@ -54,6 +64,7 @@ runs: echo "::endgroup::" - name: ci/compare-coverage + if: env.IS_PR_WITH_CACHE == 'true' shell: bash run: | echo "::group::compare-coverage" From 4ad4846581eda1c0d4b328b12b9f068322cdeea6 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 09:06:38 -0600 Subject: [PATCH 55/75] only do more steps if upload-coverage successful --- .github/actions/test-coverage/action.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index f52c8c82cc..e455e12b23 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -77,14 +77,20 @@ runs: - name: ci/upload-coverage if: github.ref_name == 'main' + id: upload-coverage uses: actions/upload-artifact@v4 with: name: test-coverage-result-${{ inputs.run_id }} path: coverage/coverage-summary.json overwrite: true + - name: Set upload success + if: github.ref_name == 'main' && steps.upload-coverage.outcome == 'success' + shell: bash + run: echo "UPLOAD_SUCCESS=true" >> $GITHUB_ENV + - name: ci/generate-run-id-file - if: github.ref_name == 'main' + if: env.UPLOAD_SUCCESS == 'true' shell: bash run: | echo "::group::generate-last-run-id" @@ -92,7 +98,7 @@ runs: echo "::endgroup::" - name: ci/cache-run-id-file - if: github.ref_name == 'main' + if: env.UPLOAD_SUCCESS == 'true' uses: actions/cache/save@0c907a75c2c80ebcb7f088228285e798b750cf8f with: path: run-id.txt From 2398d5877a4725a5e1c8551bff9cbb05deb9b3ea Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 09:35:05 -0600 Subject: [PATCH 56/75] trying thollander/actions-comment-pull-request --- .github/workflows/ci.yml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0622ffc04a..1377f3eea7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,11 +17,18 @@ jobs: steps: - name: ci/checkout-repo uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: ci/test - uses: ./.github/actions/test - - name: ci/test-coverage - if: github.event_name == 'pull_request' || github.ref_name == 'main' - uses: ./.github/actions/test-coverage + + - name: Comment PR + uses: thollander/actions-comment-pull-request@v3 with: - github_token: ${{ secrets.MM_MOBILE_GITHUB_TOKEN }} - run_id: ${{ github.run_id }} + message: | + Hello world ! :wave: + + # - name: ci/test + # uses: ./.github/actions/test + # - name: ci/test-coverage + # if: github.event_name == 'pull_request' || github.ref_name == 'main' + # uses: ./.github/actions/test-coverage + # with: + # github_token: ${{ secrets.MM_MOBILE_GITHUB_TOKEN }} + # run_id: ${{ github.run_id }} From 100e2ef51911983eb796487d782c06c635c8ea21 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 10:07:37 -0600 Subject: [PATCH 57/75] using diff way to comment. --- .github/actions/test-coverage/action.yml | 15 +++++++++++++-- .github/workflows/ci.yml | 21 +++++++-------------- scripts/compare-coverage.sh | 8 -------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index e455e12b23..5806621a20 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -65,16 +65,27 @@ runs: - name: ci/compare-coverage if: env.IS_PR_WITH_CACHE == 'true' + id: compare-coverage shell: bash run: | echo "::group::compare-coverage" - ./scripts/compare-coverage.sh \ + output=$(./scripts/compare-coverage.sh \ ./main-coverage \ ./coverage \ ${{ github.event.pull_request.number }} \ - ${{ inputs.github_token }} + ${{ inputs.github_token }}) + echo "report<> $GITHUB_ENV + echo "$output" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV echo "::endgroup::" + - name: Post coverage report + if: env.IS_PR_WITH_CACHE == 'true' + uses: thollander/actions-comment-pull-request@v3 + with: + message: ${{ env.report }} + comment_tag: coverage-report + - name: ci/upload-coverage if: github.ref_name == 'main' id: upload-coverage diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1377f3eea7..0622ffc04a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,18 +17,11 @@ jobs: steps: - name: ci/checkout-repo uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - - name: Comment PR - uses: thollander/actions-comment-pull-request@v3 + - name: ci/test + uses: ./.github/actions/test + - name: ci/test-coverage + if: github.event_name == 'pull_request' || github.ref_name == 'main' + uses: ./.github/actions/test-coverage with: - message: | - Hello world ! :wave: - - # - name: ci/test - # uses: ./.github/actions/test - # - name: ci/test-coverage - # if: github.event_name == 'pull_request' || github.ref_name == 'main' - # uses: ./.github/actions/test-coverage - # with: - # github_token: ${{ secrets.MM_MOBILE_GITHUB_TOKEN }} - # run_id: ${{ github.run_id }} + github_token: ${{ secrets.MM_MOBILE_GITHUB_TOKEN }} + run_id: ${{ github.run_id }} diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index 04e7279865..1934bac25d 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -63,14 +63,6 @@ if [ "$HAS_DECREASE" -eq 1 ]; then COMMENT_BODY+=$'\n\n'"⚠️ **Warning:** One or more coverage metrics have decreased by more than ${COVERAGE_THRESHOLD}%" fi -if [ -n "$PR_NUMBER" ] && [ -n "$GITHUB_TOKEN" ]; then - curl -X POST \ - -H "Authorization: token $GITHUB_TOKEN" \ - -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/comments" \ - -d "{\"body\":$(echo "$COMMENT_BODY" | jq -R -s .)}" -fi - echo "$COMMENT_BODY" # Not failing the build for now From 893ea6687c7a1ca26546152bf38e631c76497774 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 10:53:26 -0600 Subject: [PATCH 58/75] comment on how things work --- .github/actions/test-coverage/action.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index 5806621a20..f95923d1fa 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -1,3 +1,11 @@ +# This action is used to test the coverage of the mobile repo +# It will download the coverage result from the main branch and compare it with the current branch +# If the coverage is lower than the main branch (1% or more), it will post a warning along with +# the coverage report to the PR. +# If this action is run on the main branch, it will upload the coverage result to the main branch +# It will also generate a run id and cache it, so that the next time the action is run in the PR, +# it will use the cached run id to download the coverage result from the main branch + name: test-coverage description: Test coverage tracking for mobile repo From 62bb5a2a573df98eb75ac669204d20796149ae53 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 10:53:44 -0600 Subject: [PATCH 59/75] testing to trigger warning and see if comment is updated vs new comment --- scripts/compare-coverage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index 1934bac25d..b927ccf4ac 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -39,7 +39,7 @@ for metric in lines statements branches functions; do row=$(printf "| %-15s | %9.2f%% | %9.2f%% | %8.2f%% |" "${metric^}" "$main" "$pr" "$diff") COMMENT_BODY+=$'\n'"$row" - if (( $(echo "$diff < -$COVERAGE_THRESHOLD" | bc -l) )); then + if (( $(echo "$diff > -$COVERAGE_THRESHOLD" | bc -l) )); then echo "::error::${metric^} coverage has decreased by more than ${COVERAGE_THRESHOLD}% ($diff%)" HAS_DECREASE=1 fi From 90a801c5cf45bd2b4f258e38455946c822a5a4ef Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 13:37:57 -0600 Subject: [PATCH 60/75] omit echo messages --- scripts/compare-coverage.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index b927ccf4ac..fc9825370e 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -40,7 +40,8 @@ for metric in lines statements branches functions; do COMMENT_BODY+=$'\n'"$row" if (( $(echo "$diff > -$COVERAGE_THRESHOLD" | bc -l) )); then - echo "::error::${metric^} coverage has decreased by more than ${COVERAGE_THRESHOLD}% ($diff%)" + # Write error messages to stderr instead of stdout + echo "::error::${metric^} coverage has decreased by more than ${COVERAGE_THRESHOLD}% ($diff%)" >&2 HAS_DECREASE=1 fi done @@ -63,6 +64,7 @@ if [ "$HAS_DECREASE" -eq 1 ]; then COMMENT_BODY+=$'\n\n'"⚠️ **Warning:** One or more coverage metrics have decreased by more than ${COVERAGE_THRESHOLD}%" fi +# Only output the comment body to stdout echo "$COMMENT_BODY" # Not failing the build for now From 3732bd297f7245e31a7ce372d299c7ca0c8cf13c Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 14:06:45 -0600 Subject: [PATCH 61/75] see if giving github token would work. --- .github/actions/test-coverage/action.yml | 2 ++ scripts/compare-coverage.sh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index f95923d1fa..b43a327584 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -93,6 +93,8 @@ runs: with: message: ${{ env.report }} comment_tag: coverage-report + github_token: ${{ inputs.github_token }} + create_if_not_exists: true - name: ci/upload-coverage if: github.ref_name == 'main' diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index fc9825370e..a1a79e7cad 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -39,7 +39,7 @@ for metric in lines statements branches functions; do row=$(printf "| %-15s | %9.2f%% | %9.2f%% | %8.2f%% |" "${metric^}" "$main" "$pr" "$diff") COMMENT_BODY+=$'\n'"$row" - if (( $(echo "$diff > -$COVERAGE_THRESHOLD" | bc -l) )); then + if (( $(echo "$diff < -$COVERAGE_THRESHOLD" | bc -l) )); then # Write error messages to stderr instead of stdout echo "::error::${metric^} coverage has decreased by more than ${COVERAGE_THRESHOLD}% ($diff%)" >&2 HAS_DECREASE=1 From 6e84d9d503aad51256f826ff4fcfb0169643d4f3 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 15:14:42 -0600 Subject: [PATCH 62/75] wrong use of param --- .github/actions/test-coverage/action.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index b43a327584..660b7185b7 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -92,9 +92,9 @@ runs: uses: thollander/actions-comment-pull-request@v3 with: message: ${{ env.report }} - comment_tag: coverage-report - github_token: ${{ inputs.github_token }} - create_if_not_exists: true + comment-tag: coverage-report + github-token: ${{ inputs.github_token }} + create-if-not-exists: true - name: ci/upload-coverage if: github.ref_name == 'main' From f1cd18e27a66f6569e57c9e8e7fd7a2f5dccdaec Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 15:34:23 -0600 Subject: [PATCH 63/75] try without github token --- .github/actions/test-coverage/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index 660b7185b7..3396130e42 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -93,7 +93,7 @@ runs: with: message: ${{ env.report }} comment-tag: coverage-report - github-token: ${{ inputs.github_token }} + # github-token: ${{ inputs.github_token }} create-if-not-exists: true - name: ci/upload-coverage From 3645d88f30bf092d3e663a2a1ebe39f532862c69 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 16:16:16 -0600 Subject: [PATCH 64/75] adding a very simple change to see where it lands --- scripts/compare-coverage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index a1a79e7cad..40b5007d70 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -15,7 +15,7 @@ COMMENT_BODY="### Coverage Comparison Report \`\`\` +-----------------+------------+------------+-----------+ -| Metric | Main | This PR | Diff | +| Metric | Main | This XX | Diff | +-----------------+------------+------------+-----------+" HAS_DECREASE=0 From 9f625b3f5f77129e966ef8f5f91f917dd308ffe7 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 16:34:44 -0600 Subject: [PATCH 65/75] using cache hit instead. --- .github/actions/test-coverage/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index 3396130e42..e24a85d3e3 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -35,7 +35,7 @@ runs: last-run-id- - name: Set PR condition - if: github.event_name == 'pull_request' && steps.get-last-run-id.outcome == 'success' + if: github.event_name == 'pull_request' && steps.get-last-run-id.outputs.cache-hit == 'true' shell: bash run: echo "IS_PR_WITH_CACHE=true" >> $GITHUB_ENV From 67e525e1be4d040afb6eb8a47ae0f8202d29818b Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 16:49:35 -0600 Subject: [PATCH 66/75] creating the cache again. how did i lose it? --- .github/actions/test-coverage/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index e24a85d3e3..bf10bd89dc 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -97,7 +97,7 @@ runs: create-if-not-exists: true - name: ci/upload-coverage - if: github.ref_name == 'main' + if: github.ref_name != 'main' id: upload-coverage uses: actions/upload-artifact@v4 with: @@ -106,7 +106,7 @@ runs: overwrite: true - name: Set upload success - if: github.ref_name == 'main' && steps.upload-coverage.outcome == 'success' + if: github.ref_name != 'main' && steps.upload-coverage.outcome == 'success' shell: bash run: echo "UPLOAD_SUCCESS=true" >> $GITHUB_ENV From d432757f10874b22699395bffc9f0195b1d1a845 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Wed, 12 Mar 2025 16:58:09 -0600 Subject: [PATCH 67/75] revert back --- .github/actions/test-coverage/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index bf10bd89dc..e24a85d3e3 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -97,7 +97,7 @@ runs: create-if-not-exists: true - name: ci/upload-coverage - if: github.ref_name != 'main' + if: github.ref_name == 'main' id: upload-coverage uses: actions/upload-artifact@v4 with: @@ -106,7 +106,7 @@ runs: overwrite: true - name: Set upload success - if: github.ref_name != 'main' && steps.upload-coverage.outcome == 'success' + if: github.ref_name == 'main' && steps.upload-coverage.outcome == 'success' shell: bash run: echo "UPLOAD_SUCCESS=true" >> $GITHUB_ENV From 4439acbab2610262e0da46cf06c4a0904d0907c9 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Thu, 13 Mar 2025 05:04:28 -0600 Subject: [PATCH 68/75] cache-hit might be off --- .github/actions/test-coverage/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index e24a85d3e3..911f1cb79d 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -35,7 +35,7 @@ runs: last-run-id- - name: Set PR condition - if: github.event_name == 'pull_request' && steps.get-last-run-id.outputs.cache-hit == 'true' + if: github.event_name == 'pull_request' && steps.get-last-run-id.cache-hit == 'true' shell: bash run: echo "IS_PR_WITH_CACHE=true" >> $GITHUB_ENV @@ -85,7 +85,7 @@ runs: echo "report<> $GITHUB_ENV echo "$output" >> $GITHUB_ENV echo "EOF" >> $GITHUB_ENV - echo "::endgroup::" + echo "::endgroup:: - name: Post coverage report if: env.IS_PR_WITH_CACHE == 'true' From 7ccc8d353fbec2b68e5699eed10be9347a9ecd44 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Thu, 13 Mar 2025 05:29:09 -0600 Subject: [PATCH 69/75] debug --- .github/actions/test-coverage/action.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index 911f1cb79d..8a8f83e6e3 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -34,8 +34,18 @@ runs: restore-keys: | last-run-id- + - name: Debug condition values + shell: bash + run: | + echo "Event name: ${{ github.event_name }}" + echo "Cache hit: ${{ steps.get-last-run-id.outputs.cache-hit }}" + echo "Cache hit (direct): ${{ steps.get-last-run-id.cache-hit }}" + echo "All outputs: " + echo "${{ toJSON(steps.get-last-run-id) }}" + exit 0 + - name: Set PR condition - if: github.event_name == 'pull_request' && steps.get-last-run-id.cache-hit == 'true' + if: github.event_name == 'pull_request' && steps.get-last-run-id.outputs.cache-hit == 'true' shell: bash run: echo "IS_PR_WITH_CACHE=true" >> $GITHUB_ENV From b12812b44648b8c2876c14e65d43bc5d0515dd71 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Thu, 13 Mar 2025 05:45:05 -0600 Subject: [PATCH 70/75] debug with failing cache restoration --- .github/actions/test-coverage/action.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index 8a8f83e6e3..833b7cf5ce 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -32,20 +32,19 @@ runs: path: run-id.txt key: last-run-id-${{ inputs.run_id }} restore-keys: | - last-run-id- + last-run-id-purposedly-wrong-key - name: Debug condition values shell: bash run: | echo "Event name: ${{ github.event_name }}" - echo "Cache hit: ${{ steps.get-last-run-id.outputs.cache-hit }}" - echo "Cache hit (direct): ${{ steps.get-last-run-id.cache-hit }}" + echo "Cache matched key: ${{ steps.get-last-run-id.outputs.cache-matched-key }}" echo "All outputs: " echo "${{ toJSON(steps.get-last-run-id) }}" - exit 0 + exit 1 - name: Set PR condition - if: github.event_name == 'pull_request' && steps.get-last-run-id.outputs.cache-hit == 'true' + if: github.event_name == 'pull_request' && steps.get-last-run-id.outputs.cache-matched-key != '' shell: bash run: echo "IS_PR_WITH_CACHE=true" >> $GITHUB_ENV From a6da72237f6868c1c6a2b7411c73a09f3febdba9 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Thu, 13 Mar 2025 05:52:39 -0600 Subject: [PATCH 71/75] check for run-id.txt instead --- .github/actions/test-coverage/action.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index 833b7cf5ce..8ebec6cce4 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -38,15 +38,23 @@ runs: shell: bash run: | echo "Event name: ${{ github.event_name }}" - echo "Cache matched key: ${{ steps.get-last-run-id.outputs.cache-matched-key }}" - echo "All outputs: " + echo "Cache outputs: " echo "${{ toJSON(steps.get-last-run-id) }}" - exit 1 + echo "File exists check:" + if [ -f "run-id.txt" ]; then + echo "run-id.txt exists" + else + echo "run-id.txt does not exist" + fi - name: Set PR condition - if: github.event_name == 'pull_request' && steps.get-last-run-id.outputs.cache-matched-key != '' + if: github.event_name == 'pull_request' shell: bash - run: echo "IS_PR_WITH_CACHE=true" >> $GITHUB_ENV + run: | + if [ -f "run-id.txt" ]; then + echo "IS_PR_WITH_CACHE=true" >> $GITHUB_ENV + fi + exit 1 - name: ci/put-last-run-id-into-env if: env.IS_PR_WITH_CACHE == 'true' From bdf48f2ff702a5d4aea291b193fb3ba75cfdc28e Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Thu, 13 Mar 2025 06:00:37 -0600 Subject: [PATCH 72/75] all into action --- .github/actions/test-coverage/action.yml | 50 ++++++++++++------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index 8ebec6cce4..72ef1c335c 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -32,38 +32,40 @@ runs: path: run-id.txt key: last-run-id-${{ inputs.run_id }} restore-keys: | - last-run-id-purposedly-wrong-key - - - name: Debug condition values - shell: bash - run: | - echo "Event name: ${{ github.event_name }}" - echo "Cache outputs: " - echo "${{ toJSON(steps.get-last-run-id) }}" - echo "File exists check:" - if [ -f "run-id.txt" ]; then - echo "run-id.txt exists" - else - echo "run-id.txt does not exist" - fi - - - name: Set PR condition + last-run-id- + + # - name: Debug condition values + # shell: bash + # run: | + # echo "Event name: ${{ github.event_name }}" + # echo "Cache outputs: " + # echo "${{ toJSON(steps.get-last-run-id) }}" + # echo "File exists check:" + # if [ -f "run-id.txt" ]; then + # echo "run-id.txt exists" + # else + # echo "run-id.txt does not exist" + # fi + + - name: ci/set-pr-condition if: github.event_name == 'pull_request' shell: bash run: | + echo "::group::set-pr-condition" if [ -f "run-id.txt" ]; then echo "IS_PR_WITH_CACHE=true" >> $GITHUB_ENV + echo "LAST_RUN_ID=$(cat run-id.txt)" >> $GITHUB_ENV fi - exit 1 - - - name: ci/put-last-run-id-into-env - if: env.IS_PR_WITH_CACHE == 'true' - shell: bash - run: | - echo "::group::put-last-run-id-into-env" - echo "LAST_RUN_ID=$(cat run-id.txt)" >> $GITHUB_ENV echo "::endgroup::" + # - name: ci/put-last-run-id-into-env + # if: env.IS_PR_WITH_CACHE == 'true' + # shell: bash + # run: | + # echo "::group::put-last-run-id-into-env" + # echo "LAST_RUN_ID=$(cat run-id.txt)" >> $GITHUB_ENV + # echo "::endgroup::" + - name: ci/download-main-coverage if: env.IS_PR_WITH_CACHE == 'true' uses: actions/download-artifact@v4 From a2f0e1c4941c902d63bdff50f34836ad790e6669 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Thu, 13 Mar 2025 06:11:07 -0600 Subject: [PATCH 73/75] missing " --- .github/actions/test-coverage/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index 72ef1c335c..84d7a46c0f 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -104,7 +104,7 @@ runs: echo "report<> $GITHUB_ENV echo "$output" >> $GITHUB_ENV echo "EOF" >> $GITHUB_ENV - echo "::endgroup:: + echo "::endgroup::" - name: Post coverage report if: env.IS_PR_WITH_CACHE == 'true' From 1a31efcb48a0bdcb742d02a67e9577780147c879 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Thu, 13 Mar 2025 06:30:45 -0600 Subject: [PATCH 74/75] remove unneeded actions * change threshold to 0.5 --- .github/actions/test-coverage/action.yml | 21 --------------------- scripts/compare-coverage.sh | 6 +++--- 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/.github/actions/test-coverage/action.yml b/.github/actions/test-coverage/action.yml index 84d7a46c0f..67471e4f47 100644 --- a/.github/actions/test-coverage/action.yml +++ b/.github/actions/test-coverage/action.yml @@ -34,19 +34,6 @@ runs: restore-keys: | last-run-id- - # - name: Debug condition values - # shell: bash - # run: | - # echo "Event name: ${{ github.event_name }}" - # echo "Cache outputs: " - # echo "${{ toJSON(steps.get-last-run-id) }}" - # echo "File exists check:" - # if [ -f "run-id.txt" ]; then - # echo "run-id.txt exists" - # else - # echo "run-id.txt does not exist" - # fi - - name: ci/set-pr-condition if: github.event_name == 'pull_request' shell: bash @@ -58,14 +45,6 @@ runs: fi echo "::endgroup::" - # - name: ci/put-last-run-id-into-env - # if: env.IS_PR_WITH_CACHE == 'true' - # shell: bash - # run: | - # echo "::group::put-last-run-id-into-env" - # echo "LAST_RUN_ID=$(cat run-id.txt)" >> $GITHUB_ENV - # echo "::endgroup::" - - name: ci/download-main-coverage if: env.IS_PR_WITH_CACHE == 'true' uses: actions/download-artifact@v4 diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index 40b5007d70..74429479cf 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -1,6 +1,6 @@ #!/bin/bash -COVERAGE_THRESHOLD=1.0 +COVERAGE_THRESHOLD=0.5 MAIN_COVERAGE_FILE="$1/coverage-summary.json" RECENT_COVERAGE_FILE="$2/coverage-summary.json" PR_NUMBER="$3" @@ -15,7 +15,7 @@ COMMENT_BODY="### Coverage Comparison Report \`\`\` +-----------------+------------+------------+-----------+ -| Metric | Main | This XX | Diff | +| Metric | Main | This PR | Diff | +-----------------+------------+------------+-----------+" HAS_DECREASE=0 @@ -39,7 +39,7 @@ for metric in lines statements branches functions; do row=$(printf "| %-15s | %9.2f%% | %9.2f%% | %8.2f%% |" "${metric^}" "$main" "$pr" "$diff") COMMENT_BODY+=$'\n'"$row" - if (( $(echo "$diff < -$COVERAGE_THRESHOLD" | bc -l) )); then + if (( $(echo "$diff > -$COVERAGE_THRESHOLD" | bc -l) )); then # Write error messages to stderr instead of stdout echo "::error::${metric^} coverage has decreased by more than ${COVERAGE_THRESHOLD}% ($diff%)" >&2 HAS_DECREASE=1 From 249cf389a1a4c0afd24be2782766910f04791bd5 Mon Sep 17 00:00:00 2001 From: Rahim Rahman Date: Thu, 13 Mar 2025 08:51:15 -0600 Subject: [PATCH 75/75] relative time --- scripts/compare-coverage.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/compare-coverage.sh b/scripts/compare-coverage.sh index 74429479cf..d821126033 100755 --- a/scripts/compare-coverage.sh +++ b/scripts/compare-coverage.sh @@ -12,6 +12,7 @@ if [ ! -f "$MAIN_COVERAGE_FILE" ] || [ ! -f "$RECENT_COVERAGE_FILE" ]; then fi COMMENT_BODY="### Coverage Comparison Report +Generated $(date '+%B %d, %Y at %H:%M:%S UTC') \`\`\` +-----------------+------------+------------+-----------+