generated from Ed-Fi-Exchange-OSS/Template-for-GitHub
-
Notifications
You must be signed in to change notification settings - Fork 13
346 lines (296 loc) · 11.5 KB
/
on-pullrequest.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
name: On Pull Request
on:
push:
branches:
- main
pull_request:
branches:
- main
paths:
- "Meadowlark-js/**"
- "Meadowlark.net/**"
- ".github/**"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: abcdefgh1!
defaults:
run:
working-directory: Meadowlark-js
jobs:
scan-actions:
name: Scan Actions
uses: ed-fi-alliance-oss/ed-fi-actions/.github/workflows/repository-scanner.yml@main
upgrade:
name: Upgrade packages
runs-on: ubuntu-latest
defaults:
run:
working-directory: Meadowlark-js
permissions:
contents: write
steps:
- name: Checkout the Repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0w
- name: Get version changes
id: versions
run: |
if [ ${{ github.event_name }} == 'pull_request' ]; then
suggested=v$(cat lerna.json | jq -r .version)
current=$(git describe --tags $(git rev-list --tags --max-count=1))
echo "Versions: Lerna: $suggested. Current: $current"
echo "update-required=$([[ "$suggested" == "$current" ]] && echo true)" >>$GITHUB_OUTPUT
fi
- name: Update versions
if: steps.versions.outputs.update-required
run: npx lerna version prerelease --exact --no-git-tag-version --preid pre --yes
- name: Set Version
if: steps.versions.outputs.update-required
id: set-version
run: |
version=v$(cat lerna.json | jq -r .version)
echo "version=$version" >> "$GITHUB_OUTPUT"
- uses: planetscale/ghcommit-action@4131649dbf2fdf1eb34421702972a5af7b0a8731 #v0.1.18
if: steps.versions.outputs.update-required
with:
commit_message: "${{steps.set-version.outputs.version}}"
repo: ${{ github.repository }}
branch: ${{ github.head_ref || github.ref_name }}
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
analyze-dependencies:
# This Action will fail if run on anything other than a pull request
if: github.event_name == 'pull_request'
name: Analyze Code Dependencies
# Not mandatory, but better for this to go after the upgrade since it can change the code.
needs: upgrade
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Dependency Review ("Dependabot on PR")
uses: actions/dependency-review-action@c090f4e553673e6e505ea70d6a95362ee12adb94 # v3.0.3
analyze-code:
name: Analyze Code
# Not mandatory, but better for this to go after the upgrade since it can change the code.
needs: upgrade
runs-on: ubuntu-latest
env:
SRC_DIR: Meadowlark-js
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Node
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
with:
node-version: "18"
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- name: Node modules cache
id: modules-cache
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 #v3.3.2
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
if: ${{ steps.modules-cache.outputs.cache-hit != 'true' }}
run: npm install
- name: Initialize CodeQL
uses: github/codeql-action/init@df32e399139a3050671466d7d9b3cbacc1cfd034 # v2.15.2
with:
languages: "typescript"
setup-python-dependencies: false
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@df32e399139a3050671466d7d9b3cbacc1cfd034 # v2.15.2
lint:
name: Lint
needs: upgrade
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Node
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
with:
node-version: "18"
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- name: Node modules cache
id: modules-cache
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 #v3.3.2
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
if: steps.modules-cache.outputs.cache-hit != 'true'
run: npm install
- name: Linter
run: npm run test:lint
build:
name: Build
needs: lint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Node
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
with:
node-version: "18"
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- name: Node modules cache
id: modules-cache
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 #v3.3.2
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
if: steps.modules-cache.outputs.cache-hit != 'true'
run: npm install
- name: Build
run: npm run build
tests:
name: ${{matrix.tests.type}} tests
needs: lint
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
tests:
[
{ type: "Unit", command: "npm run test:unit:coverage:ci" },
{
type: "Integration",
command: "npm run test:integration -- --ci",
},
]
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Node
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
with:
node-version: "18"
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- name: Load MongoDB binary cache
if: matrix.tests.type != 'Unit'
id: cache-mongodb-binaries
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 #v3.3.2
with:
path: ~/.cache/mongodb-binaries
key: ${{ runner.os }}-mongo-${{ hashFiles('**/package-lock.json') }}
- name: Node modules cache
id: modules-cache
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 #v3.3.2
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
if: steps.modules-cache.outputs.cache-hit != 'true'
run: npm install
- name: Jest cache
id: cache-jest
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 #v3.3.2
with:
path: /tmp/jest_rt
key: ${{ runner.os }}-jest-${{ hashFiles('**/package-lock.json') }}
- name: Configure postgres
if: matrix.tests.type != 'Unit'
run: |
sudo systemctl start postgresql.service
sudo -u postgres psql -U postgres -c "alter user postgres with password '${{env.POSTGRES_PASSWORD}}';"
- name: Create .env file
if: matrix.tests.type != 'Unit'
run: |
# Create a .env file with proper settings
touch .env
echo POSTGRES_USER=${{ env.POSTGRES_PASSWORD }} >> .env
echo POSTGRES_PASSWORD=${{ env.POSTGRES_USER }} >> .env
echo POSTGRES_HOST=localhost >> .env
echo POSTGRES_PORT=5432 >> .env
echo MEADOWLARK_DATABASE_NAME=postgres >> .env
# The actual values below don't matter for integration tests - but _something_ must be set
echo AUTHORIZATION_STORE_PLUGIN=@edfi/meadowlark-mongodb-backend >> .env
echo DOCUMENT_STORE_PLUGIN=@edfi/meadowlark-mongodb-backend >> .env
echo OWN_OAUTH_CLIENT_ID_FOR_CLIENT_AUTH=meadowlark_verify-only_key_1 >> .env
echo OWN_OAUTH_CLIENT_SECRET_FOR_CLIENT_AUTH=meadowlark_verify-only_secret_1 >> .env
echo OAUTH_SERVER_ENDPOINT_FOR_OWN_TOKEN_REQUEST=http://localhost:3000/local/oauth/token >> .env
echo OAUTH_SERVER_ENDPOINT_FOR_TOKEN_VERIFICATION=http://localhost:3000/local/oauth/verify >> .env
echo OAUTH_SIGNING_KEY="$( openssl rand -base64 256 | tr -d '\n' )" >> .env
- name: Run ${{matrix.tests.type}} Tests
run: ${{matrix.tests.command}}
env:
JEST_JUNIT_OUTPUT_DIR: ${{matrix.tests.type}}-tests
- name: Archive coverage results
if: ${{ matrix.tests.type == 'Unit' }}
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: code-coverage-report
path: Meadowlark-js/coverage/lcov-report
retention-days: 10
end-to-end:
name: End to End tests for ${{ matrix.store.db }} as store and ${{matrix.query_handler.provider}} as query handler
needs: lint
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
store: [{ db: "Mongo", plugin: "@edfi/meadowlark-mongodb-backend" },
{ db: "PGSQL", plugin: "@edfi/meadowlark-postgresql-backend" }]
query_handler:
[
{ provider: "opensearch", plugin: "@edfi/meadowlark-opensearch-backend" },
{ provider: "elasticsearch", plugin: "@edfi/meadowlark-elasticsearch-backend" }
]
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Node
uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0
with:
node-version: "18"
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- name: Install required dependencies
run: npm install -D cross-env
- name: Jest cache
id: cache-jest
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 #v3.3.2
with:
path: /tmp/jest_rt
key: ${{ runner.os }}-jest-${{ hashFiles('**/package-lock.json') }}
- name: Create .env file
run: |
touch .env-e2e
echo OAUTH_SIGNING_KEY="$( openssl rand -base64 256 | tr -d '\n' )" >> .env-e2e
working-directory: Meadowlark-js/tests/e2e/setup/
- name: End to End tests for ${{matrix.store.db}} as store, ${{matrix.query_handler.provider}} as query handler
run: npm run test:e2e:build -- --ci
env:
AUTHORIZATION_STORE_PLUGIN: ${{ matrix.store.plugin }}
DOCUMENT_STORE_PLUGIN: ${{ matrix.store.plugin }}
QUERY_HANDLER_PLUGIN: ${{ matrix.query_handler.plugin }}
LISTENER1_PLUGIN: ${{ matrix.query_handler.plugin }}
- name: Docker logs
if: failure()
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: docker-logs
path: |
Meadowlark-js/tests/e2e/logs/
retention-days: 10