Skip to content

Commit dc473fc

Browse files
committed
Add linters
1 parent a0cc749 commit dc473fc

File tree

4 files changed

+56
-22
lines changed

4 files changed

+56
-22
lines changed

.github/workflows/test.yml

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ defaults:
3434
shell: 'bash'
3535

3636
jobs:
37+
lint:
38+
uses: 'google-github-actions/.github/.github/workflows/lint.yml@sethvargo/lint' # ratchet:exclude
39+
3740
unit:
3841
name: 'unit'
3942
runs-on: 'ubuntu-latest'
@@ -66,6 +69,7 @@ jobs:
6669
permissions:
6770
contents: 'read'
6871
id-token: 'write'
72+
6973
runs-on: 'ubuntu-latest'
7074

7175
env:
@@ -76,7 +80,7 @@ jobs:
7680

7781
- uses: 'actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a' # ratchet:actions/setup-node@v4
7882
with:
79-
node-version: '20.x'
83+
node-version-file: 'package.json'
8084

8185
- name: 'npm build'
8286
run: 'npm ci && npm run build'
@@ -98,14 +102,17 @@ jobs:
98102
ignore_violations: 'false'
99103
fail_silently: 'false'
100104
scan_timeout: '1m'
105+
101106
- name: 'Check scan result and compare sarif report generated.'
102-
run: |
103-
report_expected="tests/resources/sarif.json"
104-
report_generated="${{ steps.violations-found.outputs.iac_scan_result_sarif_path }}"
105-
if cmp -s "$report_expected" "$report_generated"; then
107+
env:
108+
REPORT_GENERATED: '${{ steps.violations-found.outputs.iac_scan_result_sarif_path }}'
109+
SCAN_RESULT: '${{ steps.violations-found.outputs.iac_scan_result }}'
110+
run: |-
111+
REPORT_EXPECTED="tests/resources/sarif.json"
112+
if cmp -s "${REPORT_EXPECTED}" "${REPORT_GENERATED}"; then
106113
exit 1
107114
fi
108-
if [ "${{ steps.violations-found.outputs.iac_scan_result }}" != "passed" ]; then
115+
if [ "${SCAN_RESULT}" != "passed" ]; then
109116
exit 1
110117
fi
111118
@@ -117,14 +124,17 @@ jobs:
117124
scan_file_ref: 'tests/resources/no-violations-tf_plan.json'
118125
iac_type: 'terraform'
119126
failure_criteria: 'CRITICAL:2, Operator:OR'
127+
120128
- name: 'Check scan result and report not generated.'
121-
run: |
122-
report_expected="tests/resources/zero_violations_sarif.json"
123-
report_generated="${{ steps.no-violations-found.outputs.iac_scan_result_sarif_path }}"
124-
if cmp -s "$report_expected" "$report_generated"; then
129+
env:
130+
REPORT_GENERATED: '${{ steps.no-violations-found.outputs.iac_scan_result_sarif_path }}'
131+
SCAN_RESULT: '${{ steps.no-violations-found.outputs.iac_scan_result }}'
132+
run: |-
133+
REPORT_EXPECTED="tests/resources/zero_violations_sarif.json"
134+
if cmp -s "${REPORT_EXPECTED}" "${REPORT_GENERATED}"; then
125135
exit 1
126136
fi
127-
if [ "${{ steps.no-violations-found.outputs.iac_scan_result }}" != "passed" ]; then
137+
if [ "${SCAN_RESULT}" != "passed" ]; then
128138
exit 1
129139
fi
130140
@@ -138,12 +148,16 @@ jobs:
138148
iac_type: 'terraform'
139149
failure_criteria: 'HIGH:1, Operator:OR'
140150
continue-on-error: true
151+
141152
- name: 'Check scan result and action build status'
142-
run: |
143-
if [ "${{ steps.failure-criteria-satisfied.outputs.iac_scan_result }}" != "failed" ]; then
153+
env:
154+
SCAN_RESULT: '${{ steps.failure-criteria-satisfied.outputs.iac_scan_result }}'
155+
SCAN_ERROR: '${{ steps.failure-criteria-satisfied.outcome }}'
156+
run: |-
157+
if [ "${SCAN_RESULT}" != "failed" ]; then
144158
exit 1
145159
fi
146-
if [ "${{ steps.failure-criteria-satisfied.outcome }}" != "failure"]; then
160+
if [ "${SCAN_ERROR}" != "failure" ]; then
147161
exit 1
148162
fi
149163
@@ -157,9 +171,12 @@ jobs:
157171
iac_type: 'terraform'
158172
ignore_violations: 'true'
159173
failure_criteria: 'HIGH:1, Operator:OR'
174+
160175
- name: 'Check scan result'
161-
run: |
162-
if [ "${{ steps.failure-criteria-satisfied-ignore-violations-true.outputs.iac_scan_result }}" != "failed" ]; then
176+
env:
177+
SCAN_RESULT: '${{ steps.failure-criteria-satisfied-ignore-violations-true.outputs.iac_scan_result }}'
178+
run: |-
179+
if [ "${SCAN_RESULT}" != "failed" ]; then
163180
exit 1
164181
fi
165182
@@ -172,12 +189,16 @@ jobs:
172189
scan_file_ref: 'tests/resources/with-violations-tf_plan.json'
173190
iac_type: 'terraform'
174191
continue-on-error: true
192+
175193
- name: 'Check scan result and build status'
176-
run: |
177-
if [ "${{ steps.action-internal-error.outputs.iac_scan_result }}" != "error" ]; then
194+
env:
195+
SCAN_RESULT: '${{ steps.action-internal-error.outputs.iac_scan_result }}'
196+
SCAN_ERROR: '${{ steps.action-internal-error.outcome }}'
197+
run: |-
198+
if [ "${SCAN_RESULT}" != "error" ]; then
178199
exit 1
179200
fi
180-
if [ "${{ steps.action-internal-error.outcome }}" != "failure" ]; then
201+
if [ "${SCAN_ERROR}" != "failure" ]; then
181202
exit 1
182203
fi
183204
@@ -189,8 +210,11 @@ jobs:
189210
scan_file_ref: 'tests/resources/with-violations-tf_plan.json'
190211
iac_type: 'terraform'
191212
fail_silently: 'true'
192-
- name: Check scan result
193-
run: |
194-
if [ "${{ steps.action-internal-error-fail-silently-true.outputs.iac_scan_result }}" != "error" ]; then
213+
214+
- name: 'Check scan result'
215+
env:
216+
SCAN_RESULT: '${{ steps.action-internal-error-fail-silently-true.outputs.iac_scan_result }}'
217+
run: |-
218+
if [ "${SCAN_RESULT}" != "error" ]; then
195219
exit 1
196220
fi

bin/runTests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ set -eEuo pipefail
1616
FILES="$(node -e "process.stdout.write(require('node:fs').readdirSync('./', { recursive: true }).filter((e) => {return e.endsWith('.test.ts') && !e.startsWith('node_modules');}).sort().join(' '));")"
1717

1818
set -x
19+
20+
# shellcheck disable=SC2086
1921
exec node --require ts-node/register --test-reporter spec --test ${FILES}

package-lock.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"format": "eslint . --fix",
1111
"test": "bash ./bin/runTests.sh"
1212
},
13+
"engines": {
14+
"node": "20.x",
15+
"npm": "10.x"
16+
},
1317
"repository": {
1418
"type": "git",
1519
"url": "https://github.com/google-github-actions/analyze-code-security-scc"

0 commit comments

Comments
 (0)