Skip to content

Commit

Permalink
Encode string with jq for coverage build data
Browse files Browse the repository at this point in the history
Fixes #504
  • Loading branch information
fniephaus committed Apr 5, 2021
1 parent 69ad6ca commit 26a68d2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
_builds
_cache
/bin/jq
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Expand Down
42 changes: 33 additions & 9 deletions helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ readonly GITHUB_API="https://api.github.com"
readonly COVERALLS_API="https://coveralls.io/api/v1/jobs"
readonly COVERALLS_OPTIONAL_KEYS="flag_name parallel repo_token service_job_id
service_job_number service_name service_number service_pull_request"
readonly JQ_BASE_URL="https://github.com/stedolan/jq/releases/download/jq-1.6"
readonly JQ_BINARY="${SMALLTALK_CI_HOME}/bin/jq"

readonly ANSI_BOLD="\033[1m"
readonly ANSI_RED="\033[31m"
Expand Down Expand Up @@ -376,14 +378,34 @@ to_lowercase() {
echo $1 | tr "[:upper:]" "[:lower:]"
}

ensure_jq() {
if ! is_file "${JQ_BINARY}"; then
case "$(uname -s)" in
"Linux")
download_file "${JQ_BASE_URL}/jq-linux64" "${JQ_BINARY}"
chmod +x "${JQ_BINARY}"
;;
"Darwin")
download_file "${JQ_BASE_URL}/jq-osx-amd64" "${JQ_BINARY}"
chmod +x "${JQ_BINARY}"
;;
"CYGWIN_NT-"*|"MINGW64_NT-"*)
download_file "${JQ_BASE_URL}/jq-win64.exe" "${JQ_BINARY}"
chmod +x "${JQ_BINARY}"
;;
*)
print_error_and_exit "Unsupported platform '$(uname -s)'."
;;
esac
fi
}

git_log() {
local format_value=$1
local output
output=$(git --no-pager log -1 --pretty=format:"${format_value}")
echo "${output//\"/\\\"}" # Escape double quotes
echo "$(git --no-pager log -1 --pretty=format:"${format_value}" | "${JQ_BINARY}" -Rs .)"
}


export_coveralls_data() {
local branch_name="unknown"
local flag_name="${COVERALLS_FLAG_NAME:-}"
Expand Down Expand Up @@ -451,18 +473,20 @@ export_coveralls_data() {
fi
done

ensure_jq # required for git_log

cat >"${SMALLTALK_CI_BUILD}/coveralls_build_data.json" <<EOL
{
${optional_values}
"git": {
"branch": "${branch_name}",
"head": {
"author_email": "$(git_log "%ae")",
"author_name": "$(git_log "%aN")",
"committer_email": "$(git_log "%ce")",
"committer_name": "$(git_log "%cN")",
"id": "$(git_log "%H")",
"message": "$(git_log "%s")"
"author_email": $(git_log "%ae"),
"author_name": $(git_log "%aN"),
"committer_email": $(git_log "%ce"),
"committer_name": $(git_log "%cN"),
"id": $(git_log "%H"),
"message": $(git_log "%s")
},
"remotes": [
{
Expand Down

0 comments on commit 26a68d2

Please sign in to comment.