-
Notifications
You must be signed in to change notification settings - Fork 8
327 lines (274 loc) · 10.4 KB
/
nodejs.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
name: Build
on: [push]
jobs:
# -- TESTS ------------------------------------------------------------------
tests:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
node: ['18']
mongodb: ['5.0']
steps:
- name: Harden GitHub Actions Runner
uses: step-security/harden-runner@2579b52abd08b0a4c3ad0e4476ddb0f2036e3b67
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
auth.docker.io:443
github.com:443
objects.githubusercontent.com:443
pipelines.actions.githubusercontent.com:443
production.cloudflare.docker.com:443
registry-1.docker.io:443
registry.npmjs.org:443
snyk.io:443
docker.io:443
auth.docker.io:443
production.cloudflare.docker.com:443
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: ${{ matrix.node }}
check-latest: true
- name: Install dependencies
run: npm install
- name: Start MongoDB
uses: supercharge/mongodb-github-action@e815fd8a9dfede09fd6e6c144f2c9f4875e933df # tag=1.7.0
with:
mongodb-version: ${{ matrix.mongodb }}
mongodb-db: encryptionAPI
- name: Run Unit-Tests + Code Coverage
run: npm run test:coverage
- name: Save Code Coverage
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: code-coverage
path: coverage
# -- SONARCLOUD -------------------------------------------------------------
code-quality:
name: Code Quality
runs-on: ubuntu-latest
needs: tests
steps:
- name: Harden GitHub Actions Runner
uses: step-security/harden-runner@2579b52abd08b0a4c3ad0e4476ddb0f2036e3b67
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
pipelines.actions.githubusercontent.com:443
sonarcloud.io:443
scanner.sonarcloud.io:443
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Download Code Coverage
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: code-coverage
path: coverage
- name: Get App Version
run: ./scripts/version.sh
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# -- SAST SCAN --------------------------------------------------------------
code-security:
name: Code Security
runs-on: ubuntu-latest
needs: tests
# Skip any PR created by dependabot to avoid permission issues
if: (github.actor != 'dependabot[bot]')
steps:
- name: Harden GitHub Actions Runner
uses: step-security/harden-runner@2579b52abd08b0a4c3ad0e4476ddb0f2036e3b67
with:
egress-policy: block
allowed-endpoints: >
github.com:443
api.github.com:443
pipelines.actions.githubusercontent.com:443
registry.npmjs.org:443
registry-1.docker.io:443
osv-vulnerabilities.storage.googleapis.com:443
nvd.nist.gov:443
pypi.org:443
location.services.mozilla.com:443
docker.io:443
auth.docker.io:443
production.cloudflare.docker.com:443
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Perform Scan
uses: ShiftLeftSecurity/scan-action@master
env:
WORKSPACE: https://github.com/${{ github.repository }}/blob/${{ github.sha }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SCAN_ANNOTATE_PR: true
- name: Save the SCAN reports
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: sast-reports
path: reports
# -- API TESTS --------------------------------------------------------------
api-tests:
name: API Tests
runs-on: ubuntu-latest
needs: tests
strategy:
matrix:
node: ['18']
mongodb: ['5.0']
steps:
- name: Harden GitHub Actions Runner
uses: step-security/harden-runner@2579b52abd08b0a4c3ad0e4476ddb0f2036e3b67
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: ${{ matrix.node }}
check-latest: true
- name: Install dependencies
run: npm install
- name: Install Postman Newman
run: npm install newman
- name: Start MongoDB
uses: supercharge/mongodb-github-action@e815fd8a9dfede09fd6e6c144f2c9f4875e933df # tag=1.7.0
with:
mongodb-version: ${{ matrix.mongodb }}
mongodb-db: encryptionAPI
- name: Start the app
run: npm start > /dev/null &
- name: Run Postman Newman
run: node_modules/.bin/newman run https://api.getpostman.com/collections/${{ secrets.POSTMAN_COLLECTION }}?apikey=${{ secrets.POSTMAN_API_TOKEN }} -e https://api.getpostman.com/environments/${{ secrets.POSTMAN_ENVIRONMENT }}?apikey=${{ secrets.POSTMAN_API_TOKEN }}
# -- ZAP Scan ---------------------------------------------------------------
api-security:
name: API Security
runs-on: ubuntu-latest
needs: tests
# Skip any PR created by dependabot to avoid permission issues
if: (github.actor != 'dependabot[bot]')
strategy:
matrix:
node: ['18']
mongodb: ['5.0']
steps:
- name: Harden GitHub Actions Runner
uses: step-security/harden-runner@2579b52abd08b0a4c3ad0e4476ddb0f2036e3b67
with:
egress-policy: block
allowed-endpoints: >
api.github.com:443
auth.docker.io:443
bit.ly:443
cfu.zaproxy.org:443
content-signature-2.cdn.mozilla.net:443
docker.io:443
firefox.settings.services.mozilla.com:443
github.com:443
location.services.mozilla.com:443
news.zaproxy.org:443
objects.githubusercontent.com:443
pipelines.actions.githubusercontent.com:443
production.cloudflare.docker.com:443
raw.githubusercontent.com:443
registry-1.docker.io:443
registry.npmjs.org:443
shavar.services.mozilla.com:443
snyk.io:443
tel.zaproxy.org:443
tracking-protection.cdn.mozilla.net:443
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: ${{ matrix.node }}
check-latest: true
- name: Install dependencies
run: npm install
- name: Start MongoDB
uses: supercharge/mongodb-github-action@e815fd8a9dfede09fd6e6c144f2c9f4875e933df # tag=1.7.0
with:
mongodb-version: ${{ matrix.mongodb }}
mongodb-db: encryptionAPI
- name: Start the app
run: npm start > /dev/null &
- name: Run ZAP API Scan
uses: zaproxy/action-api-scan@d7eab41e224d7427459ca0a3b7523ba7b98f3ccc # v0.3.1
with:
target: http://localhost:3000/swagger/json
format: openapi
# -- PRE-RELEASE ------------------------------------------------------------
pre-release:
name: Prepare Release
runs-on: ubuntu-latest
needs:
- code-quality
- code-security
- api-security
- api-tests
if: github.ref == 'refs/heads/master'
steps:
- name: Harden GitHub Actions Runner
uses: step-security/harden-runner@2579b52abd08b0a4c3ad0e4476ddb0f2036e3b67
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Semantic Release
uses: cycjimmy/semantic-release-action@8e58d20d0f6c8773181f43eb74d6a05e3099571d # v3.4.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# -- BUILD ------------------------------------------------------------------
build:
name: Build & Release
runs-on: ubuntu-latest
needs: pre-release
if: github.ref == 'refs/heads/master'
steps:
- name: Harden GitHub Actions Runner
uses: step-security/harden-runner@2579b52abd08b0a4c3ad0e4476ddb0f2036e3b67
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Docker meta
id: meta
uses: docker/metadata-action@818d4b7b91585d195f67373fd9cb0332e31a7175 # v4.6.0
with:
images: ${{ github.repository }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
type=raw,value=latest
- name: Set up QEMU
uses: docker/setup-qemu-action@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 # v2.2.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1 # v2.9.1
- name: Login to DockerHub
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}