|
| 1 | +name: Comment Command |
| 2 | +run-name: ${{ inputs.model }} Comment Command |
| 3 | +# NOTE: This workflow requires: |
| 4 | +# permissions.contents:write |
| 5 | +on: |
| 6 | + workflow_call: |
| 7 | + inputs: |
| 8 | + model: |
| 9 | + type: string |
| 10 | + required: true |
| 11 | + description: The model that is being tested and deployed |
| 12 | + root-sbd: |
| 13 | + type: string |
| 14 | + required: false |
| 15 | + default: ${{ inputs.model }} |
| 16 | + description: | |
| 17 | + The name of the root Spack Bundle Definition, if it is different from the model name. |
| 18 | + This is often a package named similarly in ACCESS-NRI/spack-packages. |
| 19 | + # Callers usually have the trigger: |
| 20 | + # issue_comment: |
| 21 | + # types: |
| 22 | + # - created |
| 23 | + # - edited |
| 24 | +env: |
| 25 | + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 26 | + SPACK_YAML_MODEL_YQ: .spack.specs[0] |
| 27 | + SPACK_YAML_MODEL_PROJECTION_YQ: .spack.modules.default.tcl.projections.${{ inputs.root-sbd }} |
| 28 | +jobs: |
| 29 | + bump-version: |
| 30 | + name: Bump spack.yaml |
| 31 | + if: github.event.issue.pull_request && startsWith(github.event.comment.body, '!bump') |
| 32 | + runs-on: ubuntu-latest |
| 33 | + permissions: |
| 34 | + pull-requests: write |
| 35 | + env: |
| 36 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + fetch-depth: 0 |
| 41 | + fetch-tags: true |
| 42 | + token: ${{ secrets.GH_COMMIT_CHECK_TOKEN }} |
| 43 | + |
| 44 | + - name: Setup |
| 45 | + id: setup |
| 46 | + # outputs: |
| 47 | + # original-version: The version contained within the spack.yaml |
| 48 | + # version: The version that will be bumped (could be latest tag instead of original-version) |
| 49 | + # bump: The bump type (major, minor or current as specified in the bump-version action) |
| 50 | + run: | |
| 51 | + # Get the version of ${{ inputs.root-sbd }} from the spack.yaml in the PR the comment was written in |
| 52 | + gh pr checkout ${{ github.event.issue.number }} |
| 53 | + original_version=$(yq e '${{ env.SPACK_YAML_MODEL_YQ }} | split("@git.") | .[1]' spack.yaml) |
| 54 | + echo "original-version=${original_version}" >> $GITHUB_OUTPUT |
| 55 | +
|
| 56 | + # Validate the comment |
| 57 | + if [[ "${{ contains(github.event.comment.body, 'major') }}" == "true" ]]; then |
| 58 | + # Compare the current date (year-month) with the latest git tag (year-month) |
| 59 | + # to determine the next valid tag. We do this because especially feature-rich |
| 60 | + # months might increment the date part beyond the current date. |
| 61 | +
|
| 62 | + d="$(date +%Y-%m)-01" |
| 63 | + d_s=$(date --date "$d" +%s) |
| 64 | +
|
| 65 | + latest_tag=$(git describe --tags --abbrev=0 | tr '.' '-') |
| 66 | + tag_date=${latest_tag%-*}-01 |
| 67 | + tag_date_s=$(date --date "$tag_date" +%s) |
| 68 | +
|
| 69 | + echo "Comparing current date ${d} with ${tag_date} (tag looks like ${latest_tag})" |
| 70 | +
|
| 71 | + if (( d_s <= tag_date_s )); then |
| 72 | + echo "version=${tag_date}" >> $GITHUB_OUTPUT |
| 73 | + echo "bump=major" >> $GITHUB_OUTPUT |
| 74 | + else |
| 75 | + echo "version=${original_version}" >> $GITHUB_OUTPUT |
| 76 | + echo "bump=current" >> $GITHUB_OUTPUT |
| 77 | + fi |
| 78 | + elif [[ "${{ contains(github.event.comment.body, 'minor')}}" == "true" ]]; then |
| 79 | + echo "version=${original_version}" >> $GITHUB_OUTPUT |
| 80 | + echo "bump=minor" >> $GITHUB_OUTPUT |
| 81 | + else |
| 82 | + echo "::warning::Usage: `!bump [major|minor]`, got `${{ github.event.comment.body }}`" |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | +
|
| 86 | + - name: Bump Version |
| 87 | + id: bump |
| 88 | + uses: access-nri/actions/.github/actions/bump-version@main |
| 89 | + with: |
| 90 | + version: ${{ steps.setup.outputs.version }} |
| 91 | + versioning-scheme: calver-minor |
| 92 | + bump-type: ${{ steps.setup.outputs.bump }} |
| 93 | + |
| 94 | + - name: Update, Commit and Push the Bump |
| 95 | + run: | |
| 96 | + git config user.name ${{ vars.GH_ACTIONS_BOT_GIT_USER_NAME }} |
| 97 | + git config user.email ${{ vars.GH_ACTIONS_BOT_GIT_USER_EMAIL }} |
| 98 | +
|
| 99 | + yq -i '${{ env.SPACK_YAML_MODEL_YQ }} = "${{ inputs.root-sbd }}@git.${{ steps.bump.outputs.after }}"' spack.yaml |
| 100 | + yq -i '${{ env.SPACK_YAML_MODEL_PROJECTION_YQ }} = "{name}/${{ steps.bump.outputs.after }}"' spack.yaml |
| 101 | + git add spack.yaml |
| 102 | + git commit -m "spack.yaml: Updated ${{ inputs.root-sbd }} package version from ${{ steps.setup.outputs.original-version }} to ${{ steps.bump.outputs.after }}" |
| 103 | + git push |
| 104 | +
|
| 105 | + - name: Success Notifier |
| 106 | + uses: access-nri/actions/.github/actions/pr-comment@main |
| 107 | + with: |
| 108 | + comment: | |
| 109 | + :white_check_mark: Version bumped from `${{ steps.setup.outputs.original-version }}` to `${{ steps.bump.outputs.after }}` :white_check_mark: |
| 110 | +
|
| 111 | + - name: Failure Notifier |
| 112 | + if: failure() |
| 113 | + uses: access-nri/actions/.github/actions/pr-comment@main |
| 114 | + with: |
| 115 | + comment: | |
| 116 | + :x: Failed to bump version or commit changes, see ${{ env.RUN_URL }} :x: |
0 commit comments