Skip to content

Commit

Permalink
Debugged until it worked (#1)
Browse files Browse the repository at this point in the history
* moar debug

* error code

* fixed typo

* capture output

* set timeout limits

* a bit more clean up

* removed debug and cleaned up a bit

* tweaking

* last one?
  • Loading branch information
fearphage committed Mar 1, 2019
1 parent 0ea3433 commit a369adb
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ parse_json() {
conclusion: (if map(select(.level == "error")) | length > 0 then "failure" else "success" end),
output: {
title: $name,
summary: map({level: .level}) | group_by(.level) | map({key: .[0].level, value: length}) | from_entries | "\(.error // 0) error(s) / \(.warning // 0) warning(s) / \(.info // 0) messages",
summary: map({level: .level}) | group_by(.level) | map({key: .[0].level, value: length}) | from_entries | "\(.error // 0) error(s) / \(.warning // 0) warning(s) / \(.info // 0) message(s)",
annotations: map({
path: .file,
start_line: .line,
Expand All @@ -29,7 +29,7 @@ parse_json() {
message: .message
})
}
}' "$1"
}'
}

request() {
Expand All @@ -46,22 +46,29 @@ request() {

>&2 echo "DEBUG: \$1 = $1 ; \$method = $method ; \$suffix = $suffix"

curl --location --show-error \
curl \
--location \
--show-error \
--silent \
--connect-timeout 5 \
--max-time 5 \
--request "$method" \
--header 'Accept: application/vnd.github.antiope-preview+json' \
--header "Authorization: token ${GITHUB_TOKEN}" \
--header 'Content-Type: application/json' \
--header 'User-Agent: github-actions' \
--data "$2" \
"${1}/check-runs${suffix}"
"${1}/check-runs${suffix}" 2> /dev/null
}

run_shellcheck() {
(find . -type f -name "*.sh" -exec "shellcheck" "--format=json" {} \;

# shellcheck disable=SC2013
for file in $(grep -IRl "#\!\(/usr/bin/env \|/bin/\)sh" --exclude-dir ".git" --exclude-dir "node_modules" --exclude "*.txt" --exclude "*.sh"); do
shellcheck --format=json --shell=sh "$file"
for ext in bash sh; do
# shellcheck disable=SC2013
for file in $(grep -il "#\!\(/usr/bin/env \|/bin/\)$ext" --exclude-dir ".git" --exclude-dir "node_modules" --exclude "*.txt" --exclude "*.sh"); do
shellcheck --format=json --shell=$ext "$file"
done
done) | jq --slurp flatten
}

Expand All @@ -70,40 +77,28 @@ timestamp() {
}

main() {
jq . "$GITHUB_EVENT_PATH"
local id
local json
local response
local url

# github doesn't provide this URL so we have to create it
url="https://api.github.com/repos/$(jq --raw-output .repository.full_name "$GITHUB_EVENT_PATH")"
>&2 echo "DEBUG: \$GITHUB_ACTION = $GITHUB_ACTION ; \$GITHUB_SHA = $GITHUB_SHA ; \$url = $url"

json='{"name":"'"${GITHUB_ACTION}"'","status":"in_progress","started_at":"'"$(timestamp)"'","head_sha":"'"${GITHUB_SHA}"'"}'

>&2 echo "DEBUG: \$json => $json"

# start check
response="$(request "$url" "$json")"
>&2 echo "DEBUG: \$response <> $response"

>&2 echo "DEBUG: before id"
id=$(echo "$response" | jq --raw-output .id)

>&2 echo "DEBUG: response: $response / json: $json / id: $id"

if [ -z "$id" ] || [ "$id" = "null" ]; then
exit 78
fi

>&2 echo "DEBUG: before run_shellcheck"

results=$(run_shellcheck)
>&2 echo "DEBUG: $results => $results"
if [ "$(jq --raw-output length "$results")" -eq 0 ]; then
exit 0
fi
json=$(run_shellcheck | parse_json)

json=$(parse_json "$results")
>&2 echo "DEBUG: pre-patch json => $json"
response=$(request "$url" "$json" "$id")
>&2 echo "DEBUG: response $response"
# update check with results
request "$url" "$json" "$id"
}

main "$@"

0 comments on commit a369adb

Please sign in to comment.