forked from sbdchd/squawk-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
131 lines (118 loc) · 3.68 KB
/
action.yml
File metadata and controls
131 lines (118 loc) · 3.68 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: "Squawk action"
description: "Lint Postgres migrations with Squawk"
author: sbdchd
branding:
icon: "check-square"
color: "blue"
inputs:
access_token:
description: "Your GitHub Access Token (default: {{ github.token }})"
default: "${{ github.token }}"
required: true
type: string
assume-in-transaction:
description: "Assume in transaction"
required: false
default: "false"
type: boolean
config:
description: "Path to a custom config file"
required: false
default: ""
type: string
exclude:
description: "Rules to exclude, as a comma-separated string"
required: false
type: string
files:
description: "Space separated list of file paths to check. Cannot contain glob patterns."
required: false
default: ""
type: string
upload-to-github:
description: "Comment on a PR with Squawk's results"
required: false
default: "true"
type: boolean
fail-on-violations:
description: "Fail on violations"
required: false
default: "false"
type: boolean
pattern:
description: "Glob pattern of files to match. (./migrations/*)"
required: false
default: ""
type: string
pg-version:
description: "PostgreSQL version"
required: false
type: string
verbose:
description: "Verbose output"
required: false
default: "true"
type: boolean
version:
description: "Squawk NPM version to install (default: latest)"
default: "latest"
required: true
type: string
runs:
using: "composite"
steps:
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npm install -g squawk-cli@${{inputs.version}}
shell: bash
- shell: bash
run: |
ASSUME_IN_TRANSACTION="${{ inputs.assume-in-transaction }}"
CONFIG="${{ inputs.config }}"
EXCLUDE="${{ inputs.exclude }}"
UPLOAD_TO_GITHUB="${{ inputs.upload-to-github }}"
FAIL_ON_VIOLATIONS="${{ inputs.fail-on-violations }}"
FILES="${{ inputs.files }}"
PATTERN="${{ inputs.pattern }}"
PG_VERSION="${{ inputs.pg-version }}"
VERBOSE="${{ inputs.verbose }}"
COMMAND="squawk"
if "$ASSUME_IN_TRANSACTION"; then
COMMAND="$COMMAND --assume-in-transaction"
fi
if [ -n "$CONFIG" ]; then
COMMAND="$COMMAND --config=$CONFIG"
fi
if [ -n "$EXCLUDE" ]; then
COMMAND="$COMMAND --exclude=$EXCLUDE"
fi
if [ -n "$PG_VERSION" ]; then
COMMAND="$COMMAND --pg-version=$PG_VERSION"
fi
if "$VERBOSE"; then
COMMAND="$COMMAND --verbose"
fi
# We can only leave a comment when we run on pull_request.
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
if "$UPLOAD_TO_GITHUB"; then
COMMAND="$COMMAND upload-to-github"
fi
if "$FAIL_ON_VIOLATIONS"; then
COMMAND="$COMMAND --fail-on-violations"
fi
fi
if [ -n "$FILES" ]; then
COMMAND="$COMMAND $FILES"
fi
if [ -n "$PATTERN" ]; then
expandedFiles=$(find . \( -path "./$PATTERN" -or -path "$PATTERN" \) -type f | xargs echo)
COMMAND="$COMMAND $expandedFiles"
fi
export SQUAWK_GITHUB_API_URL=$GITHUB_API_URL
export SQUAWK_GITHUB_TOKEN=${{inputs.access_token}}
export SQUAWK_GITHUB_REPO_OWNER=$(jq --raw-output .repository.owner.login "$GITHUB_EVENT_PATH")
export SQUAWK_GITHUB_REPO_NAME=$(jq --raw-output .repository.name "$GITHUB_EVENT_PATH")
export SQUAWK_GITHUB_PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
echo "Running: $COMMAND"
sh -c "$COMMAND"