Created
April 25, 2022 14:38
-
-
Save mitsuru/4740f7014fb7fc5c22169ae2c150b1e6 to your computer and use it in GitHub Desktop.
Attach simplecov coverage report to github status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
curl -s -H "Circle-Token: $CIRCLE_API_TOKEN" "https://circleci.com/api/v1.1/project/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/$CIRCLE_BUILD_NUM/artifacts" > tmp/.artifacts.json | |
COV_URL=`cat tmp/.artifacts.json | jq -r 'map(select(.["path"] == "coverage/index.html")) | .[].url'` | |
PERCENTAGE_LINE=`cat coverage/.last_run.json | jq '.result.line'` | |
PERCENTAGE_BRANCH=`cat coverage/.last_run.json | jq '.result.branch'` | |
COV_DESC="$PERCENTAGE_LINE% covered (branch: $PERCENTAGE_BRANCH%)" | |
[ $PERCENTAGE_LINE -eq 100 ] && STATE=success || STATE=pending | |
POST_BODY_COVERAGE="{\"state\": \"$STATE\", \"target_url\": \"$COV_URL\", \"description\": \"$COV_DESC\", \"context\": \"coverage\"}" | |
curl -XPOST \ | |
-H "Authorization: token $GITHUB_TOKEN" \ | |
-H "Content-Type: application/json" \ | |
-d "$POST_BODY_COVERAGE" \ | |
https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/statuses/$CIRCLE_SHA1 | |
TEST_RESULTS_URL=`cat tmp/.artifacts.json | jq -r 'map(select(.["path"] == "test-results/rspec/rspec.html")) | .[].url'` | |
TEST_RESULTS_STATS=`cat tmp/test-results/rspec/rspec.json | jq -r '[.summary_line, (.summary.duration * 10 | floor / 10 ) ] | "\(.[0]) (\(.[1]) seconds)"'` | |
POST_BODY_RSPEC="{\"state\": \"success\", \"target_url\": \"$TEST_RESULTS_URL\", \"description\": \"$TEST_RESULTS_STATS\", \"context\": \"rspec report\"}" | |
echo $POST_BODY_RSPEC | |
curl -XPOST \ | |
-H "Authorization: token $GITHUB_TOKEN" \ | |
-H "Content-Type: application/json" \ | |
-d "$POST_BODY_RSPEC" \ | |
https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/statuses/$CIRCLE_SHA1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment