From 701633f1e64898625e85e00d86d98af21cfc8611 Mon Sep 17 00:00:00 2001
From: Jacob Marble <jacobmarble@influxdata.com>
Date: Wed, 9 Feb 2022 14:44:06 -0800
Subject: [PATCH] chore: improve semantic check (#3694)

- bash context
- curl retry and fail with grace
- jq syntax improvement

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
---
 .github/workflows/semantic_check.sh | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/.github/workflows/semantic_check.sh b/.github/workflows/semantic_check.sh
index 89bb1578bb..0dc1c482aa 100755
--- a/.github/workflows/semantic_check.sh
+++ b/.github/workflows/semantic_check.sh
@@ -1,5 +1,7 @@
 #!/usr/bin/env bash
 
+set -e -o pipefail
+
 shopt -s nocasematch
 semantic_pattern='^(Merge branch '\''.+'\'' into|(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([^)]+\))?: +[^ ])'
 
@@ -36,12 +38,8 @@ chore:foo
   exit $exit_code
 fi
 
-# nb: quotes are often not required around env var names between [[ and ]]
-if [[ -z $PR_TITLE || -z $COMMITS_URL ]]; then
-  echo ::error::required env vars: PR_TITLE, COMMITS_URL
-  exit 1
-fi
-
+# ensure expected env vars are set
+set -u
 exit_code=0
 
 if [[ ! $PR_TITLE =~ $semantic_pattern ]]; then
@@ -51,8 +49,8 @@ else
   echo PR title OK: "$PR_TITLE"
 fi
 
-json=$(curl --silent "$COMMITS_URL")
-commits=$(echo "$json" | jq --raw-output '.[] | [.sha, .commit.message] | join(" ") | split("\n") | first')
+json=$(curl --fail --retry 3 --silent "$COMMITS_URL")
+commits=$(echo "$json" | jq --raw-output '.[] | [.sha, (.commit.message | split("\n") | first)] | join(" ")')
 
 while read -r commit; do
   commit_title=$(echo "$commit" | cut -c 42-999)