|
| 1 | +#!/bin/bash -e |
| 2 | + |
| 3 | +if [[ $DEBUG == "true" ]]; then |
| 4 | + echo "DEBUG is enabled" |
| 5 | + set -x # Print commands and their arguments as they are executed |
| 6 | +fi |
| 7 | + |
| 8 | +APP_VERSION_FILE="APP_VERSION" |
| 9 | + |
| 10 | +# This script is used to update the version of the app. |
| 11 | + |
| 12 | +# Get the latest draft version from the GitHub Releases |
| 13 | +# and take into accoutn that the most recent version is the latest version, |
| 14 | +# while the second most recent version is the second entry. |
| 15 | +# ❯ gh release list -L 5 |
| 16 | +# TITLE TYPE TAG NAME PUBLISHED |
| 17 | +# 2.2.27 Latest 2.2.27 about 5 days ago |
| 18 | +# 2.2.28 Draft 2.2.28 about 1 month ago |
| 19 | +# 2.2.26 2.2.26 about 1 month ago |
| 20 | +# 2.2.25 2.2.25 about 2 months ago |
| 21 | +# 2.2.24 2.2.24 about 2 months ago |
| 22 | +LATEST_DRAFT_VERSION=$(gh release list -L 20 | awk -F '\t' '{if ($2 == "Draft" && match($3, "^[0-9]+\\.[0-9]+\\.[0-9]+")) {print $3; exit}}') |
| 23 | +LATEST_VERSION=$(gh release view --json tagName -q .tagName) |
| 24 | + |
| 25 | +if [[ $LATEST_DRAFT_VERSION == $LATEST_VERSION ]]; then |
| 26 | + echo "latest draft version ($LATEST_DRAFT_VERSION) matches latest version ($LATEST_VERSION)" |
| 27 | + exit 0 |
| 28 | +elif [[ $LATEST_DRAFT_VERSION == $(cat $APP_VERSION_FILE) ]]; then |
| 29 | + echo "latest draft version ($LATEST_DRAFT_VERSION) matches current version in $APP_VERSION_FILE" |
| 30 | + exit 0 |
| 31 | +fi |
| 32 | + |
| 33 | +if [[ -n $GITHUB_ACTOR ]]; then |
| 34 | + git config --global user.name "${GITHUB_ACTOR}" |
| 35 | + git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" |
| 36 | +fi |
| 37 | + |
| 38 | +BRANCH_NAME_PREFIX="update-app-version" |
| 39 | + |
| 40 | +BRANCH_NAME="$BRANCH_NAME_PREFIX-$LATEST_DRAFT_VERSION" |
| 41 | + |
| 42 | +EXISTS=$(git branch -r -l 'origin*' | sed -E -e 's/^[^\/]+\///g' -e 's/HEAD.+//' | grep "$BRANCH_NAME" || echo "false") |
| 43 | + |
| 44 | +if [[ -n $EXISTS ]] && [[ $EXISTS != "false" ]]; then |
| 45 | + echo "A PR already exists on branch $BRANCH_NAME for App Version update: $LATET_DRAFT_VERSION" |
| 46 | + exit 0 |
| 47 | +fi |
| 48 | + |
| 49 | +echo "checking out new Git branch $BRANCH_NAME..." |
| 50 | + |
| 51 | +git switch -c $BRANCH_NAME master |
| 52 | + |
| 53 | +printf " done\n" |
| 54 | + |
| 55 | +echo "Updating $APP_VERSION_FILE..." |
| 56 | + |
| 57 | +echo $LATEST_DRAFT_VERSION >$APP_VERSION_FILE |
| 58 | + |
| 59 | +echo "Committing changes..." |
| 60 | + |
| 61 | +COMMIT_MSG="Update $APP_VERSION_FILE to $LATEST_DRAFT_VERSION" |
| 62 | + |
| 63 | +git add $APP_VERSION_FILE |
| 64 | + |
| 65 | +git commit -m "$COMMIT_MSG" |
| 66 | + |
| 67 | +echo "Pushing to origin..." |
| 68 | + |
| 69 | +git push -u origin $BRANCH_NAME |
| 70 | + |
| 71 | +echo "Creating Pull Request..." |
| 72 | + |
| 73 | +printf "This updates the App Version to $LATEST_DRAFT_VERSION" | gh pr create -R go-nv/goenv -B master \ |
| 74 | + -t "$COMMIT_MSG" \ |
| 75 | + -F - |
| 76 | + |
| 77 | +echo 'All done!' |
0 commit comments