Skip to content

Commit 85a0ce3

Browse files
authored
Update publish script (#159)
1 parent 2e27230 commit 85a0ce3

File tree

1 file changed

+68
-25
lines changed

1 file changed

+68
-25
lines changed

etc/publish.sh

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,77 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

3-
set -e
3+
# NOTE: This script requires bash >= 4.4 and GNU coreutils!
4+
# If you run this on macOS, you might need to install the appropiate packages.
45

5-
BP_NAME=${1:-"heroku/gradle"}
6+
set -euo pipefail
7+
shopt -s inherit_errexit
68

7-
curVersion=$(heroku buildpacks:versions $BP_NAME | awk 'FNR == 3 { print $1 }')
8-
newVersion="v$((curVersion + 1))"
9+
buildpack_registry_name="heroku/gradle"
910

10-
read -p "Deploy as version: $newVersion [y/n]? " choice
11-
case "$choice" in
12-
y|Y ) echo "";;
13-
n|N ) exit 0;;
14-
* ) exit 1;;
11+
function abort() {
12+
echo
13+
echo "Error: ${1}" >&2
14+
exit 1
15+
}
16+
17+
echo "Checking environment..."
18+
19+
if ! command -v gh >/dev/null; then
20+
abort "Install the GitHub CLI first: https://cli.github.com"
21+
fi
22+
23+
if ! heroku buildpacks:publish --help >/dev/null; then
24+
abort "Install the Buildpack Registry plugin first: https://github.com/heroku/plugin-buildpack-registry"
25+
fi
26+
27+
# Explicitly check the CLI is logged in, since the Buildpack Registry plugin doesn't handle re-authing
28+
# expired logins properly, which can otherwise lead to the release aborting partway through.
29+
if ! heroku whoami >/dev/null; then
30+
abort "Log into the Heroku CLI first: heroku login"
31+
fi
32+
33+
echo "Checking buildpack versions in sync..."
34+
current_github_release_version=$(gh release view --json tagName --jq '.tagName' | tr --delete 'v')
35+
current_registry_version="$(heroku buildpacks:versions "${buildpack_registry_name}" | awk 'FNR == 3 { print $1 }')"
36+
37+
if [[ "${current_github_release_version}" != "${current_registry_version}" ]]; then
38+
abort "The current GitHub release version (v${current_github_release_version}) does not match the registry version (v${current_registry_version}), likely due to a registry rollback. Fix this first!"
39+
fi
40+
41+
new_version="$((current_github_release_version + 1))"
42+
new_git_tag="v${new_version}"
43+
44+
echo "Extracting changelog entry for this release..."
45+
git fetch origin
46+
# Using `git show` to avoid having to disrupt the current branch/working directory.
47+
changelog_entry="$(git show origin/main:CHANGELOG.md | awk "/^## \[v${new_version}\]/{flag=1; next} /^## /{flag=0} flag")"
48+
49+
if [[ -n "${changelog_entry}" ]]; then
50+
echo -e "${changelog_entry}\n"
51+
else
52+
abort "Unable to find changelog entry for v${new_version}. Has the prepare release PR been triggered/merged?"
53+
fi
54+
55+
read -r -p "Deploy as ${new_git_tag} [y/n]? " choice
56+
case "${choice}" in
57+
y | Y) ;;
58+
n | N) exit 0 ;;
59+
*) exit 1 ;;
1560
esac
1661

17-
originMain=$(git rev-parse origin/main)
18-
echo "Tagging commit $originMain with $newVersion... "
19-
git tag $newVersion ${originMain:?}
20-
git push origin refs/tags/$newVersion
62+
echo -e "\nCreating GitHub release..."
63+
gh release create "${new_git_tag}" --title "${new_git_tag}" --notes "${changelog_entry}"
64+
git fetch --tags
2165

22-
heroku buildpacks:publish $BP_NAME $newVersion
66+
echo -e "\nUpdating previous-version tag..."
67+
git tag -f previous-version latest-version
68+
git push -f origin :refs/tags/previous-version
2369

24-
echo "Updating previous-version tag"
25-
git tag -d previous-version
26-
git push origin :previous-version
27-
git tag previous-version latest-version
28-
echo "Updating latest-version tag"
29-
git tag -d latest-version
30-
git push origin :latest-version
31-
git tag latest-version ${originMain:?}
32-
git push --tags
70+
echo -e "\nUpdating latest-version tag..."
71+
git tag -f latest-version "${new_git_tag}"
72+
git push -f origin :refs/tags/latest-version
3373

34-
echo "Done."
74+
echo -e "\nPublishing to the Heroku Buildpack Registry..."
75+
heroku buildpacks:publish "${buildpack_registry_name}" "${new_git_tag}"
76+
echo
77+
heroku buildpacks:versions "${buildpack_registry_name}" | head -n 3

0 commit comments

Comments
 (0)