Skip to content

Commit e5c81d3

Browse files
authored
Consolidated CI/CD (#7)
* Updated the CI/CD to use the simplified format described in ACCESS-NRI/build-cd#47 * cd.yml: om3 instead of om2 * Changed explicit model name to vars
1 parent e2c338f commit e5c81d3

File tree

4 files changed

+40
-328
lines changed

4 files changed

+40
-328
lines changed

.github/workflows/cd.yml

+5-34
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,12 @@ on:
77
paths:
88
- config/**
99
- spack.yaml
10-
env:
11-
SPACK_YAML_MODEL_YQ: .spack.specs[0]
1210
jobs:
13-
push-tag:
14-
name: Tag Deployment
15-
runs-on: ubuntu-latest
16-
permissions:
17-
contents: write
18-
outputs:
19-
name: ${{ steps.tag.outputs.name }}
20-
steps:
21-
- uses: actions/checkout@v4
22-
23-
- name: Generate Tag
24-
id: tag
25-
# Get the tag name from the `spack.yaml` that was merged into main, which
26-
# is of the form `access-om3@git.<version>`.
27-
run: echo "name=$(yq '${{ env.SPACK_YAML_MODEL_YQ }} | split("@git.") | .[1]' spack.yaml)" >> $GITHUB_OUTPUT
28-
29-
- name: Push Tag
30-
# NOTE: Regarding the config user.name/user.email, see https://github.com/actions/checkout/pull/1184
31-
run: |
32-
git config user.name ${{ vars.GH_ACTIONS_BOT_GIT_USER_NAME }}
33-
git config user.email ${{ vars.GH_ACTIONS_BOT_GIT_USER_EMAIL }}
34-
git tag ${{ steps.tag.outputs.name }} --force
35-
git push --tags --force
36-
37-
deploy-release:
38-
name: Deploy Release
39-
needs:
40-
- push-tag
41-
uses: access-nri/build-cd/.github/workflows/deploy-1-setup.yml@main
11+
cd:
12+
name: CD
13+
uses: access-nri/build-cd/.github/workflows/cd.yml@main
4214
with:
43-
ref: ${{ github.ref_name }}
44-
version: ${{ needs.push-tag.outputs.name }}
45-
secrets: inherit
15+
model: ${{ vars.NAME }}
4616
permissions:
4717
contents: write
18+
secrets: inherit

.github/workflows/ci.yml

+35-159
Original file line numberDiff line numberDiff line change
@@ -1,178 +1,54 @@
11
name: CI
22
on:
33
pull_request:
4+
types:
5+
- opened
6+
- reopened
7+
- synchronize
8+
- closed
49
branches:
510
- main
611
- backport/*.*
712
paths:
813
- config/**
914
- spack.yaml
10-
env:
11-
SPACK_YAML_MODEL_YQ: .spack.specs[0]
15+
issue_comment:
16+
types:
17+
- created
18+
- edited
1219
jobs:
13-
validate-json:
14-
name: Validate JSON
15-
uses: access-nri/actions/.github/workflows/validate-json.yml@main
20+
pr-ci:
21+
name: CI
22+
# This job is responsible for checks and prerelease deployments
23+
# that happen when a PR is modified or opened
24+
if: github.event_name == 'pull_request' && github.event.action != 'closed'
25+
uses: access-nri/build-cd/.github/workflows/ci.yml@main
1626
with:
17-
src: "config"
18-
19-
check-config:
20-
name: Check Config Fields
21-
needs:
22-
- validate-json
23-
runs-on: ubuntu-latest
24-
outputs:
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
27+
model: ${{ vars.NAME }}
4328
permissions:
4429
pull-requests: write
45-
steps:
46-
- uses: actions/checkout@v4
47-
with:
48-
fetch-depth: 0
49-
50-
- name: Check Model Version Modified
51-
id: version
52-
run: |
53-
git checkout ${{ github.base_ref }}
54-
base_version=$(yq e '${{ env.SPACK_YAML_MODEL_YQ }}' spack.yaml)
55-
56-
git checkout ${{ github.head_ref }}
57-
current_version=$(yq e '${{ env.SPACK_YAML_MODEL_YQ }}' spack.yaml)
58-
echo "current=${current_version}" >> $GITHUB_OUTPUT
59-
60-
if [[ "${base_version}" == "${current_version}" ]]; then
61-
echo "::warning::The version string hasn't been modified in this PR, but needs to be before merging."
62-
exit 1
63-
fi
64-
65-
- name: Same Model Version Failure Notifier
66-
if: failure() && steps.version.outcome == 'failure'
67-
uses: access-nri/actions/.github/actions/pr-comment@main
68-
with:
69-
comment: |
70-
The model version in the `spack.yaml` has not been updated.
71-
Either update it manually, or comment the following to have it updated and committed automatically:
72-
* `!bump major` for feature releases
73-
* `!bump minor` for bugfixes
74-
75-
- name: Projection Version Matches
76-
# this step checks that the versions of the packages themselves match with the
77-
# names of the modules. For example, [email protected] matches with the
78-
# modulefile access-om3/2023.12.12 (specifically, the version strings match)
79-
run: |
80-
FAILED='false'
81-
DEPS=$(yq ".spack.modules.default.tcl.include | join(\" \")" spack.yaml)
82-
83-
# for each of the modules
84-
for DEP in $DEPS; do
85-
DEP_VER=''
86-
if [[ "$DEP" == "access-om3" ]]; then
87-
DEP_VER=$(yq '.spack.specs[0] | split("@git.") | .[1]' spack.yaml)
88-
else
89-
DEP_VER=$(yq ".spack.packages.\"$DEP\".require[0] | split(\"@git.\") | .[1]" spack.yaml)
90-
fi
91-
92-
MODULE_VER=$(yq ".spack.modules.default.tcl.projections.\"$DEP\" | split(\"/\") | .[1]" spack.yaml)
93-
94-
if [[ "$DEP_VER" != "$MODULE_VER" ]]; then
95-
echo "::error::Version of dependency and projection do not match ($DEP_VER != $MODULE_VER)"
96-
FAILED='true'
97-
fi
98-
done
99-
if [[ "$FAILED" == "true" ]]; then
100-
exit 1
101-
fi
102-
103-
version-tag:
104-
name: Get Version and Tag Prerelease
105-
needs:
106-
- check-spack-yaml
107-
runs-on: ubuntu-latest
108-
permissions:
10930
contents: write
110-
outputs:
111-
release: ${{ steps.version.outputs.release }}
112-
prerelease: ${{ steps.version.outputs.prerelease }}
113-
steps:
114-
- uses: actions/checkout@v4
115-
with:
116-
ref: ${{ github.head_ref }}
117-
fetch-depth: 0
118-
119-
- name: Generate Versions
120-
id: version
121-
# This step generates the release and prerelease version numbers.
122-
# The release is a general version number from the spack.yaml, looking the
123-
# same as a regular release build. Ex. '[email protected]' -> '2024.01.1'
124-
# The prerelease looks like: `pr<pull request number>-<number of commits on this branch>`.
125-
# Ex. Pull Request #12 with 2 commits on branch -> `pr12-2`.
126-
run: |
127-
echo "release=$(yq '${{ env.SPACK_YAML_MODEL_YQ }} | split("@git.") | .[1]' spack.yaml)" >> $GITHUB_OUTPUT
128-
129-
number_of_commits=$(git rev-list --count ${{ github.event.pull_request.base.sha }}..HEAD)
130-
echo "prerelease=pr${{ github.event.pull_request.number }}-${number_of_commits}" >> $GITHUB_OUTPUT
131-
132-
- name: Shift Prerelease Tag ${{ steps.version.outputs.release }}
133-
# We shift the 'Release' tag along the PR as the spack.yaml will not work without the correct tag in this repostiory.
134-
# NOTE: Regarding the config user.name/user.email, see https://github.com/actions/checkout/pull/1184
135-
run: |
136-
git config user.name ${{ vars.GH_ACTIONS_BOT_GIT_USER_NAME }}
137-
git config user.email ${{ vars.GH_ACTIONS_BOT_GIT_USER_EMAIL }}
138-
git tag ${{ steps.version.outputs.release }} --force
139-
git push --tags --force
140-
141-
# -----------------------------
142-
# | PRERELEASE DEPLOYMENT JOB |
143-
# -----------------------------
144-
prerelease-deploy:
145-
name: Deploy to Prerelease
146-
# This will create a `spack` environment with the name `access-om3-pr<pull request number>-<commit number>`.
147-
# For example, `access-om3-pr13-3` for the deployment based on the third commit on the PR#13.
148-
needs:
149-
- version-tag # implies all the spack.yaml-related checks have passed, has appropriate version for the prerelease build
150-
- check-config # implies all the json-related checks have passed
151-
uses: access-nri/build-cd/.github/workflows/deploy-1-setup.yml@main
31+
secrets: inherit # inherit GitHub Deployment Environment secrets
32+
33+
pr-comment:
34+
name: Comment
35+
# This job is responsible for handling Command Comments like
36+
# `!bump` during an open PR
37+
if: github.event_name == 'issue_comment'
38+
uses: access-nri/build-cd/.github/workflows/ci-comment.yml@main
15239
with:
153-
type: prerelease
154-
ref: ${{ github.head_ref }}
155-
version: ${{ needs.version-tag.outputs.prerelease }}
156-
secrets: inherit
157-
158-
notifier:
159-
name: Notifier
160-
needs:
161-
- version-tag # implies all the spack.yaml-related checks have passed, has appropriate version for the prerelease build
162-
- check-config # implies all the json-related checks have passed
163-
runs-on: ubuntu-latest
40+
model: ${{ vars.NAME }}
16441
permissions:
16542
pull-requests: write
166-
steps:
167-
- uses: access-nri/actions/.github/actions/pr-comment@main
168-
with:
169-
comment: |
170-
This `${{ github.repository }}` model will be deployed with the following versions:
171-
* `${{ needs.version-tag.outputs.release }}` as a Release (when merged).
172-
* `${{ 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.
43+
contents: write
17344

174-
It will be deployed using:
175-
* `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 }})
176-
* `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 }})
17745

178-
If this is not what was expected, commit changes to `config/versions.json`.
46+
pr-closed:
47+
name: Closed
48+
# This job is responsible for cleaning up the Prereleases after a
49+
# PR is closed
50+
if: github.event_name == 'pull_request' && github.event.action == 'closed'
51+
uses: access-nri/build-cd/.github/workflows/ci-closed.yml@main
52+
with:
53+
model: ${{ vars.NAME }}
54+
secrets: inherit # inherit GitHub Deployment environment secrets

.github/workflows/comment.yml

-99
This file was deleted.

.github/workflows/pr-closed.yml

-36
This file was deleted.

0 commit comments

Comments
 (0)