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

Pull out long inline scripts from run: steps, add testing #84

Open
CodeGat opened this issue May 23, 2024 · 0 comments · May be fixed by #91
Open

Pull out long inline scripts from run: steps, add testing #84

CodeGat opened this issue May 23, 2024 · 0 comments · May be fixed by #91

Comments

@CodeGat
Copy link
Contributor

CodeGat commented May 23, 2024

similar to https://github.com/ACCESS-NRI/build-cd/blob/main/scripts/generate-build-metadata.bash which has had a large script pulled out and tested, we need to do this for more scripts. This will make it easier to test independently. This should be the case for all long-running scripts.

Some candidates:

  • 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" == "${{ needs.defaults.outputs.root-sbd }}" ]]; then
    DEP_VER=$(yq '.spack.specs[0] | split("@git.") | .[1]' spack.yaml)
    else
    # Capture the section after '@git.' or '@' (if it's not a git-attributed version) for a given dependency.
    # Ex. '@git.2024.02.11' -> '2024.02.11', '@access-esm1.5' -> 'access-esm1.5'
    DEP_VER=$(yq ".spack.packages.\"$DEP\".require[0] | match(\"^@(?:git.)?(.*)\").captures[0].string" spack.yaml)
    fi
    MODULE_VER=$(yq ".spack.modules.default.tcl.projections.\"$DEP\" | split(\"/\") | .[1]" spack.yaml)
    if [[ "$DEP_VER" != "$MODULE_VER" ]]; then
    echo "::error::$DEP: Version of dependency and projection do not match ($DEP_VER != $MODULE_VER)"
    FAILED='true'
    fi
    done
    if [[ "$FAILED" == "true" ]]; then
    exit 1
    fi
  • # Get the version of ${{ inputs.root-sbd }} from the spack.yaml in the PR the comment was written in
    gh pr checkout ${{ github.event.issue.number }}
    original_version=$(yq e '${{ env.SPACK_YAML_MODEL_YQ }} | split("@git.") | .[1]' spack.yaml)
    echo "original-version=${original_version}" >> $GITHUB_OUTPUT
    # Validate the comment
    if [[ "${{ contains(github.event.comment.body, 'major') }}" == "true" ]]; then
    # Compare the current date (year-month) with the latest git tag (year-month)
    # to determine the next valid tag. We do this because especially feature-rich
    # months might increment the date part beyond the current date.
    d="$(date +%Y-%m)-01"
    d_s=$(date --date "$d" +%s)
    latest_tag=$(git describe --tags --abbrev=0 | tr '.' '-')
    tag_date=${latest_tag%-*}-01
    tag_date_s=$(date --date "$tag_date" +%s)
    echo "Comparing current date ${d} with ${tag_date} (tag looks like ${latest_tag})"
    if (( d_s <= tag_date_s )); then
    echo "version=${tag_date}" >> $GITHUB_OUTPUT
    echo "bump=major" >> $GITHUB_OUTPUT
    else
    echo "version=${original_version}" >> $GITHUB_OUTPUT
    echo "bump=current" >> $GITHUB_OUTPUT
    fi
    elif [[ "${{ contains(github.event.comment.body, 'minor')}}" == "true" ]]; then
    echo "version=${original_version}" >> $GITHUB_OUTPUT
    echo "bump=minor" >> $GITHUB_OUTPUT
    else
    echo "::warning::Usage: `!bump [major|minor]`, got `${{ github.event.comment.body }}`"
    exit 1
    fi
  • I'm sure there are others...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant