Skip to content

Commit

Permalink
Moved bump-version setup script into scripts/ci-comment/setup-bump-ar…
Browse files Browse the repository at this point in the history
…gs.bash
  • Loading branch information
CodeGat committed May 31, 2024
1 parent 118ffcf commit 250db44
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 34 deletions.
35 changes: 1 addition & 34 deletions .github/workflows/ci-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,40 +48,7 @@ jobs:
# 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 ${{ 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
./scripts/ci-comment/setup-bump-args.bash ${{ github.event.issue.number }} "${{ github.event.issue.comment }}"
- name: Bump Version
id: bump
Expand Down
44 changes: 44 additions & 0 deletions scripts/ci-comment/setup-bump-args.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
set -x
set -e

### INPUTS ###
# Comments are made to certain PRs, this variable holds the PR Number
PR_NUMBER=$1
# Comment Body
COMMENT_BODY=$2

# Get the version of ${{ inputs.root-sbd }} from the spack.yaml in the PR the comment was written in
gh pr checkout "$PR_NUMBER"
original_version=$(yq e '$SPACK_YAML_MODEL_YQ | split("@git.") | .[1]' spack.yaml)
echo "original-version=${original_version}" >> "$GITHUB_OUTPUT"

# Validate the comment
if [[ "$COMMENT_BODY" =~ major ]]; 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 [[ "$COMMENT_BODY" =~ minor ]]; then
echo "version=${original_version}" >> "$GITHUB_OUTPUT"
echo "bump=minor" >> "$GITHUB_OUTPUT"
else
echo "::warning::Usage: '!bump [major|minor]', got '$COMMENT_BODY'"
exit 1
fi

0 comments on commit 250db44

Please sign in to comment.