Created
May 23, 2016 05:21
-
-
Save 6temes/b900c4d832920118f73db662bf88b596 to your computer and use it in GitHub Desktop.
Upload result of static analysis tools to GitHub
This file contains 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
dependencies: | |
pre: | |
- bin/create_github_statuses.sh | |
test: | |
post: | |
- bundle exec rake factory_girl:lint | |
- bundle exec rubocop --format html -o ${CIRCLE_ARTIFACTS}/rubocop_output.html | |
- bundle exec brakeman -o ${CIRCLE_ARTIFACTS}/brakeman_output.json -o ${CIRCLE_ARTIFACTS}/brakeman_output.html | |
- bundle exec rubycritic app lib --mode-ci --path ${CIRCLE_ARTIFACTS}/rubycritic/ | |
- bin/update_github_statuses.sh |
This file contains 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
#!/bin/bash | |
USERNAME="your_username" | |
REPO="your_repo" | |
STATUSES_API_URL="https://api.github.com/repos/${USERNAME}/${REPO}/statuses/${CIRCLE_SHA1}" | |
CONTEXTS=(simplecov brakeman rubocop rubycritic) | |
for context in ${CONTEXTS[@]}; do | |
curl -H "Authorization: token $GITHUB_ACCESS_TOKEN" \ | |
-H "Content-Type: application/json" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-d "{\"description\": \"CircleCI is running your tests\", \"state\": \"pending\", \"context\": \"${context}\"}" \ | |
$STATUSES_API_URL | |
done |
This file contains 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
#!/bin/bash | |
USERNAME="your_username" | |
REPO="your_repo" | |
STATUSES_API_URL="https://api.github.com/repos/${USERNAME}/${REPO}/statuses/${CIRCLE_SHA1}" | |
PROJECT_ROOT_URL="https://circle-artifacts.com/gh/${USERNAME}/${REPO}/${CIRCLE_BUILD_NUM}/artifacts/0/${CIRCLE_ARTIFACTS}" | |
function push_status { | |
curl -H "Authorization: token $GITHUB_ACCESS_TOKEN" \ | |
-H "Content-Type: application/json" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-d "{\"description\": \"$1\", \"state\": \"$2\", \"context\": \"$3\", \"target_url\": \"$4\"}" \ | |
$STATUSES_API_URL | |
} | |
SIMPLECOV_TARGET_URL="${PROJECT_ROOT_URL}/coverage/index.html#_AllFiles" | |
SIMPLECOV_PERCENT=`ruby -rjson -e "puts JSON.parse(File.read('${CIRCLE_ARTIFACTS}/coverage/.last_run.json'))['result']['covered_percent']"` | |
SIMPLECOV_DESCRIPTION="${SIMPLECOV_PERCENT}% covered" | |
push_status "$SIMPLECOV_DESCRIPTION" "success" "simplecov" "$SIMPLECOV_TARGET_URL" | |
BRAKEMAN_TARGET_URL="${PROJECT_ROOT_URL}/brakeman_output.html" | |
BRAKEMAN_WARNINGS=`ruby -rjson -e "puts JSON.parse(File.read('${CIRCLE_ARTIFACTS}/brakeman_output.json'))['scan_info']['security_warnings']"` | |
BRAKEMAN_DESCRIPTION="${BRAKEMAN_WARNINGS} security warnings" | |
if [ "${BRAKEMAN_WARNINGS}" = "0" ]; then | |
BRAKEMAN_STATE="success" | |
else | |
BRAKEMAN_STATE="failure" | |
fi | |
push_status "$BRAKEMAN_DESCRIPTION" "$BRAKEMAN_STATE" "brakeman" "$BRAKEMAN_TARGET_URL" | |
RUBOCOP_TARGET_URL="${PROJECT_ROOT_URL}/rubocop_output.html" | |
RUBOCOP_WARNINGS=`grep "no offenses detected" ${CIRCLE_ARTIFACTS}/rubocop_output.html` | |
if [ ! -z "$RUBOCOP_WARNINGS" ]; then | |
RUBOCOP_STATE="success" | |
RUBOCOP_DESCRIPTION="Your code is beautiful!" | |
else | |
RUBOCOP_STATE="failure" | |
RUBOCOP_DESCRIPTION="Some Rubocop offenses detected" | |
fi | |
push_status "$RUBOCOP_DESCRIPTION" "$RUBOCOP_STATE" "rubocop" "$RUBOCOP_TARGET_URL" | |
RUBYCRITIC_TARGET_URL="${PROJECT_ROOT_URL}/rubycritic/overview.html" | |
RUBYCRITIC_SCORE=`cat ${CIRCLE_ARTIFACTS}/rubycritic/overview.html|ruby -ne 'if $_ =~ %r(^\s+<h2>([^<]+)</h2>$) then puts $1 end'` | |
RUBYCRITIC_DESCRIPTION=$RUBYCRITIC_SCORE | |
push_status "$RUBYCRITIC_DESCRIPTION" "success" "rubycritic" "$RUBYCRITIC_TARGET_URL" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment