Skip to content

Instantly share code, notes, and snippets.

@oboxodo
Last active August 29, 2019 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oboxodo/9571987ea6841c0854f49a916d65c613 to your computer and use it in GitHub Desktop.
Save oboxodo/9571987ea6841c0854f49a916d65c613 to your computer and use it in GitHub Desktop.
Solano CI hook scripts for CodeClimate's coverage test-reporter supporting parallel builds

This is an example for running Code Climate Test Reporter in Solano CI (ex-TDDIUM).

This example is particular for SimpleCov and Amazon's AWS but it should still be a good template for other coverage tools and cloud storage providers.

For these scripts to work you'll need to set 3 ENV vars in Solano CI:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • CC_TEST_REPORTER_ID
#!/usr/bin/env sh
set -e
S3_FOLDER="s3://cc-test-reporter/coverage/${TDDIUM_CURRENT_COMMIT}-${TDDIUM_SESSION_ID}"
MERGED_REPORT_FILE="coverage/codeclimate-${TDDIUM_CURRENT_COMMIT}-${TDDIUM_SESSION_ID}.json"
if [ ! -f ./cc-test-reporter ]; then
echo "### CodeClimate Test Reporter not installed"
exit
fi
if [ "$TDDIUM_BUILD_STATUS" = "passed" ]; then
echo "Downloading partial Coverage files from ${S3_FOLDER}"
aws s3 sync "${S3_FOLDER}" coverage/
echo "Summing partial Coverage from `ls coverage/codeclimate.*.json` to ${MERGED_REPORT_FILE}"
./cc-test-reporter sum-coverage --output "${MERGED_REPORT_FILE}" coverage/codeclimate.*.json
echo "Uploading merged Coverage from ${MERGED_REPORT_FILE} to CodeClimate"
./cc-test-reporter upload-coverage --input "${MERGED_REPORT_FILE}" &&
echo "Successfully uploaded coverage" ||
echo "Failed to upload coverage"
else
echo "\$TDDIUM_BUILD_STATUS = $TDDIUM_BUILD_STATUS"
echo "Will only report coverage on passed builds"
fi
echo "Cleaning ${S3_FOLDER}"
aws s3 rm "${S3_FOLDER}" --recursive
#!/usr/bin/env sh
set -e
if [ ! -f ./cc-test-reporter ]; then
echo "### CodeClimate Test Reporter not installed"
exit
fi
PARTIAL_FILENAME="codeclimate.${TDDIUM_SESSION_ID}-${SOLANO_WORKER_NUM}.json"
PARTIAL_FILE="coverage/${PARTIAL_FILENAME}"
S3_FOLDER="s3://cc-test-reporter/coverage/${TDDIUM_CURRENT_COMMIT}-${TDDIUM_SESSION_ID}"
set +e
echo "### Formatting Coverage for CodeClimate to ${PARTIAL_FILE}"
./cc-test-reporter format-coverage --input-type simplecov --output "${PARTIAL_FILE}"
exit_code=$?
set -e
if [ $exit_code -eq 0 ]; then
echo "### Uploading partial Coverage to ${S3_FOLDER}"
aws s3 cp "${PARTIAL_FILE}" "${S3_FOLDER}/${PARTIAL_FILENAME}"
else
echo "### CodeClimate's Test Reporter failed finding or formatting the coverage file"
fi
#!/usr/bin/env sh
set -e
echo "### Downloading CodeClimate's Test Reporter"
set +e
curl --fail -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
exit_code=$?
set -e
if [ $exit_code -eq 0 ]; then
echo "### Making cc-test-reporter executable"
chmod +x ./cc-test-reporter
else
echo "### CodeClimate's Test Reporter couldn't be downloaded (curl failed)"
rm ./cc-test-reporter
fi
hooks:
pre_setup: ./bin/ci/pre_setup.sh
post_worker: ./bin/ci/post_worker.sh
post_build: ./bin/ci/post_build.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment