Skip to content

Commit

Permalink
chore: setup SQL review CI for Bytebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois-Werbrouck committed Apr 11, 2024
1 parent 051c6b1 commit 7116166
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/bytebase-sql-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
on: [pull_request]

Check warning on line 1 in .github/workflows/bytebase-sql-review.yml

View workflow job for this annotation

GitHub Actions / workflow-yaml-check / yaml-lint-check

1:1 [document-start] missing document start "---"

Check warning on line 1 in .github/workflows/bytebase-sql-review.yml

View workflow job for this annotation

GitHub Actions / workflow-yaml-check / yaml-lint-check

1:1 [document-start] missing document start "---"
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

0 comments on commit 7116166

Please sign in to comment.