forked from NUWCDIVNPT/stig-manager
-
Notifications
You must be signed in to change notification settings - Fork 2
235 lines (229 loc) · 10.1 KB
/
api-audit-test-coverage-response.yml
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
name: Test API Generate Coverage, and Run SonarCloud Analysis
on:
workflow_dispatch:
pull_request:
branches:
- main
- test-coverage
paths:
- "api/source/**"
- "test/api/**"
- ".github/workflows/api-audit-test-coverage-response.yml"
push:
branches:
- main
- test-coverage
paths:
- "api/source/**"
- "test/api/**"
- ".github/workflows/api-audit-test-coverage-response.yml"
env:
STIGMAN_API_PORT: 64001
STIGMAN_DB_HOST: localhost
STIGMAN_DB_PORT: 3306
STIGMAN_DB_PASSWORD: stigman
STIGMAN_API_AUTHORITY: http://127.0.0.1:8080/auth/realms/stigman
STIGMAN_SWAGGER_ENABLED: true
STIGMAN_SWAGGER_SERVER: http://localhost:64001/api
STIGMAN_SWAGGER_REDIRECT: http://localhost:64001/api-docs/oauth2-redirect.html
STIGMAN_DEV_RESPONSE_VALIDATION: logOnly
NODE_V8_COVERAGE: /home/runner/work/stig-manager/stig-manager/api/source/coverage/tmp/
permissions:
pull-requests: read # allows SonarCloud to decorate PRs with analysis results
jobs:
npm_audit:
name: npm audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: install dependencies
run: npm ci
working-directory: ./api/source/
- name: Audit Dependencies and Create PR Comment if needed
uses: oke-py/npm-audit-action@2c6b2da234031fbf72af81a04c76b3a152bb2222 # pin@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
create_issues: false
create_pr_comments: true
working_directory: ./api/source/
test_api:
name: Run tests with coverage
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- name: coverage directory
run: printenv NODE_V8_COVERAGE
- name: Install app dependencies
working-directory: ./api/source
run: npm ci
- name: Run mock Keycloak
id: idp-run
working-directory: ./test/api/mock-keycloak
run: |
python3 -m http.server 8080 &
- name: Run MySQL container
id: mysql-run
run: |
docker run -d --name stig-manager-db \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=rootpw \
-e MYSQL_DATABASE=stigman \
-e MYSQL_USER=stigman \
-e MYSQL_PASSWORD=stigman \
mysql:8.0.21
- name: Install c8 coverage reporter
run: |
sudo npm install -g c8
- name: Install Newman reporter
id: newman-reporter-install
run: |
sudo npm install -g newman-reporter-htmlextra
- name: Run app and echo pid
working-directory: ./api/source
run: sh -c 'echo $$ > /tmp/test.pid ; exec c8 -r html node index.js > api-log.json 2>&1' &
- name: pid file check
working-directory: ./api/source
run: cat /tmp/test.pid
- name: Wait for bootstrap
run: for i in {1..10}; do [ $i -gt 1 ] && sleep 5; curl --output /dev/null --silent --fail http://localhost:64001/api/op/configuration && s=0 && break || s=$?; printf '.'; done; (exit $s)
- name: Run Newman Collection LoadTestData
id: newman-run-loadTestData
working-directory: ./test/api
run: |
set -o pipefail
newman run postman_collection.json -e postman_environment.json -d collectionRunnerData.json -n 1 --folder LoadTestData -r cli,htmlextra --reporter-cli-no-assertions --reporter-cli-no-console --reporter-htmlextra-showOnlyFails --reporter-htmlextra-export ./newman/dataPreloadReport.html | grep -A18 '┌─────'
- name: Run Newman Collection GETS
id: newman-run-gets
if: steps.newman-run-loadTestData.conclusion == 'success'
working-directory: ./test/api
run: |
set -o pipefail
newman run postman_collection.json -e postman_environment.json -d collectionRunnerData.json -n 6 --folder GETs -r cli,htmlextra --reporter-cli-no-assertions --reporter-cli-no-console --reporter-htmlextra-showOnlyFails --reporter-htmlextra-export ./newman/GetsReport.html | grep -A18 '┌─────'
- name: Run Newman Collection Posts, Puts, Patches, Deletes
id: newman-run-pppd
if: steps.newman-run-loadTestData.conclusion == 'success'
working-directory: ./test/api
run: |
set -o pipefail
newman run postman_collection.json -e postman_environment.json -d collectionRunnerData.json -n 6 --folder "POSTS, Puts, Patches, and Deletes" -r cli,htmlextra --reporter-cli-no-assertions --reporter-cli-no-console --reporter-htmlextra-showOnlyFails --reporter-htmlextra-export ./newman/PPPDReport.html | grep -A18 '┌─────'
- name: Run Newman Collection STIGS
id: newman-run-stigs
if: steps.newman-run-loadTestData.conclusion == 'success'
working-directory: ./test/api
run: |
set -o pipefail
newman run postman_collection.json -e postman_environment.json -d collectionRunnerData.json -n 2 --folder "STIGS" -r cli,htmlextra --reporter-cli-no-assertions --reporter-cli-no-console --reporter-htmlextra-showOnlyFails --reporter-htmlextra-export ./newman/stigsReport.html | grep -A18 '┌─────'
- name: Run Newman Collection LVL1 Cross-Boundary Tests
id: newman-run-lvl1-cross-boundary
if: steps.newman-run-loadTestData.conclusion == 'success'
working-directory: ./test/api
run: |
set -o pipefail
newman run postman_collection.json -e postman_environment.json -d collectionRunnerData.json -n 1 --folder "LVL1 cross-boundary tests" -r cli,htmlextra --reporter-cli-no-assertions --reporter-cli-no-console --reporter-htmlextra-showEnvironmentData --reporter-htmlextra-export ./newman/lvl1Report.html | grep -A18 '┌─────'
- name: Run Newman Collection Additional Sundry Tests
id: newman-run-additional-sundry
if: steps.newman-run-loadTestData.conclusion == 'success'
working-directory: ./test/api
run: |
set -o pipefail
newman run postman_collection.json -e postman_environment.json -d collectionRunnerData.json -n 1 --folder "Additional sundry tests" -r cli,htmlextra --reporter-cli-no-assertions --reporter-cli-no-console --reporter-htmlextra-showEnvironmentData --reporter-htmlextra-export ./newman/AdditionalSundryReport.html | grep -A18 '┌─────'
- name: Kill child pid
working-directory: ./api/source
run: kill -SIGINT $(ps -ef --ppid `cat /tmp/test.pid` -o pid= )
- name: Wait until c8 process ends, or 60 seconds, whichever is shorter.
run: timeout 60 tail --pid=`cat /tmp/test.pid` -f /dev/null
- name: run c8 text/lcov report
working-directory: ./api/source
run: c8 report -r lcov -r text
- name: Upload Newman artifact
id: artifact-upload-newman
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: newman-htmlextra
path: ./test/api/newman
- name: Upload coverage artifact
id: artifact-upload-coverage
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: coverage-report
path: ./api/source/coverage
- name: Upload API logs
id: artifact-upload-api-logs
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: api-log
path: ./api/source/api-log.json
response_validation:
name: Response validation
needs:
- test_api
runs-on: ubuntu-latest
steps:
- name: Download API log artifact
uses: actions/download-artifact@v4
with:
name: api-log
path: ./logs
- name: Test for response validation messages
working-directory: ./logs
run: |
jq -s 'map(select(.type=="responseValidation")|{method:.data.request.method,url:.data.request.url,errors:.data.error.errors,body:.data.body})' api-log.json > response-validation.json
exit $(jq '. | length' response-validation.json)
- name: Upload response validation artifact
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: response-validation
path: ./logs/response-validation.json
SonarCloudAnalysis-API:
name: SonarCloud Analysis API
needs: test_api
runs-on: ubuntu-latest
steps:
- name: Check if PR is from a fork
id: check_fork
run: |
if [ "${{ github.event.pull_request.head.repo.fork }}" == "true" ]; then
echo "This is a PR from a fork, skipping sonarcloud analysis."
echo "SKIP_STEP=true" >> $GITHUB_ENV
fi
- name: Checkout repository
if: env.SKIP_STEP != 'true'
uses: actions/checkout@v4
with:
fetch-depth: 0 # Important to fetch all history for accurate blame information
- name: Download lcov artifact
if: env.SKIP_STEP != 'true'
uses: actions/download-artifact@v4
with:
name: coverage-report
- name: Move lcov.info to api/source
if: env.SKIP_STEP != 'true'
run: mv lcov.info ./api/source/
- name: Analyze API with SonarCloud
if: env.SKIP_STEP != 'true'
uses: SonarSource/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_API }} # Needed to push to SonarCloud
with:
# Additional arguments for the sonarcloud scanner
projectBaseDir: ./api/source
args: -Dsonar.projectKey=nuwcdivnpt_stig-manager-api
-Dsonar.projectName=nuwcdivnpt_stig-manager-api
-Dsonar.organization=nuwcdivnpt
-Dsonar.inclusions=**/*.js
-Dsonar.exclusions=**/node_modules/**,**/coverage-report/**
-Dsonar.javascript.lcov.reportPaths=./lcov.info
# This will fail the action if Quality Gate fails (leaving out for now )
# - name: Check Quality Gate
# uses: sonarsource/sonarqube-quality-gate-action@master
# env:
# SONAR_TOKEN: