-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (88 loc) · 4.13 KB
/
comment.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Comment Command
on:
issue_comment:
types:
- created
- edited
env:
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
SPACK_YAML_MODEL_YQ: .spack.specs[0]
SPACK_YAML_MODEL_PROJECTION_YQ: .spack.modules.default.tcl.projections.access-om3
jobs:
bump-version:
name: Bump spack.yaml
if: github.event.issue.pull_request && startsWith(github.event.comment.body, '!bump')
runs-on: ubuntu-latest
permissions:
pull-requests: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
token: ${{ secrets.GH_COMMIT_CHECK_TOKEN }}
- name: Setup
id: setup
# outputs:
# original-version: The version contained within the spack.yaml
# version: The version that will be bumped (could be latest tag instead of original-version)
# bump: The bump type (major, minor or current as specified in the bump-version action)
run: |
# Get the version of access-om3 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
- name: Bump Version
id: bump
uses: access-nri/actions/.github/actions/bump-version@main
with:
version: ${{ steps.setup.outputs.version }}
versioning-scheme: calver-minor
bump-type: ${{ steps.setup.outputs.bump }}
- name: Update, Commit and Push the Bump
run: |
git config user.name ${{ vars.GH_ACTIONS_BOT_GIT_USER_NAME }}
git config user.email ${{ vars.GH_ACTIONS_BOT_GIT_USER_EMAIL }}
yq -i '${{ env.SPACK_YAML_MODEL_YQ }} = "access-om3@git.${{ steps.bump.outputs.after }}"' spack.yaml
yq -i '${{ env.SPACK_YAML_MODEL_PROJECTION_YQ }} = "{name}/${{ steps.bump.outputs.after }}"' spack.yaml
git add spack.yaml
git commit -m "spack.yaml: Updated access-om3 package version from ${{ steps.setup.outputs.original-version }} to ${{ steps.bump.outputs.after }}"
git push
- name: Success Notifier
uses: access-nri/actions/.github/actions/pr-comment@main
with:
comment: |
:white_check_mark: Version bumped from `${{ steps.setup.outputs.original-version }}` to `${{ steps.bump.outputs.after }}` :white_check_mark:
- name: Failure Notifier
if: failure()
uses: access-nri/actions/.github/actions/pr-comment@main
with:
comment: |
:x: Failed to bump version or commit changes, see ${{ env.RUN_URL }} :x: