Skip to content

Instantly share code, notes, and snippets.

@ferPrieto
Created May 18, 2023 20:35
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 ferPrieto/faf18600c1f8fc8b73b603c9c5092aeb to your computer and use it in GitHub Desktop.
Save ferPrieto/faf18600c1f8fc8b73b603c9c5092aeb to your computer and use it in GitHub Desktop.
This script parses the value from the code coverage report file and is able to update the secrets value 'CODE_COVERAGE'.
# Get code coverage generated by Jacoco reports
chmod +x $BITRISE_SOURCE_DIR/build/reports/jacoco/index.html
CURRENT_COVERAGE=$(cat $BITRISE_SOURCE_DIR/build/reports/jacoco/index.html | grep -o 'Total[^%]*%' | sed 's/<.*>/ /; s/Total//')
echo ${CURRENT_COVERAGE//[[:blank:]]/}
# Try delete previous value in Bitrise Secrets
curl -X DELETE 'https://api.bitrise.io/v0.1/apps/$APP_ID/secrets/CODE_COVERAGE' \
-H 'Content-Type: application/json' \
-H 'Authorization: $BITRISE_PERSONAL_ACCESS_TOKEN'> delete_secret_result.json
# Update Code Coverage in Bitrise Secrets
curl -X PUT 'https://api.bitrise.io/v0.1/apps/$APP_ID/secrets/CODE_COVERAGE' \
-H "accept: application/json" \
-H "Authorization: $BITRISE_PERSONAL_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"expand_in_step_inputs\": false, \"is_exposed_for_pull_requests\": true, \"is_protected\": false, \"value\": \"$CURRENT_COVERAGE\"}" > secret-result.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment