-
Notifications
You must be signed in to change notification settings - Fork 0
244 lines (222 loc) · 9.54 KB
/
ci.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
name: CI
on:
pull_request:
branches:
- main
- backport/*.*
paths:
- config/**
- spack.yaml
env:
SPACK_YAML_MODEL_YQ: .spack.spec[0]
jobs:
# There are a lot of interconnected jobs here. Here is a dependency diagram:
# validate-json ──> check-json ─────────┬─────────────────────────┐
# ├> notifier ├> prerelease-deploy
# check-spack-yaml ──> deploy-versions ─┼> update-prerelease-tag ─┤
# └─────────────────────────┘
# ---------------------
# | JSON-RELATED JOBS |
# ---------------------
validate-json:
name: Validate JSON
uses: access-nri/actions/.github/workflows/validate-json.yml@main
with:
src: "config"
check-json:
name: Check JSON Fields
needs:
- validate-json
runs-on: ubuntu-latest
outputs:
spack-packages-version: ${{ steps.versions.outputs.packages }}
spack-config-version: ${{ steps.versions.outputs.config }}
steps:
# The next two steps checkout the spack-{packages,config} repos to confirm that the versions in
# versions.json exist in the repositories.
- name: Setup
id: versions
run: |
echo "packages=$(jq --compact-output --raw-output '."spack-packages"' ./config/versions.json)" >> $GITHUB_OUTPUT
echo "config=$(jq --compact-output --raw-output '."spack-config"' ./config/versions.json)" >> $GITHUB_OUTPUT
- name: Spack Packages
id: spack-packages
continue-on-error: true
uses: actions/checkout@v4
with:
repository: access-nri/spack-packages
ref: ${{ steps.versions.outputs.packages }}
path: packages
- name: Spack Config
id: spack-config
continue-on-error: true
uses: actions/checkout@v4
with:
repository: access-nri/spack-config
ref: ${{ steps.versions.outputs.config }}
path: config
- name: Failure Notifier
if: contains(steps.*.outcome, 'failure')
run: |
if [[ "${{ steps.spack-packages.outcome }}" == "failure" ]]; then
echo "::error::spack-packages at the specified ref (${{ steps.versions.outputs.packages }}) doesn't exist."
fi
if [[ "${{ steps.spack-config.outcome }}" == "failure" ]]; then
echo "::error::spack-config at the specified ref (${{ steps.versions.outputs.config }}) doesn't exist."
fi
exit 1
# ---------------------------
# | SPACK.YAML-RELATED JOBS |
# ---------------------------
check-spack-yaml:
name: Check spack.yaml
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}
fetch-depth: 0
- name: Check Model Version Modified
id: version
run: |
base_version=$(yq e '${{ env.SPACK_YAML_MODEL_YQ }}' spack.yaml)
git checkout ${{ github.head_ref }}
current_version=$(yq e '${{ env.SPACK_YAML_MODEL_YQ }}' spack.yaml)
echo "current=${current_version}" >> $GITHUB_OUTPUT
if [[ "${base_version}" == "${current_version}" ]]; then
echo "::warning::The version string hasn't been modified in this PR, but needs to be before merging."
exit 1
fi
- name: Same Model Version Failure Notifier
if: failure() && steps.version.outcome == 'failure'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BODY: |
The model version in the `spack.yaml` has not been updated.
Either update it manually, or comment the following to have it updated and committed automatically:
* `!bump major` for feature releases
* `!bump minor` for bugfixes
run: |
gh pr checkout ${{ github.event.pull_request.number }}
gh pr comment --body '${{ env.BODY }}'
- name: Projection Version Matches
# this step checks that the versions of the packages themselves match with the
# names of the modules. For example, [email protected] matches with the
# modulefile mom5/2023.12.12 (specifically, the version strings match)
run: |
FAILED='false'
DEPS=$(yq ".spack.modules.default.tcl.include | join(\" \")" spack.yaml)
# for each of the packages (access-om2, mom5, cice5...)
for DEP in $DEPS; do
DEP_VER=''
if [[ "$DEP" == "access-om2" ]]; then
DEP_VER=$(yq ".spack.specs[]" spack.yaml | cut -c16-)
else
DEP_VER=$(yq ".spack.packages.\"$DEP\".require" spack.yaml | cut -c6-)
fi
MODULE_VER=$(yq ".spack.modules.default.tcl.projections.\"$DEP\"" spack.yaml | cut -c8-)
if [[ "$DEP_VER" != "$MODULE_VER" ]]; then
echo "::error::Version of dependency and projection do not match ($DEP_VER != $MODULE_VER)"
FAILED='true'
fi
done
if [[ "$FAILED" == "true" ]]; then
exit 1
fi
get-versions:
name: Get Version and Build Number
needs:
- check-spack-yaml
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version-name }}
version-build: ${{ steps.get-version-build.outputs.version-build-name }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Generate Version Number
id: get-version
# The step generates a general version number from the spack.yaml, looking the
# same as a regular release build.
# Ex. '[email protected]' -> '2024.01.1'
run: |
access-om2-package=$(yq e '${{ env.SPACK_YAML_MODEL_YQ }}' spack.yaml)
echo "version-name=${access-om2-package/*@git./}" >> $GITHUB_OUTPUT
- name: Generate Version-Build String
id: get-version-build
# This step generates the version number for prereleases,
# which looks like: `<version>-<number of commits on this branch>`.
# Ex. `2024.10.1` with 2 commits on branch -> `2024.10.1-2`.
run: |
number-of-commits=$(git rev-list --count ${{ github.event.pull_request.base.sha }}..HEAD)
echo "version-build-name=${{ steps.get-version.outputs.version-name }}-${number-of-commits}" >> $GITHUB_OUTPUT
update-prerelease-tag:
name: Update Prerelease Tag ${{ needs.get-versions.outputs.version }}
needs:
- get-versions
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Push
# NOTE: Regarding the config user.name/user.email, see https://github.com/actions/checkout/pull/1184
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git tag ${{ needs.get-versions.outputs.version }} --force
git push --tags --force
# -----------------------------
# | PRERELEASE DEPLOYMENT JOB |
# -----------------------------
prerelease-deploy:
name: Deploy to Prerelease
# This will create a `spack` environment with the name `access-om2-<version>-<commit number>`.
# For example, `access-om2-2024_01_1-3` for the deployment based on the third commit on the PR branch.
needs:
- get-versions # so we can give an appropriate version to the prerelease build
- update-prerelease-tag # implies all the spack.yaml-related checks have passed
- check-json # implies all the json-related checks have passed
runs-on: ubuntu-latest
steps:
- run: echo "Pretending to deploy prerelease with ref ${{ github.head_ref }} and version ${{ needs.get-versions.outputs.version-build }}"
# uses: access-nri/build-cd/.github/workflows/deploy-1-setup.yml@main
# with:
# type: prerelease
# ref: ${{ github.head_ref }}
# version: ${{ needs.get-versions.outputs.version-build }}
# secrets: inherit
notifier:
name: Notifier
runs-on: ubuntu-latest
needs:
- check-json
- get-versions
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Comment
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
BODY: |
This ${{ github.repository }} model will be deployed with the following versions:
* `${{ needs.get-versions.outputs.version }}` as a Release (when merged).
* `${{ needs.get-versions.outputs.version-build }}` as a Prerelease (during this PR).
It will be deployed using:
* `access-nri/spack-packages` version [`${{ needs.check-json.outputs.spack-packages-version }}`](https://github.com/ACCESS-NRI/spack-packages/releases/tag/${{ needs.check-json.outputs.spack-packages-version }})
* `access-nri/spack-config` version [`${{ needs.check-json.outputs.spack-config-version }}`](https://github.com/ACCESS-NRI/spack-config/releases/tag/${{ needs.check-json.outputs.spack-config-version }})
If this is not what was expected, commit changes to `config/versions.json`.
run: |
gh pr checkout ${{ github.event.pull_request.number }}
gh pr comment --body '${{ env.BODY }}'