chore: setup SQL review CI for Bytebase #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: [pull_request] | |
jobs: | |
bytebase-sql-review: | |
runs-on: ubuntu-latest | |
name: SQL Review | |
steps: | |
- name: SQL advise | |
run: | | |
API="https://bytebase.inspection.alpha.canada.ca/hook/sql-review/c033cbf2-f0e6-4c1a-89ba-ced209b06fba-1712844967" | |
TOKEN="${{ secrets.SQL_REVIEW_API_SECRET }}" | |
echo "Start request $API" | |
pull_number=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH") | |
repository=`echo $GITHUB_REPOSITORY` | |
request_body=$(jq -n \ | |
--arg repositoryId "$repository" \ | |
--arg pullRequestId $pull_number \ | |
--arg webURL "$GITHUB_SERVER_URL" \ | |
'$ARGS.named') | |
response=$(curl -s -w "%{http_code}" -X POST $API \ | |
-H "X-SQL-Review-Token: $TOKEN" \ | |
-H "Content-Type: application/json" \ | |
-d "$request_body") | |
echo "::debug::response $response" | |
http_code=$(tail -n1 <<< "$response") | |
body=$(sed '$ d' <<< "$response") | |
if [ $http_code != 200 ]; then | |
echo ":error::Failed to check SQL with response code $http_code and body $body" | |
exit 1 | |
fi | |
status=$(echo $body | jq -r '.status') | |
content=$(echo $body | jq -r '.content') | |
while read message; do | |
echo $message | |
done <<< "$(echo $content | jq -r '.[]')" | |
if [ "$status" != "SUCCESS" ]; then exit 1; fi |