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>pull/24376/head
parent
6a002f09e1
commit
701633f1e6
|
@ -1,5 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e -o pipefail
|
||||||
|
|
||||||
shopt -s nocasematch
|
shopt -s nocasematch
|
||||||
semantic_pattern='^(Merge branch '\''.+'\'' into|(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([^)]+\))?: +[^ ])'
|
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
|
exit $exit_code
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# nb: quotes are often not required around env var names between [[ and ]]
|
# ensure expected env vars are set
|
||||||
if [[ -z $PR_TITLE || -z $COMMITS_URL ]]; then
|
set -u
|
||||||
echo ::error::required env vars: PR_TITLE, COMMITS_URL
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit_code=0
|
exit_code=0
|
||||||
|
|
||||||
if [[ ! $PR_TITLE =~ $semantic_pattern ]]; then
|
if [[ ! $PR_TITLE =~ $semantic_pattern ]]; then
|
||||||
|
@ -51,8 +49,8 @@ else
|
||||||
echo PR title OK: "$PR_TITLE"
|
echo PR title OK: "$PR_TITLE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
json=$(curl --silent "$COMMITS_URL")
|
json=$(curl --fail --retry 3 --silent "$COMMITS_URL")
|
||||||
commits=$(echo "$json" | jq --raw-output '.[] | [.sha, .commit.message] | join(" ") | split("\n") | first')
|
commits=$(echo "$json" | jq --raw-output '.[] | [.sha, (.commit.message | split("\n") | first)] | join(" ")')
|
||||||
|
|
||||||
while read -r commit; do
|
while read -r commit; do
|
||||||
commit_title=$(echo "$commit" | cut -c 42-999)
|
commit_title=$(echo "$commit" | cut -c 42-999)
|
||||||
|
|
Loading…
Reference in New Issue