Skip to content

Commit

Permalink
chore: add pr code coverage to ci (#4643)
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbo committed Nov 8, 2024
1 parent 92aeba1 commit 8a82e2c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ci/partials/code-coverage-diff.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions ci/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 28 additions & 0 deletions ci/tasks/code-coverage-diff.sh
Original file line number Diff line number Diff line change
@@ -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%
"

0 comments on commit 8a82e2c

Please sign in to comment.