-
Notifications
You must be signed in to change notification settings - Fork 0
268 lines (242 loc) · 9.14 KB
/
cd.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
name: CD
run-name: ${{ inputs.model }} CD
# NOTE: This workflow requires:
# permissions.contents:write
# secrets:inherit with an appropriate GitHub Environment for deployment in the caller
on:
workflow_call:
inputs:
model:
type: string
required: true
description: The model that is being tested and deployed
root-sbd:
type: string
required: false
# default: The ${{ inputs.model }} above
description: |
The name of the root Spack Bundle Definition, if it is different from the model name.
This is often a package named similarly in ACCESS-NRI/spack-packages.
# Callers usually have the trigger:
# push:
# branches:
# - main
# - backport/*.*
# paths:
# - config/**
# - spack.yaml
env:
METADATA_PATH: /opt/metadata
OUTPUTS_PATH: /opt/outputs
jobs:
defaults:
name: Set Defaults
# Unfortunately, you can't set a dynamic default value based on `inputs` yet
runs-on: ubuntu-latest
outputs:
root-sbd: ${{ steps.root-sbd.outputs.default }}
targets: ${{ steps.target.outputs.valid-targets }}
steps:
- name: root-sbd
id: root-sbd
run: |
if [ -z "${{ inputs.root-sbd }}" ]; then
echo "default=${{ inputs.model }}" >> $GITHUB_OUTPUT
else
echo "default=${{ inputs.root-sbd }}" >> $GITHUB_OUTPUT
fi
- name: Generate Deployment Target Matrix
id: target
uses: access-nri/build-cd/.github/actions/get-target-matrix@v4
with:
targets: ${{ vars.RELEASE_DEPLOYMENT_TARGETS }}
verify-settings:
name: Verify Deployment Settings
runs-on: ubuntu-latest
needs:
- defaults
strategy:
matrix:
target: ${{ fromJson(needs.defaults.outputs.targets) }}
steps:
- uses: actions/checkout@v4
with:
repository: access-nri/build-cd
- uses: access-nri/build-cd/.github/actions/validate-deployment-settings@v4
with:
settings-path: ./config/settings.json
target: ${{ matrix.target }}
error-level: error
push-tag:
name: Tag Deployment
runs-on: ubuntu-latest
needs:
- verify-settings
permissions:
contents: write
outputs:
name: ${{ steps.tag.outputs.root-spec-ref }}
steps:
- uses: actions/checkout@v4
- name: Get root spec ref
id: tag
uses: access-nri/build-cd/.github/actions/get-spack-root-spec@v4
- name: Import Commit-Signing Key
uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 # v6.1.0
with:
gpg_private_key: ${{ secrets.GH_ACTIONS_BOT_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GH_ACTIONS_BOT_GPG_PASSPHRASE }}
git_config_global: true
git_committer_name: ${{ vars.GH_ACTIONS_BOT_GIT_USER_NAME }}
git_committer_email: ${{ vars.GH_ACTIONS_BOT_GIT_USER_EMAIL }}
git_user_signingkey: true
git_commit_gpgsign: true
git_tag_gpgsign: true
- name: Push Tag
env:
TAG: ${{ steps.tag.outputs.root-spec-ref }}
run: |
if [[ "${{ env.TAG }}" == "latest" ]]; then
echo "::error::The version 'latest' is reserved for a spack package that moves often and cannot be used as a release tag. Reset the 'main' or 'backport' branch, reopen the merged PR, and update the version."
exit 1
fi
git tag ${{ env.TAG }} -m "Deployment of ${{ inputs.model }} ${{ env.TAG }} via build-cd 'cd.yml' workflow"
git push --tags
deploy-release:
name: Deploy Release
needs:
- defaults
- push-tag
strategy:
matrix:
target: ${{ fromJson(needs.defaults.outputs.targets) }}
uses: access-nri/build-cd/.github/workflows/deploy-1-setup.yml@v4
with:
deployment-target: ${{ matrix.target }}
deployment-ref: ${{ github.ref_name }}
deployment-type: Release
deployment-version: ${{ needs.push-tag.outputs.name }}
spack-manifest-path: ./spack.yaml
spack-manifest-root-sbd: ${{ needs.defaults.outputs.root-sbd }}
secrets: inherit
permissions:
contents: write
# We require pull-requests:write despite not using it in this path,
# because it is needed by the pull_request invocation of the workflow.
pull-requests: write
release:
name: Create Release
needs:
- defaults
- push-tag
- deploy-release
runs-on: ubuntu-latest
env:
TEMPLATED_RELEASE_BODY_PATH: /opt/release-body.md
outputs:
url: ${{ steps.release.outputs.url }}
created-at: ${{ steps.metadata.outputs.created-at }}
steps:
- name: Checkout build-cd
uses: actions/checkout@v4
with:
repository: access-nri/build-cd
- name: Download Metadata Artifacts
uses: actions/download-artifact@v4
with:
pattern: ${{ needs.deploy-release.outputs.general-metadata-artifact-glob }}
path: ${{ env.METADATA_PATH }}
merge-multiple: true
- name: Download Outputs Artifacts
uses: actions/download-artifact@v4
with:
pattern: ${{ needs.deploy-release.outputs.general-outputs-artifact-glob }}
path: ${{ env.OUTPUTS_PATH }}
merge-multiple: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
cache: pip
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -q -q -r scripts/jinja_template/requirements.txt
- name: Generate Release Notes
id: release-body
env:
J2_MODEL: ${{ inputs.model }}
J2_VERSION: ${{ needs.push-tag.outputs.name }}
J2_ROOT_SBD: ${{ needs.defaults.outputs.root-sbd }}
run: |
python -m scripts.jinja_template.render_deployment_info \
--template scripts/jinja_template/templates/release-body.md.j2 \
--deployment-outputs ${{ env.OUTPUTS_PATH }} \
--output ${{ env.TEMPLATED_RELEASE_BODY_PATH }}
- name: Create Release
id: release
uses: softprops/action-gh-release@69320dbe05506a9a39fc8ae11030b214ec2d1f87 # v2.0.5
with:
tag_name: ${{ needs.push-tag.outputs.name }}
name: ${{ inputs.model}} ${{ needs.push-tag.outputs.name }}
body_path: ${{ env.TEMPLATED_RELEASE_BODY_PATH }}
generate_release_notes: true
fail_on_unmatched_files: true
files: |
${{ env.METADATA_PATH }}/*.spack.yaml
${{ env.METADATA_PATH }}/*.spack.lock
${{ env.METADATA_PATH }}/*.spack.location
${{ env.METADATA_PATH }}/*.spack.location.json
- name: Release Metadata
id: metadata
env:
GH_TOKEN: ${{ github.token }}
run: echo "created-at=$(gh release view --json createdAt --jq '.createdAt' --repo ${{ github.repository }})" >> $GITHUB_OUTPUT
# TODO: This will only upload data related to the Gadi deployment
build-db:
name: Build DB Metadata Upload
needs:
- defaults
- deploy-release
- release
runs-on: ubuntu-latest
steps:
- name: Download Metadata Artifact
uses: actions/download-artifact@v4
with:
pattern: ${{ needs.deploy-release.outputs.general-metadata-artifact-glob }}
path: ${{ env.METADATA_PATH }}
merge-multiple: true
- name: Download Outputs Artifact
uses: actions/download-artifact@v4
with:
pattern: ${{ needs.deploy-release.outputs.general-outputs-artifact-glob }}
path: ${{ env.OUTPUTS_PATH }}
merge-multiple: true
- name: 'Get Gadi spack-* Repo Versions'
id: spack-versions
run: |
echo "packages-version=$(jq --raw-output --compact-output '.spack_packages_version' ${{ env.OUTPUTS_PATH }}/deploy-outputs.Gadi)" >> $GITHUB_OUTPUT
echo "config-version=$(jq --raw-output --compact-output '.spack_config_version' ${{ env.OUTPUTS_PATH }}/deploy-outputs.Gadi)" >> $GITHUB_OUTPUT
- name: Checkout Upload Script
uses: actions/checkout@v4
with:
repository: access-nri/build-cd
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ vars.PYTHON_VERSION }}
cache: pip
- name: Install Build Metadata Script Requirements
run: pip install -r tools/release_provenance/requirements.txt
- name: Upload Build Metadata
env:
BUILD_DB_CONNECTION_STR: ${{ secrets.BUILD_DB_CONNECTION_STR }}
run: |
./scripts/generate-build-metadata.bash \
${{ needs.release.outputs.url }} ${{ needs.release.outputs.created-at }} \
${{ steps.spack-versions.outputs.packages-version }} ${{ steps.spack-versions.outputs.config-version }} \
${{ env.METADATA_PATH }} ${{ env.OUTPUTS_PATH }} \
${{ needs.defaults.outputs.root-sbd }} ${{ vars.BUILD_DB_PACKAGES }}
echo "Attempting upload of build_metadata.json"
python ./tools/release_provenance/save_release.py "${{ env.OUTPUTS_PATH }}/build_metadata.json"