-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (134 loc) · 6.13 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
name: CI
on:
pull_request:
branches:
- main
- backport/*.*
paths:
- config/**
- spack.yaml
env:
SPACK_YAML_MODEL_YQ: .spack.specs[0]
jobs:
validate-json:
name: Validate JSON
uses: access-nri/actions/.github/workflows/validate-json.yml@main
with:
src: "config"
check-config:
name: Check Config Fields
needs:
- validate-json
runs-on: ubuntu-latest
outputs:
spack-packages-version: ${{ steps.spack-packages.outputs.version }}
spack-config-version: ${{ steps.spack-config.outputs.version }}
steps:
- name: Validate spack-packages version
id: spack-packages
uses: access-nri/build-cd/.github/actions/validate-repo-version@main
with:
repo-to-check: spack-packages
- name: Validate spack-config version
id: spack-config
uses: access-nri/build-cd/.github/actions/validate-repo-version@main
with:
repo-to-check: spack-config
check-spack-yaml:
name: Check spack.yaml
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check Model Version Modified
id: version
run: |
git checkout ${{ github.base_ref }}
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'
uses: access-nri/actions/.github/actions/pr-comment@main
with:
comment: |
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
- name: More Checks
# FIXME: More spack.yaml checks specific to access-om3
run: echo "::warning::Stub for more access-om3 specific checks"
version-tag:
name: Get Version and Tag Prerelease
needs:
- check-spack-yaml
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
release: ${{ steps.version.outputs.release }}
prerelease: ${{ steps.version.outputs.prerelease }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Generate Versions
id: version
# This step generates the release and prerelease version numbers.
# The release is a general version number from the spack.yaml, looking the
# same as a regular release build. Ex. '[email protected]' -> '2024.01.1'
# The prerelease looks like: `pr<pull request number>-<number of commits on this branch>`.
# Ex. Pull Request #12 with 2 commits on branch -> `pr12-2`.
run: |
echo "release=$(yq '${{ env.SPACK_YAML_MODEL_YQ }} | split("@git.") | .[1]' spack.yaml)" >> $GITHUB_OUTPUT
number_of_commits=$(git rev-list --count ${{ github.event.pull_request.base.sha }}..HEAD)
echo "prerelease=pr${{ github.event.pull_request.number }}-${number_of_commits}" >> $GITHUB_OUTPUT
- name: Shift Prerelease Tag ${{ steps.version.outputs.release }}
# We shift the 'Release' tag along the PR as the spack.yaml will not work without the correct tag in this repostiory.
# NOTE: Regarding the config user.name/user.email, see https://github.com/actions/checkout/pull/1184
run: |
git config user.name ${{ vars.GH_ACTIONS_BOT_GIT_USER_NAME }}
git config user.email ${{ vars.GH_ACTIONS_BOT_GIT_USER_EMAIL }}
git tag ${{ steps.version.outputs.release }} --force
git push --tags --force
# -----------------------------
# | PRERELEASE DEPLOYMENT JOB |
# -----------------------------
prerelease-deploy:
name: Deploy to Prerelease
# This will create a `spack` environment with the name `access-om3-pr<pull request number>-<commit number>`.
# For example, `access-om3-pr13-3` for the deployment based on the third commit on the PR#13.
needs:
- version-tag # implies all the spack.yaml-related checks have passed, has appropriate version for the prerelease build
- check-config # implies all the json-related checks have passed
uses: access-nri/build-cd/.github/workflows/deploy-1-setup.yml@main
with:
type: prerelease
ref: ${{ github.head_ref }}
version: ${{ needs.version-tag.outputs.prerelease }}
secrets: inherit
notifier:
name: Notifier
needs:
- version-tag # implies all the spack.yaml-related checks have passed, has appropriate version for the prerelease build
- check-config # implies all the json-related checks have passed
permissions:
pull-requests: write
uses: access-nri/actions/.github/actions/pr-comment@main
with:
comment: |
This `${{ github.repository }}` model will be deployed with the following versions:
* `${{ needs.version-tag.outputs.release }}` as a Release (when merged).
* `${{ needs.version-tag.outputs.prerelease }}` as a Prerelease (during this PR). This can be accessed on `Gadi` via `spack` at `/g/data/vk83/prerelease/apps/spack/0.20/spack` once deployed.
It will be deployed using:
* `access-nri/spack-packages` version [`${{ needs.check-config.outputs.spack-packages-version }}`](https://github.com/ACCESS-NRI/spack-packages/releases/tag/${{ needs.check-config.outputs.spack-packages-version }})
* `access-nri/spack-config` version [`${{ needs.check-config.outputs.spack-config-version }}`](https://github.com/ACCESS-NRI/spack-config/releases/tag/${{ needs.check-config.outputs.spack-config-version }})
If this is not what was expected, commit changes to `config/versions.json`.