-
Notifications
You must be signed in to change notification settings - Fork 398
194 lines (174 loc) · 5.77 KB
/
pr-validation.yaml
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
permissions:
contents: read
name: PR Validation
on: pull_request
jobs:
file-checks:
runs-on: ubuntu-latest
steps:
- name: Clone the code
uses: actions/checkout@v4 #v3.2.0
- name: reviewdog
uses: reviewdog/action-setup@80a06617492b461a66508e2dedf16233f0506804 # v1.0.6
with:
reviewdog_version: latest
- name: Trailing Whitespace
shell: bash
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ github.token }}
run: |
set -e
pushd "${GITHUB_WORKSPACE}/" || exit 1
echo '::group:: Flagging trailing whitespace with reviewdog 🐶 ...'
# Don't fail because of grep
set +o pipefail
# Exclude generated and vendored files, plus some legacy
# paths until we update all .gitattributes
git ls-files |
git check-attr --stdin linguist-generated | grep -Ev ': (set|true)$' | cut -d: -f1 |
git check-attr --stdin linguist-vendored | grep -Ev ': (set|true)$' | cut -d: -f1 |
git check-attr --stdin ignore-lint | grep -Ev ': (set|true)$' | cut -d: -f1 |
grep -Ev '^(vendor/|third_party/|LICENSES/|.git|bundle/)' |
grep -v api.md |
xargs grep -nE " +$" |
reviewdog -efm="%f:%l:%m" \
-name="trailing whitespace" \
-reporter="github-pr-check" \
-filter-mode="added" \
-fail-on-error="true" \
-level="error"
echo '::endgroup::'
popd
- name: EOF newline
shell: bash
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ github.token }}
run: |
set -e
pushd "${GITHUB_WORKSPACE}/" || exit 1
git status
echo '::group:: Flagging missing EOF newlines with reviewdog 🐶 ...'
# Don't fail because of misspell
set +o pipefail
# Lint exclude rule:
# - nothing in vendor/
# - nothing in third_party
# - nothing in .git/
# - no *.ai (Adobe Illustrator) files.
LINT_FILES=$(git ls-files |
git check-attr --stdin linguist-generated | grep -Ev ': (set|true)$' | cut -d: -f1 |
git check-attr --stdin linguist-vendored | grep -Ev ': (set|true)$' | cut -d: -f1 |
git check-attr --stdin ignore-lint | grep -Ev ': (set|true)$' | cut -d: -f1 |
grep -Ev '^(vendor/|third_party/|LICENSES/|.git)' |
grep -v '\.ai$' |
grep -v '\.svg$')
for x in $LINT_FILES; do
# Based on https://stackoverflow.com/questions/34943632/linux-check-if-there-is-an-empty-line-at-the-end-of-a-file
if [[ -f $x && ! ( -s "$x" && -z "$(tail -c 1 $x)" ) ]]; then
# We add 1 to `wc -l` here because of this limitation (from the man page):
# Characters beyond the final <newline> character will not be included in the line count.
echo $x:$((1 + $(wc -l $x | tr -s ' ' | cut -d' ' -f 1))): Missing newline
fi
done |
reviewdog -efm="%f:%l: %m" \
-name="EOF Newline" \
-reporter="github-pr-check" \
-filter-mode="added" \
-fail-on-error="true" \
-level="error"
echo '::endgroup::'
popd
go-lint:
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/checkout@v4 #v3.2.0
with:
submodules: recursive
- name: Setup go
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"
- name: golangci-lint
uses: golangci/[email protected]
with:
version: "v1.51.2"
test:
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/checkout@v4 #v3.2.0
with:
submodules: recursive
- name: Setup go
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"
- name: Run test
run: |
make test
- name: Check if working tree is dirty
run: |
if [[ $(git status --porcelain) ]]; then
git diff
echo '::error::run make test and commit changes'
exit 1
fi
helm:
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/checkout@v4 #v3.2.0
with:
submodules: recursive
- name: Setup go
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"
- name: Run helm-docs
run: |
make helm/docs
- name: Check if working tree is dirty
run: |
if [[ $(git status --porcelain) ]]; then
git diff
echo '::error::run make helm/docs and commit changes'
exit 1
fi
kustomize:
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/checkout@v4 #v3.2.0
with:
submodules: recursive
- name: Setup go
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"
- name: Run kustomize-crd
run: |
make kustomize-crd
- name: Check if working tree is dirty
run: |
if [[ $(git status --porcelain) ]]; then
git diff
echo '::error::run make kustomize-crd or make all and commit changes'
exit 1
fi
trivy:
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/checkout@v4 #v3.2.0
with:
submodules: recursive
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: "fs"
scan-ref: "."
format: "table"
exit-code: "1"
ignore-unfixed: true
severity: "CRITICAL,HIGH"