Improve logging and error handling

This commit is contained in:
Gunter Labes 2023-09-22 13:04:41 +02:00 committed by GitHub
parent 533169ec46
commit d83fb0b366
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,35 +28,38 @@ jobs:
env: env:
SHA: ${{ github.event.pull_request.head.sha }} SHA: ${{ github.event.pull_request.head.sha }}
run: | run: |
sudo apt-get install -y pngquant sudo apt-get -y -q install pngquant
comment_body="" comment_body=""
log() { printf '\e[1m%s\e[m\n' "$*"; } # write log message in bold
## Get maps changed ## Get changed maps
git fetch --depth=1 origin "$SHA" git fetch --depth=1 origin "$SHA"
mapfile -t map_paths < <(git diff --name-only HEAD "$SHA" | grep '\.map$') mapfile -t map_paths < <(git diff --name-only HEAD "$SHA" | grep '\.map$')
for map_path in "${map_paths[@]}" for map_path in "${map_paths[@]}"
do do
echo "** Working on $map_path **"
## Get new map version ## Get new map version
log "Check out $map_path from $SHA..."
new_map=${map_path##*/} new_map=${map_path##*/}
git show "$SHA":"$map_path" > "$new_map" git show "$SHA":"$map_path" > "$new_map"
## Run map diff log "Generate map diff image for $map_path..."
diff_image=${new_map%.map}.png node build/index.js "../../$map_path" "$new_map" diff_image.png
node build/index.js "../../$map_path" "$new_map" "$diff_image" identify diff_image.png
## Compress image log 'Compress image...'
pngquant --force --output "$diff_image" "$diff_image" pngquant --force --output diff_image.png diff_image.png
identify diff_image.png
## Write comment body log 'Uploading diff_image.png...'
curl_result=$(curl -F "image=@\"$diff_image\"" "https://api.imgur.com/3/upload") json=$(curl -s -F image=@diff_image.png https://api.imgur.com/3/upload | tee /dev/stderr) || continue
echo "Imgur result:" log 'Generating HTML comment...'
echo "$curl_result" html=$(jq -r --arg path "$map_path" 'if .data.link != null
then @html "<h3>\($path)</h3><img src=\"\(.data.link)\" /> <br />"
comment_body+=$(jq -r --arg path "$map_path" '@html "<h3>\($path)</h3><img src=\"\(.data.link)\" /> <br />"' <<< "$curl_result") elif has("errors") then .errors[].status | halt_error
else "Unexpected JSON structure!\n" | halt_error end') || continue
comment_body+=$html
done done
printf 'COMMENT_BODY=%s\n' "$comment_body" >> "$GITHUB_OUTPUT" printf 'COMMENT_BODY=%s\n' "$comment_body" >> "$GITHUB_OUTPUT"