* ci(MM-63199): code coverage tracking * try to download existing coverage file * read coverage * add token * use github.token instead * passing github token * github_token passing from workflow * remove download * re-add download * wrong param * try download all artifacts * add run-id so to retrieve with download later * remove read coverage temp * use run-id to download * put files into current-coverage * using last run id * temporary comment * can retrieve last run id? * remove hard-coding * echo into github_env vs export * comparing new and old * comparison improvement * post to github * fix coverage text * refactor to main from current-coverage * formatting changes * fix missing content * small tweaking * showing the Warning to make sure * formatting * remove + * checking to see if the error shows via echo * revert the change to error * separate to a new file * comment the actual test for now * prep node deps * only run certain things on main * trying cache-hit * real trying cache-hit * testing to make sure cache-run-id runs * save-always true * save-always deprecated * let's try different strategy * add key * restore-key adding a - * only perform on `main` * only run on main or if its a PR * coverage_threshold * remove comments * add total * removing unneeded comments * calculate total * run test in `release-*` only * making sure that only PR will run * only do more steps if upload-coverage successful * trying thollander/actions-comment-pull-request * using diff way to comment. * comment on how things work * testing to trigger warning and see if comment is updated vs new comment * omit echo messages * see if giving github token would work. * wrong use of param * try without github token * adding a very simple change to see where it lands * using cache hit instead. * creating the cache again. how did i lose it? * revert back * cache-hit might be off * debug * debug with failing cache restoration * check for run-id.txt instead * all into action * missing " * remove unneeded actions * change threshold to 0.5 * relative time * skeptical about date formatting * revert back to the threshold trigger * below 80% total coverage threshold * only show one error/warning at time. * testing if the coverage drop below 80 * debug output * add Reset Test Coverage label use * try using contains vs direct comparsion * remove the label checker * temp change * ooops * revert back * let's post before exiting * consistency * total coverage threshold reset to 80%
131 lines
4.2 KiB
YAML
131 lines
4.2 KiB
YAML
# 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
|
|
|
|
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/prepare-node-deps
|
|
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:
|
|
path: run-id.txt
|
|
key: last-run-id-${{ inputs.run_id }}
|
|
restore-keys: |
|
|
last-run-id-
|
|
|
|
- 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
|
|
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 }}
|
|
path: main-coverage/
|
|
github-token: ${{ inputs.github_token }}
|
|
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-with-coverage
|
|
shell: bash
|
|
run: |
|
|
echo "::group::run-tests"
|
|
npm run test:coverage
|
|
echo "::endgroup::"
|
|
|
|
- name: ci/compare-coverage
|
|
if: env.IS_PR_WITH_CACHE == 'true'
|
|
id: compare-coverage
|
|
shell: bash
|
|
run: |
|
|
echo "::group::compare-coverage"
|
|
output=$(./scripts/compare-coverage.sh \
|
|
./main-coverage \
|
|
./coverage \
|
|
${{ github.event.pull_request.number }} \
|
|
${{ inputs.github_token }})
|
|
echo "report<<EOF" >> $GITHUB_ENV
|
|
echo "$output" >> $GITHUB_ENV
|
|
echo "EOF" >> $GITHUB_ENV
|
|
echo "::endgroup::"
|
|
|
|
- name: ci/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
|
|
create-if-not-exists: true
|
|
|
|
- name: ci/exit-on-test-coverage-failure
|
|
if: env.IS_PR_WITH_CACHE == 'true'
|
|
shell: bash
|
|
run: |
|
|
echo "::group::exit-on-test-coverage-failure"
|
|
exit ${{ steps.compare-coverage.outputs.status }}
|
|
echo "::endgroup::"
|
|
|
|
- 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: ci/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: env.UPLOAD_SUCCESS == 'true'
|
|
shell: bash
|
|
run: |
|
|
echo "::group::generate-last-run-id"
|
|
echo "${{ inputs.run_id }}" > run-id.txt
|
|
echo "::endgroup::"
|
|
|
|
- name: ci/cache-run-id-file
|
|
if: env.UPLOAD_SUCCESS == 'true'
|
|
uses: actions/cache/save@0c907a75c2c80ebcb7f088228285e798b750cf8f
|
|
with:
|
|
path: run-id.txt
|
|
key: last-run-id-${{ inputs.run_id }}
|