Solano CI Test Coverage

📘

Examples

For more example scripts, head to the test reporter repo on GitHub.

This is an example for running Code Climate Test Reporter in Solano CI (formerly 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

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}"

echo "### Formatting Coverage for CodeClimate to ${PARTIAL_FILE}"
./cc-test-reporter format-coverage --output "${PARTIAL_FILE}"

echo "Uploading partial Coverage to ${S3_FOLDER}"
aws s3 cp "${PARTIAL_FILE}" "${S3_FOLDER}/${PARTIAL_FILENAME}"
#!/usr/bin/env sh

set -e

S3_FOLDER="s3://cc-test-reporter/coverage/${TDDIUM_CURRENT_COMMIT}"
MERGED_REPORT_FILE="coverage/codeclimate-${TDDIUM_SESSION_ID}-${TDDIUM_CURRENT_COMMIT}.json"

if [[ "passed" != "$TDDIUM_BUILD_STATUS" ]]; then
  echo "\$TDDIUM_BUILD_STATUS = $TDDIUM_BUILD_STATUS"
  echo "Will only report coverage on passed builds"
else
  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}"
fi

echo "Cleaning ${S3_FOLDER}"
aws s3 rm "${S3_FOLDER}" --recursive
#!/usr/bin/env sh

set -e

echo "### Downloading CodeClimate's Test Reporter"
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter

echo "### Making cc-test-reporter executable"
chmod +x ./cc-test-reporter

./cc-test-reporter before-build
hooks:
  pre_setup: ./bin/ci/pre_setup.sh
  post_worker: ./bin/ci/post_worker.sh
  post_build: ./bin/ci/post_build.sh