-
Notifications
You must be signed in to change notification settings - Fork 8
550 lines (467 loc) · 18.9 KB
/
on-prerelease.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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
# SPDX-License-Identifier: Apache-2.0
# Licensed to the Ed-Fi Alliance under one or more agreements.
# The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
# See the LICENSE and NOTICES files in the project root for more information.
name: On Pre-Release for DMS and Config Service
on:
release:
types:
- prereleased
env:
ARTIFACTS_API_KEY: ${{ secrets.AZURE_ARTIFACTS_PERSONAL_ACCESS_TOKEN }}
ARTIFACTS_FEED_URL: "https://pkgs.dev.azure.com/ed-fi-alliance/Ed-Fi-Alliance-OSS/_packaging/EdFi/nuget/v3/index.json"
VSS_NUGET_EXTERNAL_FEED_ENDPOINTS: '{"endpointCredentials": [{"endpoint": "https://pkgs.dev.azure.com/ed-fi-alliance/Ed-Fi-Alliance-OSS/_packaging/EdFi/nuget/v3/index.json","password": "${{ secrets.AZURE_ARTIFACTS_PERSONAL_ACCESS_TOKEN }}"}]}'
MANIFEST_FILE: "_manifest/spdx_2.2/manifest.spdx.json"
DMS_PACKAGE_NAME: "EdFi.DataManagementService"
CS_PACKAGE_NAME: "EdFi.DmsConfigurationService"
IMAGE_NAME: ${{ vars.IMAGE_NAME }}
CONFIG_IMAGE_NAME: "edfialliance/dms-configuration-service"
DOCKER_USERNAME: ${{ vars.DOCKER_USERNAME }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
REF: ${{ github.ref_name }}
permissions: read-all
jobs:
# jobs for DMS
pack-dms:
name: Build and Pack DMS
if: startsWith(github.event.release.tag_name, 'dms-')
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
outputs:
hash-code: ${{ steps.hash-code.outputs.hash-code }}
dms-version: ${{ steps.versions.outputs.dms-v }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0
- name: Set DMS Version Numbers
id: versions
run: |
Import-Module ./package-helpers.psm1
Get-VersionNumber -projectPrefix "dms"
- name: Publish DMS .NET Assemblies
run: |
$packageVersion = "${{ steps.versions.outputs.dms-semver }}" -replace "dms-v", ""
./build-dms.ps1 -Command BuildAndPublish `
-Configuration Release `
-DMSVersion $packageVersion
- name: Create DMS NuGet Package
run: |
$packageVersion = "${{ steps.versions.outputs.dms-semver }}" -replace "dms-v", ""
./build-dms.ps1 -Command Package `
-DMSVersion $packageVersion `
-Configuration Release
- name: Generate DMS hash for NuGet package
id: hash-code
run: |
"hash-code=$(sha256sum *.nupkg | base64 -w0)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
- name: Upload DMS Packages as Artifacts
if: success()
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
with:
name: "${{ env.DMS_PACKAGE_NAME }}-NuGet"
path: ${{ github.workspace }}/*.nupkg
if-no-files-found: error
retention-days: 30
sbom-create-dms:
name: Create DMS SBOM
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
needs: pack-dms
permissions:
actions: read
contents: write
outputs:
sbom-hash-code: ${{ steps.sbom-hash-code.outputs.sbom-hash-code }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Get DMS Artifacts
uses: actions/download-artifact@6b208ae046db98c579e8a3aa621ab581ff575935 #v4.1.1
with:
name: ${{ env.DMS_PACKAGE_NAME }}-NuGet
- name: Generate DMS Software Bill of Materials (SBOM)
run: |
$packageName = "${{ env.DMS_PACKAGE_NAME }}"
$version = "${{ needs.pack-dms.outputs.dms-version }}"
Get-ChildItem -Include "$packageName.*.nupkg" -Recurse | ForEach-Object { $_.FullName } > buildfilelist.txt
dotnet tool install --global Microsoft.Sbom.DotNetTool
sbom-tool generate `
-b ./ `
-bl ./buildfilelist.txt `
-bc "./" `
-pn "$packageName" `
-pv $version `
-nsb https://ed-fi.org `
-m ./ `
-ps "Ed-Fi Alliance"
cp _manifest/spdx_2.2/manifest.spdx.* .
- name: Upload DMS SBOM
if: success()
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
with:
name: ${{ env.DMS_PACKAGE_NAME }}-SBOM
path: ${{ env.MANIFEST_FILE }}
if-no-files-found: error
retention-days: 30
- name: Generate DMS hash code for SBOM
id: sbom-hash-code
shell: bash
run: |
# sha256sum returns "<hashcode> <name of file". Split that and return only the <hashcode>.
sbom_hash=$(sha256sum ./${{ env.MANIFEST_FILE }} | awk '{split($0,a); print a[1]}')
echo "sbom-hash-code=$sbom_hash" >> $GITHUB_OUTPUT
sbom-attach-dms:
name: Attach DMS SBOM file
runs-on: ubuntu-latest
needs:
- sbom-create-dms
- pack-dms
permissions:
actions: read
contents: write
steps:
- name: Download DMS SBOM
uses: Ed-Fi-Alliance-OSS/slsa-github-generator/.github/actions/[email protected]
with:
name: "${{ env.DMS_PACKAGE_NAME }}-SBOM"
path: ${{ env.MANIFEST_FILE }}
sha256: "${{ needs.sbom-create-dms.outputs.sbom-hash-code }}"
- name: Attach DMS to release
shell: pwsh
run: |
$release = "${{ github.ref_name }}"
$repo = "${{ github.repository }}"
$token = "${{ secrets.GITHUB_TOKEN }}"
$file = "${{ env.MANIFEST_FILE }}"
$uploadName = "${{ env.DMS_PACKAGE_NAME }}-SBOM.zip"
$url = "https://api.github.com/repos/$repo/releases/tags/$release"
$gh_headers = @{
"Accept" = "application/vnd.github+json"
"Authorization" = "Bearer $token"
}
$response = Invoke-RestMethod -Uri $url -Headers $gh_headers
$releaseId = $response.id
$url = "https://uploads.github.com/repos/$repo/releases/$releaseId/assets"
Compress-Archive $file -DestinationPath $uploadName
$gh_headers["Content-Type"] = "application/octet"
Invoke-RestMethod -Method POST `
-Uri "$($url)?name=$($uploadName)" `
-Headers $gh_headers `
-InFile $uploadName
provenance-create-dms:
name: Create DMS Provenance
needs: pack-dms
permissions:
actions: read
id-token: write
contents: write
uses: Ed-Fi-Alliance-OSS/slsa-github-generator/.github/workflows/[email protected]
with:
base64-subjects: ${{ needs.pack-dms.outputs.hash-code }}
provenance-name: dmsApi.intoto.jsonl
upload-assets: true
# TODO: remove this after this issue is resolved: https://github.com/slsa-framework/slsa-github-generator/issues/876
compile-generator: true
publish-package-dms:
name: Publish DMS NuGet Package
needs: pack-dms
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Get DMS Artifact
uses: actions/download-artifact@6b208ae046db98c579e8a3aa621ab581ff575935 #4.1.1
with:
name: ${{ env.DMS_PACKAGE_NAME }}-NuGet
- name: Install-credential-handler DMS
run: iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) } -AddNetfx"
- name: Push DMS Package to Azure Artifacts
run: |
$artifact = (Get-ChildItem -Path $_ -Name -Include *.nupkg)
$arguments = @{
EdFiNuGetFeed = "${{ env.ARTIFACTS_FEED_URL }}"
NuGetApiKey = "${{ env.ARTIFACTS_API_KEY }}"
}
$artifact | ForEach-Object {
$arguments.PackageFile = $_
./build-dms.ps1 Push @arguments
}
docker-publish-dms:
name: Publish DMS to Docker Hub
runs-on: ubuntu-latest
needs:
- publish-package-dms
steps:
- name: Wait 20s
# Give Azure Artifacts caching a moment to catch up
run: sleep 20
- name: Prepare DMS Tags
id: prepare-tags
run: |
REF="${{ env.REF }}"
PACKAGEVERSION=${REF}
if [[ $PACKAGEVERSION =~ "alpha" ]]
then
# Pre-releases get the tag "pre"
DMSTAGS="${{ env.IMAGE_NAME }}:pre"
else
# Releases get the version, plus shortened form for minor release.
# We are not using shortened form for major or using "latest"
# because they are too imprecise.
MINOR=`echo ${PACKAGEVERSION} | awk -F"." '{print $1"."$2}'`
DMSTAGS="${{ env.IMAGE_NAME }}:${PACKAGEVERSION},${{ env.IMAGE_NAME }}:${MINOR}"
fi
SEMVERSION=${PACKAGEVERSION:8} # strip off the leading 'dms-pre-'
echo "DMSTAGS=$DMSTAGS" >> $GITHUB_OUTPUT
echo "VERSION=$SEMVERSION" >> $GITHUB_OUTPUT
- name: Set up DMS Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
- name: Log in to Docker Hub for DMS
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_HUB_TOKEN }}
- name: Extract metadata (tags, labels) for Data Management Service image
id: metadatamanagementservice
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.IMAGE_NAME }}
- name: Build and push DMS image
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: "{{defaultContext}}:src/dms"
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:pre
cache-to: type=inline
build-args: VERSION=${{ steps.prepare-tags.outputs.VERSION }}
file: Nuget.Dockerfile
tags: ${{ steps.prepare-tags.outputs.DMSTAGS }}
labels: ${{ steps.metadatamanagementservice.outputs.labels }}
push: true
# jobs for Config
pack-cs:
name: Build and Pack Config
if: startsWith(github.event.release.tag_name, 'cs-')
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
outputs:
hash-code: ${{ steps.hash-code.outputs.hash-code }}
dms-version: ${{ steps.versions.outputs.dms-v }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0
- name: Set Config Version Numbers
id: versions
run: |
Import-Module ./package-helpers.psm1
Get-VersionNumber -projectPrefix "cs"
- name: Publish Config .NET Assemblies
run: |
$packageVersion = "${{ steps.versions.outputs.dms-semver }}" -replace "cs-v", ""
./build-config.ps1 -Command BuildAndPublish `
-Configuration Release `
-DmsCSVersion $packageVersion
- name: Create Config NuGet Package
run: |
$packageVersion = "${{ steps.versions.outputs.dms-semver }}" -replace "cs-v", ""
./build-config.ps1 -Command Package `
-DmsCSVersion $packageVersion `
-Configuration Release
- name: Generate Config hash for NuGet package
id: hash-code
run: |
"hash-code=$(sha256sum *.nupkg | base64 -w0)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
- name: Upload Config Packages as Artifacts
if: success()
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
with:
name: "${{ env.CS_PACKAGE_NAME }}-NuGet"
path: ${{ github.workspace }}/*.nupkg
if-no-files-found: error
retention-days: 30
sbom-create-cs:
name: Create Config SBOM
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
needs: pack-cs
permissions:
actions: read
contents: write
outputs:
sbom-hash-code: ${{ steps.sbom-hash-code.outputs.sbom-hash-code }}
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Get Config Artifacts
uses: actions/download-artifact@6b208ae046db98c579e8a3aa621ab581ff575935 #v4.1.1
with:
name: ${{ env.CS_PACKAGE_NAME }}-NuGet
- name: Generate Config Software Bill of Materials (SBOM)
run: |
$packageName = "${{ env.CS_PACKAGE_NAME }}"
$version = "${{ needs.pack-cs.outputs.dms-version }}"
Get-ChildItem -Include "$packageName.*.nupkg" -Recurse | ForEach-Object { $_.FullName } > buildfilelist.txt
dotnet tool install --global Microsoft.Sbom.DotNetTool
sbom-tool generate `
-b ./ `
-bl ./buildfilelist.txt `
-bc "./" `
-pn "$packageName" `
-pv $version `
-nsb https://ed-fi.org `
-m ./ `
-ps "Ed-Fi Alliance"
cp _manifest/spdx_2.2/manifest.spdx.* .
- name: Upload Config SBOM
if: success()
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
with:
name: ${{ env.CS_PACKAGE_NAME }}-SBOM
path: ${{ env.MANIFEST_FILE }}
if-no-files-found: error
retention-days: 30
- name: Generate Config hash code for SBOM
id: sbom-hash-code
shell: bash
run: |
# sha256sum returns "<hashcode> <name of file". Split that and return only the <hashcode>.
sbom_hash=$(sha256sum ./${{ env.MANIFEST_FILE }} | awk '{split($0,a); print a[1]}')
echo "sbom-hash-code=$sbom_hash" >> $GITHUB_OUTPUT
sbom-attach-cs:
name: Attach Config SBOM file
runs-on: ubuntu-latest
needs:
- sbom-create-cs
- pack-cs
permissions:
actions: read
contents: write
steps:
- name: Download Config SBOM
uses: Ed-Fi-Alliance-OSS/slsa-github-generator/.github/actions/[email protected]
with:
name: "${{ env.CS_PACKAGE_NAME }}-SBOM"
path: ${{ env.MANIFEST_FILE }}
sha256: "${{ needs.sbom-create-cs.outputs.sbom-hash-code }}"
- name: Attach Config to release
shell: pwsh
run: |
$release = "${{ github.ref_name }}"
$repo = "${{ github.repository }}"
$token = "${{ secrets.GITHUB_TOKEN }}"
$file = "${{ env.MANIFEST_FILE }}"
$uploadName = "${{ env.CS_PACKAGE_NAME }}-SBOM.zip"
$url = "https://api.github.com/repos/$repo/releases/tags/$release"
$gh_headers = @{
"Accept" = "application/vnd.github+json"
"Authorization" = "Bearer $token"
}
$response = Invoke-RestMethod -Uri $url -Headers $gh_headers
$releaseId = $response.id
$url = "https://uploads.github.com/repos/$repo/releases/$releaseId/assets"
Compress-Archive $file -DestinationPath $uploadName
$gh_headers["Content-Type"] = "application/octet"
Invoke-RestMethod -Method POST `
-Uri "$($url)?name=$($uploadName)" `
-Headers $gh_headers `
-InFile $uploadName
provenance-create-cs:
name: Create Config Provenance
needs: pack-cs
permissions:
actions: read
id-token: write
contents: write
uses: Ed-Fi-Alliance-OSS/slsa-github-generator/.github/workflows/[email protected]
with:
base64-subjects: ${{ needs.pack-cs.outputs.hash-code }}
provenance-name: dmsCSApi.intoto.jsonl
upload-assets: true
# TODO: remove this after this issue is resolved: https://github.com/slsa-framework/slsa-github-generator/issues/876
compile-generator: true
publish-package-cs:
name: Publish Config NuGet Package
needs: pack-cs
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Get Config Artifact
uses: actions/download-artifact@6b208ae046db98c579e8a3aa621ab581ff575935 #4.1.1
with:
name: ${{ env.CS_PACKAGE_NAME }}-NuGet
- name: Install-credential-handler Config
run: iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) } -AddNetfx"
- name: Push Config Package to Azure Artifacts
run: |
$artifact = (Get-ChildItem -Path $_ -Name -Include *.nupkg)
$arguments = @{
EdFiNuGetFeed = "${{ env.ARTIFACTS_FEED_URL }}"
NuGetApiKey = "${{ env.ARTIFACTS_API_KEY }}"
}
$artifact | ForEach-Object {
$arguments.PackageFile = $_
./build-config.ps1 Push @arguments
}
docker-publish-cs:
name: Publish Config to Docker Hub
runs-on: ubuntu-latest
needs:
- publish-package-cs
steps:
- name: Wait 20s
# Give Azure Artifacts caching a moment to catch up
run: sleep 20
- name: Prepare Config Tags
id: prepare-tags
run: |
REF="${{ env.REF }}"
PACKAGEVERSION=${REF}
if [[ $PACKAGEVERSION =~ "alpha" ]]
then
# Pre-releases get the tag "pre"
DMSTAGS="${{ env.CONFIG_IMAGE_NAME }}:pre"
else
# Releases get the version, plus shortened form for minor release.
# We are not using shortened form for major or using "latest"
# because they are too imprecise.
MINOR=`echo ${PACKAGEVERSION} | awk -F"." '{print $1"."$2}'`
DMSTAGS="${{ env.CONFIG_IMAGE_NAME }}:${PACKAGEVERSION},${{ env.CONFIG_IMAGE_NAME }}:${MINOR}"
fi
SEMVERSION=${PACKAGEVERSION:7} # strip off the leading 'cs-pre-'
echo "DMSTAGS=$DMSTAGS" >> $GITHUB_OUTPUT
echo "VERSION=$SEMVERSION" >> $GITHUB_OUTPUT
- name: Set up Config Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
- name: Log in to Docker Hub for Config
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_HUB_TOKEN }}
- name: Extract metadata (tags, labels) for Configuration Service image
id: metadatamanagementservice
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.CONFIG_IMAGE_NAME }}
- name: Build and push Config image
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: "{{defaultContext}}:src/config"
cache-from: type=registry,ref=${{ env.CONFIG_IMAGE_NAME }}:pre
cache-to: type=inline
build-args: VERSION=${{ steps.prepare-tags.outputs.VERSION }}
file: Nuget.Dockerfile
tags: ${{ steps.prepare-tags.outputs.DMSTAGS }}
labels: ${{ steps.metadatamanagementservice.outputs.labels }}
push: true