-
Notifications
You must be signed in to change notification settings - Fork 32
/
update.sh
executable file
·37 lines (29 loc) · 1.04 KB
/
update.sh
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
#!/usr/bin/env bash
set -e
set -o pipefail
# Colours https://misc.flogisoft.com/bash/tip_colors_and_formatting
reset=$'\e[0m'
red=$'\e[1;31m'
if ! [ -x "$(command -v gh)" ]; then
printf "%sPlease install 'jq' %s\\n" "${red}" "${reset}"
exit 1
fi
CURRENT_VERSION=$(grep -si HUGO_VERSION= action.sh | cut -d "=" -f 2)
LATEST_VERSION=$(gh release list -R gohugoio/hugo -L 1 | cut -f 1)
LATEST_VERSION=${LATEST_VERSION//v/}
# Update the main action
sed -i.orig "s/HUGO_VERSION=${CURRENT_VERSION}/HUGO_VERSION=${LATEST_VERSION}/g" action.sh
# Update the readme
sed -i.orig "s/HUGO_VERSION: ${CURRENT_VERSION}/HUGO_VERSION: ${LATEST_VERSION}/g" README.md
# Cleanup
rm README.md.orig action.sh.orig
if [[ "${CURRENT_VERSION}" != "${LATEST_VERSION}" ]]; then
printf "Raising pull request"
TITLE="Upgrading Hugo to ${LATEST_VERSION}"
git checkout -b "${LATEST_VERSION}" origin/main
git add action.sh README.md
git commit -m "${TITLE}"
git push origin "${LATEST_VERSION}"
gh pr create --body "${TITLE}" --title "${TITLE}"
git checkout main
fi