From 8a82e2c8476027309e0b6456c3613566840e0913 Mon Sep 17 00:00:00 2001 From: Drew Bollinger Date: Fri, 8 Nov 2024 11:39:38 -0500 Subject: [PATCH] chore: add pr code coverage to ci (#4643) --- ci/partials/code-coverage-diff.yml | 15 +++++++++++++++ ci/pipeline.yml | 11 +++++++++++ ci/tasks/code-coverage-diff.sh | 28 ++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 ci/partials/code-coverage-diff.yml create mode 100755 ci/tasks/code-coverage-diff.sh diff --git a/ci/partials/code-coverage-diff.yml b/ci/partials/code-coverage-diff.yml new file mode 100644 index 000000000..92834e345 --- /dev/null +++ b/ci/partials/code-coverage-diff.yml @@ -0,0 +1,15 @@ +platform: linux +inputs: + - name: src + - name: pipeline-tasks +outputs: [name: src] +params: + GH_EMAIL: ((pages-operations-github-user-info.email)) + GH_USERNAME: ((pages-operations-github-user-info.username)) + GH_BOT_GPG_KEY: ((pages-operations-github-user-gpg.private_key)) + GH_BOT_SSH_KEY: ((pages-gpg-operations-github-sshkey.private_key)) + GH_BOT_GPG_TRUST: ((pages-operations-github-user-gpg-trust)) + GH_TOKEN: ((pages-operations-ci-github-token)) +run: + dir: src + path: ci/tasks/code-coverage-diff.sh diff --git a/ci/pipeline.yml b/ci/pipeline.yml index 92b86ac01..ddb6238c7 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -75,6 +75,17 @@ jobs: instance_vars: deploy-env: ((deploy-env)) + #@ if/end env == 'dev': + - name: code-coverage-diff + plan: + - get: src + trigger: true + - get: node + - get: pipeline-tasks + - task: code-coverage-diff + image: node + file: src/ci/partials/code-coverage-diff.yml + #@ if/end env == 'staging': - name: update-release-branch plan: diff --git a/ci/tasks/code-coverage-diff.sh b/ci/tasks/code-coverage-diff.sh new file mode 100755 index 000000000..9dba0f5ad --- /dev/null +++ b/ci/tasks/code-coverage-diff.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -e + +source "$(dirname $PWD)/pipeline-tasks/scripts/github-setup.sh" + +apt-get install jq + +# note our branch +branch=$(git rev-parse --abbrev-ref HEAD) + +# generate test coverage +yarn install +cov_cmd="yarn test:rtl --coverageReporters json-summary --coverageDirectory tmp" +tot_cmd="jq '.["total"]["lines"]["pct"]' tmp/coverage-summary.json" +bash -c $cov_cmd +newcc=$(bash -c $tot_cmd) +git checkout main +bash -c $cov_cmd +oldcc=$(bash -c $tot_cmd) + +difcc=$(($newcc-$oldcc)) + +gh pr comment $branch -b " \ + ## :robot: This is an automated code coverage report + Total coverage (lines): $newcc% + Coverage diff: $diffcc% +"