generated from Ed-Fi-Exchange-OSS/Template-for-GitHub
-
Notifications
You must be signed in to change notification settings - Fork 13
253 lines (224 loc) · 8.86 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
# 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
on:
release:
types:
- prereleased
env:
ARTIFACTS_API_KEY: ${{ secrets.AZURE_ARTIFACTS_PERSONAL_ACCESS_TOKEN }}
GITHUB_TOKEN: ${{ secrets.PAT_ATTACH_TO_RELEASE }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
DOCKER_USERNAME: ${{ vars.DOCKER_USERNAME }}
REF: ${{ github.ref_name }}
IMAGE_NAME: ${{ vars.MEADOWLARK_IMAGE_NAME }}
NPM_REGISTRY: ${{ vars.NPM_REGISTRY }}
jobs:
azure-publish:
name: Publish to Azure Artifacts
runs-on: ubuntu-latest
defaults:
run:
working-directory: Meadowlark-js
outputs:
hash-code: ${{ steps.hash-code.outputs.hash-code }}
steps:
- name: Checkout repository
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
with:
# Need full Git history for calculating the version number
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@8c91899e586c5b171469028077307d293428b516 # v3.5.1
with:
node-version: "18"
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- name: Install dependencies
if: ${{ steps.modules-cache.outputs.cache-hit != 'true' }}
run: npm ci
- name: Update version to match tag
working-directory: eng/version
run: |
npm ci --omit dev
node ./set.js ${{ env.REF }}
- name: Transpile to JS
run: npm run build --workspaces
- name: Create packages
# Explicit step is not required for publishing, but it allows us to upload artifacts
run: npm pack --workspaces
- name: Create .npmrc for Azure Artifacts publishing
run: |
echo "Configuring .npmrc for ${{ env.NPM_REGISTRY }}"
set +x # disable echo to shell so that the base64-encoded API key never escapes into the log.
# Create the user .npmrc file with proper settings
API_KEY=`echo -n "${{ env.ARTIFACTS_API_KEY }}" | base64`
touch $HOME/.npmrc
echo "; begin auth token" >> $HOME/.npmrc
echo ${{ env.NPM_REGISTRY }}:username=ed-fi-alliance >> $HOME/.npmrc
echo ${{ env.NPM_REGISTRY }}:_password=$API_KEY >> $HOME/.npmrc
echo ${{ env.NPM_REGISTRY }}:[email protected] >> $HOME/.npmrc
echo "; end auth token" >> $HOME/.npmrc
- name: Publish
run: npm publish --workspaces --tag dev
# NOTE: there are uncommitted version number changes in package.json. No
# problem! Our strategy is to rely on the tag history for version numbers,
# not on package.json.
- name: Generate hash codes for npm tarballs
id: hash-code
shell: bash
run: |
echo "hash-code=$(sha256sum *.tgz | base64 -w0)" >> $GITHUB_OUTPUT
- name: Upload packages as artifacts
if: success()
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: npm
path: Meadowlark-js/*.tgz
if-no-files-found: error
retention-days: 30
docker-publish:
name: Publish to Docker Hub
runs-on: ubuntu-latest
needs:
- azure-publish
steps:
- name: Wait 20s
# Give Azure Artifacts caching a moment to catch up
run: sleep 20
- name: Prepare Tags
id: prepare-tags
run: |
BASE="${{ env.IMAGE_NAME }}"
REF="${{ env.REF }}"
NPM_VERSION=${REF:1} # strip off the leading 'v'
if [[ $REF =~ "pre" ]]
then
# Pre-releases get the version and the tag "pre"
TAGS="${{ env.IMAGE_NAME }}:${REF},${{ 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 ${REF} | awk -F"." '{print $1"."$2}'`
TAGS="${{ env.IMAGE_NAME }}:${REF},${{ env.IMAGE_NAME }}:${MINOR}"
fi
echo "TAGS=$TAGS" >> $GITHUB_OUTPUT
echo "NPM_VERSION=$NPM_VERSION" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4b4e9c3e2d4531116a6f8ba8e71fc6e2cb6e6c8c # v2.5.0
- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ env.DOCKER_HUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 # v4.3.0
with:
images: ${{ env.IMAGE_NAME }}
- name: Build and push
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 # v4.0.0
with:
context: "{{defaultContext}}:docker"
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:pre
cache-to: type=inline
build-args: ML_VERSION=${{ steps.prepare-tags.outputs.NPM_VERSION }}
file: Dockerfile
tags: ${{ steps.prepare-tags.outputs.TAGS }}
labels: ${{ steps.meta.outputs.labels }}
push: true
sbom-create:
name: Create SBOM for NPM Packages
runs-on: ubuntu-latest
needs: azure-publish
permissions:
actions: read
contents: write
outputs:
sbom-hash-code: ${{ steps.sbom-hash-code.outputs.sbom-hash-code }}
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
- name: Get Artifacts
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a #v3.0.2
with:
name: npm
- name: Generate Software Bill of Materials (SBOM) - API
shell: pwsh
run: |
$url = "https://github.com/microsoft/sbom-tool/releases/latest/download/sbom-tool-linux-x64"
$out = "$($env:RUNNER_TEMP)/sbom-tool"
Invoke-RestMethod -Uri $url -OutFile $out
chmod +x $out
New-Item -Path sbom -Type Directory
&$out generate `
-b . `
-pn "Ed-Fi-Meadowlark" `
-pv ${{ env.REF }} `
-nsb https://ed-fi.org `
-m sbom `
-ps "Ed-Fi Alliance"
- name: Upload SBOM
if: success()
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: meadowlark-SBOM
path: ./sbom
if-no-files-found: error
retention-days: 30
- name: Store hash code for SBOM
id: sbom-hash-code
shell: bash
run: |
echo sbom-hash-code=$(sha256sum ./sbom/_manifest/spdx_2.2/manifest.spdx.json | awk '{split($0,a); print a[1]}') >> $GITHUB_OUTPUT
sbom-attach:
name: Attach SBOM file
runs-on: ubuntu-latest
needs:
- sbom-create
permissions:
actions: read
contents: write
steps:
- name: Download the SBOM
uses: slsa-framework/slsa-github-generator/.github/actions/secure-download-artifact@7f4fdb871876c23e455853d694197440c5a91506 #v1.5.0
with:
name: meadowlark-SBOM
path: _manifest/spdx_2.2/manifest.spdx.json
sha256: "${{ needs.sbom-create.outputs.sbom-hash-code }}"
- name: Attach to release
shell: pwsh
run: |
$release = "${{ env.REF }}"
$repo = "${{ github.repository }}"
$token = "${{ secrets.GITHUB_TOKEN }}"
$file = "_manifest/spdx_2.2/manifest.spdx.json"
$uploadName = "meadowlark-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:
name: Create Provenance
needs: azure-publish
permissions:
actions: read
id-token: write
contents: write
uses: Ed-Fi-Alliance-OSS/slsa-github-generator/.github/workflows/[email protected]
with:
base64-subjects: ${{ needs.azure-publish.outputs.hash-code }}
provenance-name: meadowlark.intoto.jsonl
upload-assets: true