Skip to content

Commit

Permalink
Consolidated CI/CD (#7)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
CodeGat authored Apr 19, 2024
1 parent e2c338f commit e5c81d3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 328 deletions.
39 changes: 5 additions & 34 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,12 @@ on:
paths:
- config/**
- spack.yaml
env:
SPACK_YAML_MODEL_YQ: .spack.specs[0]
jobs:
push-tag:
name: Tag Deployment
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
name: ${{ steps.tag.outputs.name }}
steps:
- uses: actions/checkout@v4

- name: Generate Tag
id: tag
# Get the tag name from the `spack.yaml` that was merged into main, which
# is of the form `access-om3@git.<version>`.
run: echo "name=$(yq '${{ env.SPACK_YAML_MODEL_YQ }} | split("@git.") | .[1]' spack.yaml)" >> $GITHUB_OUTPUT

- name: Push Tag
# 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.tag.outputs.name }} --force
git push --tags --force
deploy-release:
name: Deploy Release
needs:
- push-tag
uses: access-nri/build-cd/.github/workflows/deploy-1-setup.yml@main
cd:
name: CD
uses: access-nri/build-cd/.github/workflows/cd.yml@main
with:
ref: ${{ github.ref_name }}
version: ${{ needs.push-tag.outputs.name }}
secrets: inherit
model: ${{ vars.NAME }}
permissions:
contents: write
secrets: inherit
194 changes: 35 additions & 159 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,178 +1,54 @@
name: CI
on:
pull_request:
types:
- opened
- reopened
- synchronize
- closed
branches:
- main
- backport/*.*
paths:
- config/**
- spack.yaml
env:
SPACK_YAML_MODEL_YQ: .spack.specs[0]
issue_comment:
types:
- created
- edited
jobs:
validate-json:
name: Validate JSON
uses: access-nri/actions/.github/workflows/validate-json.yml@main
pr-ci:
name: CI
# This job is responsible for checks and prerelease deployments
# that happen when a PR is modified or opened
if: github.event_name == 'pull_request' && github.event.action != 'closed'
uses: access-nri/build-cd/.github/workflows/ci.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
model: ${{ vars.NAME }}
permissions:
pull-requests: write
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: 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 access-om3/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 modules
for DEP in $DEPS; do
DEP_VER=''
if [[ "$DEP" == "access-om3" ]]; then
DEP_VER=$(yq '.spack.specs[0] | split("@git.") | .[1]' spack.yaml)
else
DEP_VER=$(yq ".spack.packages.\"$DEP\".require[0] | split(\"@git.\") | .[1]" spack.yaml)
fi
MODULE_VER=$(yq ".spack.modules.default.tcl.projections.\"$DEP\" | split(\"/\") | .[1]" spack.yaml)
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
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
secrets: inherit # inherit GitHub Deployment Environment secrets

pr-comment:
name: Comment
# This job is responsible for handling Command Comments like
# `!bump` during an open PR
if: github.event_name == 'issue_comment'
uses: access-nri/build-cd/.github/workflows/ci-comment.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
runs-on: ubuntu-latest
model: ${{ vars.NAME }}
permissions:
pull-requests: write
steps:
- 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.
contents: write

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`.
pr-closed:
name: Closed
# This job is responsible for cleaning up the Prereleases after a
# PR is closed
if: github.event_name == 'pull_request' && github.event.action == 'closed'
uses: access-nri/build-cd/.github/workflows/ci-closed.yml@main
with:
model: ${{ vars.NAME }}
secrets: inherit # inherit GitHub Deployment environment secrets
99 changes: 0 additions & 99 deletions .github/workflows/comment.yml

This file was deleted.

36 changes: 0 additions & 36 deletions .github/workflows/pr-closed.yml

This file was deleted.

0 comments on commit e5c81d3

Please sign in to comment.