forked from bytebase/sql-review-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.sh
executable file
·63 lines (57 loc) · 1.57 KB
/
main.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
# ===========================================================================
# File: main.sh
# Description: usage: ./main.sh --files=[files] --database-type=[database type] --override-file=[override file path] --template-id=[template id]
# ===========================================================================
# Get parameters
for i in "$@"
do
case $i in
--files=*)
FILES="${i#*=}"
shift
;;
--database-type=*)
DATABASE_TYPE="${i#*=}"
shift
;;
--override-file=*)
OVERRIDE_FILE="${i#*=}"
shift
;;
--template-id=*)
TEMPLATE_ID="${i#*=}"
shift
;;
*) # unknown option
;;
esac
done
# Use BB_SQL_API from environment as default value.
# Users can deploy their own SQL Service from https://github.com/Bytebase/Bytebase/blob/main/Dockerfile.sql-service, thus they can get their own SQL check API and inject it into the repo's environment
API_URL=$BB_SQL_API
if [ -z $API_URL ]
then
API_URL=https://sql.bytebase.com/v1/advise
fi
override=""
if [ ! -z $OVERRIDE_FILE ]
then
override=`cat $OVERRIDE_FILE`
if [ $? != 0 ]
then
echo "::error file=$FILE,line=1,col=5,endColumn=7::Cannot find SQL review config file"
exit 1
fi
fi
result=0
for FILE in $FILES; do
if [[ $FILE =~ \.sql$ ]]; then
echo "Start check statement in file $FILE"
$GITHUB_ACTION_PATH/sql-review.sh --file=$FILE --database-type=$DATABASE_TYPE --override="$override" --template-id="$TEMPLATE_ID" --api=$API_URL
if [ $? != 0 ]; then
result=1
fi
fi
done
exit $result