Skip to content

Commit 54b0104

Browse files
committed
ci.yml: Fleshed out the workflow
1 parent 1fff63e commit 54b0104

File tree

1 file changed

+120
-33
lines changed

1 file changed

+120
-33
lines changed

.github/workflows/ci.yml

+120-33
Original file line numberDiff line numberDiff line change
@@ -7,57 +7,144 @@ on:
77
paths:
88
- config/**
99
- spack.yaml
10+
env:
11+
SPACK_YAML_MODEL_YQ: .spack.specs[0]
1012
jobs:
1113
validate-json:
1214
name: Validate JSON
1315
uses: access-nri/actions/.github/workflows/validate-json.yml@main
1416
with:
1517
src: "config"
1618

17-
check-json:
18-
name: Check JSON Fields
19+
check-config:
20+
name: Check Config Fields
1921
needs:
2022
- validate-json
2123
runs-on: ubuntu-latest
2224
outputs:
23-
spack-packages-version: ${{ steps.versions.outputs.packages }}
24-
spack-config-version: ${{ steps.versions.outputs.config }}
25+
spack-packages-version: ${{ steps.spack-packages.outputs.version }}
26+
spack-config-version: ${{ steps.spack-config.outputs.version }}
27+
steps:
28+
- name: Validate spack-packages version
29+
id: spack-packages
30+
uses: access-nri/build-cd/.github/actions/validate-repo-version@main
31+
with:
32+
repo-to-check: spack-packages
33+
34+
- name: Validate spack-config version
35+
id: spack-config
36+
uses: access-nri/build-cd/.github/actions/validate-repo-version@main
37+
with:
38+
repo-to-check: spack-config
39+
40+
check-spack-yaml:
41+
name: Check spack.yaml
42+
runs-on: ubuntu-latest
2543
steps:
2644
- uses: actions/checkout@v4
45+
with:
46+
fetch-depth: 0
2747

28-
# The next steps checkout the spack-{packages,config} repos to confirm that the versions in
29-
# versions.json exist in the repositories.
30-
- name: Setup
31-
id: versions
48+
- name: Check Model Version Modified
49+
id: version
3250
run: |
33-
echo "packages=$(jq --compact-output --raw-output '."spack-packages"' ./config/versions.json)" >> $GITHUB_OUTPUT
34-
echo "config=$(jq --compact-output --raw-output '."spack-config"' ./config/versions.json)" >> $GITHUB_OUTPUT
51+
git checkout ${{ github.base_ref }}
52+
base_version=$(yq e '${{ env.SPACK_YAML_MODEL_YQ }}' spack.yaml)
3553
36-
- name: Spack Packages
37-
id: spack-packages
38-
continue-on-error: true
39-
uses: actions/checkout@v4
54+
git checkout ${{ github.head_ref }}
55+
current_version=$(yq e '${{ env.SPACK_YAML_MODEL_YQ }}' spack.yaml)
56+
echo "current=${current_version}" >> $GITHUB_OUTPUT
57+
58+
if [[ "${base_version}" == "${current_version}" ]]; then
59+
echo "::warning::The version string hasn't been modified in this PR, but needs to be before merging."
60+
exit 1
61+
fi
62+
63+
- name: Same Model Version Failure Notifier
64+
if: failure() && steps.version.outcome == 'failure'
65+
uses: access-nri/actions/.github/actions/pr-comment@main
4066
with:
41-
repository: access-nri/spack-packages
42-
ref: ${{ steps.versions.outputs.packages }}
43-
path: packages
67+
comment: |
68+
The model version in the `spack.yaml` has not been updated.
69+
Either update it manually, or comment the following to have it updated and committed automatically:
70+
* `!bump major` for feature releases
71+
* `!bump minor` for bugfixes
4472
45-
- name: Spack Config
46-
id: spack-config
47-
continue-on-error: true
48-
uses: actions/checkout@v4
73+
- name: More Checks
74+
# FIXME: More spack.yaml checks specific to access-om3
75+
run: echo "::warning::Stub for more access-om3 specific checks"
76+
77+
version-tag:
78+
name: Get Version and Tag Prerelease
79+
needs:
80+
- check-spack-yaml
81+
runs-on: ubuntu-latest
82+
permissions:
83+
contents: write
84+
outputs:
85+
release: ${{ steps.version.outputs.release }}
86+
prerelease: ${{ steps.version.outputs.prerelease }}
87+
steps:
88+
- uses: actions/checkout@v4
4989
with:
50-
repository: access-nri/spack-config
51-
ref: ${{ steps.versions.outputs.config }}
52-
path: config
90+
ref: ${{ github.head_ref }}
91+
fetch-depth: 0
5392

54-
- name: Failure Notifier
55-
if: contains(steps.*.outcome, 'failure')
93+
- name: Generate Versions
94+
id: version
95+
# This step generates the release and prerelease version numbers.
96+
# The release is a general version number from the spack.yaml, looking the
97+
# same as a regular release build. Ex. '[email protected]' -> '2024.01.1'
98+
# The prerelease looks like: `pr<pull request number>-<number of commits on this branch>`.
99+
# Ex. Pull Request #12 with 2 commits on branch -> `pr12-2`.
56100
run: |
57-
if [[ "${{ steps.spack-packages.outcome }}" == "failure" ]]; then
58-
echo "::error::spack-packages at the specified ref (${{ steps.versions.outputs.packages }}) doesn't exist."
59-
fi
60-
if [[ "${{ steps.spack-config.outcome }}" == "failure" ]]; then
61-
echo "::error::spack-config at the specified ref (${{ steps.versions.outputs.config }}) doesn't exist."
62-
fi
63-
exit 1
101+
echo "release=$(yq '${{ env.SPACK_YAML_MODEL_YQ }} | split("@git.") | .[1]' spack.yaml)" >> $GITHUB_OUTPUT
102+
103+
number_of_commits=$(git rev-list --count ${{ github.event.pull_request.base.sha }}..HEAD)
104+
echo "prerelease=pr${{ github.event.pull_request.number }}-${number_of_commits}" >> $GITHUB_OUTPUT
105+
106+
- name: Shift Prerelease Tag ${{ steps.version.outputs.release }}
107+
# We shift the 'Release' tag along the PR as the spack.yaml will not work without the correct tag in this repostiory.
108+
# NOTE: Regarding the config user.name/user.email, see https://github.com/actions/checkout/pull/1184
109+
run: |
110+
git config user.name ${{ vars.GH_ACTIONS_BOT_GIT_USER_NAME }}
111+
git config user.email ${{ vars.GH_ACTIONS_BOT_GIT_USER_EMAIL }}
112+
git tag ${{ steps.version.outputs.release }} --force
113+
git push --tags --force
114+
115+
# -----------------------------
116+
# | PRERELEASE DEPLOYMENT JOB |
117+
# -----------------------------
118+
prerelease-deploy:
119+
name: Deploy to Prerelease
120+
# This will create a `spack` environment with the name `access-om3-pr<pull request number>-<commit number>`.
121+
# For example, `access-om3-pr13-3` for the deployment based on the third commit on the PR#13.
122+
needs:
123+
- version-tag # implies all the spack.yaml-related checks have passed, has appropriate version for the prerelease build
124+
- check-config # implies all the json-related checks have passed
125+
uses: access-nri/build-cd/.github/workflows/deploy-1-setup.yml@main
126+
with:
127+
type: prerelease
128+
ref: ${{ github.head_ref }}
129+
version: ${{ needs.version-tag.outputs.prerelease }}
130+
secrets: inherit
131+
132+
notifier:
133+
name: Notifier
134+
needs:
135+
- version-tag # implies all the spack.yaml-related checks have passed, has appropriate version for the prerelease build
136+
- check-config # implies all the json-related checks have passed
137+
permissions:
138+
pull-requests: write
139+
uses: access-nri/actions/.github/actions/pr-comment@main
140+
with:
141+
comment: |
142+
This `${{ github.repository }}` model will be deployed with the following versions:
143+
* `${{ needs.version-tag.outputs.release }}` as a Release (when merged).
144+
* `${{ 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.
145+
146+
It will be deployed using:
147+
* `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 }})
148+
* `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 }})
149+
150+
If this is not what was expected, commit changes to `config/versions.json`.

0 commit comments

Comments
 (0)