|
| 1 | +name: CI |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + - backport/*.* |
| 7 | + paths: |
| 8 | + - config/** |
| 9 | + - spack.yaml |
| 10 | +env: |
| 11 | + SPACK_YAML_MODEL_YQ: .spack.specs[0] |
| 12 | +jobs: |
| 13 | + validate-json: |
| 14 | + name: Validate JSON |
| 15 | + uses: access-nri/actions/.github/workflows/validate-json.yml@main |
| 16 | + 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 |
| 43 | + permissions: |
| 44 | + 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-virtual" ]]; 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: |
| 109 | + 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 |
| 152 | + 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 |
| 164 | + permissions: |
| 165 | + 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. |
| 173 | +
|
| 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 }}) |
| 177 | +
|
| 178 | + If this is not what was expected, commit changes to `config/versions.json`. |
0 commit comments