Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft PRs disable schema and package projection checks #244

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 37 additions & 27 deletions .github/workflows/deploy-1-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ jobs:
ref: ${{ inputs.deployment-ref }}

- name: Validate ACCESS-NRI spack.yaml Restrictions
if: >-
(github.event_name == 'pull_request' && !github.event.pull_request.draft) ||
(github.event_name == 'issue_comment' && !github.event.issue.draft)
uses: access-nri/schema/.github/actions/validate-with-schema@main
with:
schema-version: ${{ vars.SPACK_YAML_SCHEMA_VERSION }}
Expand All @@ -185,7 +188,7 @@ jobs:

- name: Check '@latest' version usage
if: >-
(github.event_name == 'pull_request' && !github.event.pull_request.draft) ||
(github.event_name == 'pull_request' && !github.event.pull_request.draft) ||
(github.event_name == 'issue_comment' && !github.event.issue.draft)
run: |
if [[ "${{ steps.current.outputs.root-spec-ref }}" == "latest" ]]; then
Expand Down Expand Up @@ -236,40 +239,47 @@ jobs:
* `!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 projections, if they're given.
# For example, [email protected] matches with the
# modulefile access-om3/2023.12.12 (specifically, the version strings match)
# TODO: Move this into the `scripts` directory - it's getting unweildly.
- name: Check Projections - Specs
# This step checks that the root spec has an appropriate projection in the spack.yaml file.
run: |
git checkout ${{ inputs.deployment-ref }}

current_projection=$(yq '.spack.modules.default.tcl.projections.${{ steps.current.outputs.root-spec-name }}' ${{ inputs.spack-manifest-path }})
expected_projection_prefix='{name}/${{ steps.current.outputs.root-spec-ref }}'

if [[ "$current_projection" == "$expected_projection_prefix"* ]]; then
echo "Current root spec projection ($current_projection) and expected projection prefix ($expected_projection_prefix) match."
else
echo "::error::Current root spec projection ($current_projection) and expected projection prefix ($expected_projection_prefix) don't match."
exit 1
fi

- name: Check Projections - Packages
# This step checks that the defined projections have the same versions as the referenced packages in the spack.yaml file.
# For example, [email protected] matches with the
# modulefile mom5/2023.12.12 (specifically, the version strings match)
if: >-
(github.event_name == 'pull_request' && !github.event.pull_request.draft) ||
(github.event_name == 'issue_comment' && !github.event.issue.draft)
run: |
FAILED="false"
# Get all the defined projections (minus 'all') and make them suitable for a bash for loop
DEPS=$(yq '.spack.modules.default.tcl.projections | del(.all) | keys | join(" ")' spack.yaml)
# Get all the defined projections (minus 'all' and the root spec) and make them suitable for a bash for loop
DEPS=$(yq '.spack.modules.default.tcl.projections | del(.all) | del(.${{ steps.current.outputs.root-spec-name }}) | keys | join(" ")' spack.yaml)

# for each of the modules
# for each of the module names
for DEP in $DEPS; do
DEP_VER=''
if [[ "$DEP" == "${{ inputs.spack-manifest-root-sbd }}" ]]; then
# The model version is the bit after '@git.', before any later, space-separated, optional variants.
# For example, in '[email protected] type=ACCESS ~debug' the version is 'VERSION'.
DEP_VER=${{ steps.current.outputs.root-spec-ref }}
else
# Capture the section after '@git.' or '@' (if it's not a git-attributed version) and before a possible '=' for a given dependency.
# Ex. '@git.2024.02.11' -> '2024.02.11', '@access-esm1.5' -> 'access-esm1.5', '@git.2024.05.21=access-esm1.5' -> '2024.05.21'
DEP_VER=$(yq ".spack.packages.\"$DEP\".require[0] | match(\"^@(?:git.)?([^=]*)\").captures[0].string" spack.yaml)
fi
# Capture the section after '@git.' or '@' (if it's not a git-attributed version) and before a possible '=' for a given dependency.
# Ex. '@git.2024.02.11' -> '2024.02.11', '@access-esm1.5' -> 'access-esm1.5', '@git.2024.05.21=access-esm1.5' -> '2024.05.21'
package_ver=$(yq ".spack.packages.\"$DEP\".require[0] | match(\"^@(?:git.)?([^=]*)\").captures[0].string" spack.yaml)
expected_projection_prefix="{name}/$package_ver"

# Get the version from the module projection, for comparison with DEP_VER
# Projections are of the form '{name}/VERSION[-{hash:7}]', in which we only care about VERSION. For example, '{name}/2024.11.11', or '{name}/2024.11.11-{hash:7}'
MODULE_NAME=$(yq ".spack.modules.default.tcl.projections.\"$DEP\"" spack.yaml)
MODULE_VER="${MODULE_NAME#*/}" # Strip '{name}/' from '{name}/VERSION' module, even if VERSION contains '/'
MODULE_VER="${MODULE_VER%%-\{hash:7\}}" # Strip a potential '-{hash:7}' appendix from the VERSION, since we won't have that in the DEP_VER
# Projections must start with '{name}/VERSION'. For example, '{name}/2024.11.11', or '{name}/2024.11.11-{hash:7}'
current_projection=$(yq ".spack.modules.default.tcl.projections.\"$DEP\"" spack.yaml)

if [[ "$DEP_VER" != "$MODULE_VER" ]]; then
echo "::error::$DEP: Version of dependency and projection do not match ($DEP_VER != $MODULE_VER)"
if [[ "$current_projection" == "$expected_projection_prefix"* ]]; then
echo "$DEP: Current projection ($current_projection) and expected projection prefix ($expected_projection_prefix) match."
else
echo "::error::$DEP: Current projection ($current_projection) and expected projection prefix ($expected_projection_prefix) don't match."
FAILED='true'
fi
done
Expand Down