Skip to content

Commit 95f4586

Browse files
authored
Update publish script (#253)
1 parent 3d2f0d8 commit 95f4586

1 file changed

Lines changed: 62 additions & 23 deletions

File tree

etc/publish.sh

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

3-
set -e
3+
set -euo pipefail
4+
shopt -s inherit_errexit
45

5-
BP_NAME=${1:-"heroku/java"}
6+
buildpack_registry_name="heroku/java"
67

7-
curVersion=$(heroku buildpacks:versions "$BP_NAME" | awk 'FNR == 3 { print $1 }')
8-
newVersion="v$((curVersion + 1))"
8+
function abort() {
9+
echo
10+
echo "Error: ${1}" >&2
11+
exit 1
12+
}
913

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

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
59+
echo -e "\nCreating GitHub release..."
60+
gh release create "${new_git_tag}" --title "${new_git_tag}" --notes "${changelog_entry}"
2161

22-
heroku buildpacks:publish "$BP_NAME" $newVersion
62+
echo -e "\nUpdating previous-version tag..."
63+
git tag -f previous-version latest-version
64+
git push -f origin :refs/tags/previous-version
2365

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
66+
echo -e "\nUpdating latest-version tag..."
67+
git tag -f latest-version "${new_git_tag}"
68+
git push -f origin :refs/tags/latest-version
3369

34-
echo "Done."
70+
echo -e "\nPublishing to the Heroku Buildpack Registry..."
71+
heroku buildpacks:publish "${buildpack_registry_name}" "${new_git_tag}"
72+
echo
73+
heroku buildpacks:versions "${buildpack_registry_name}" | head -n 3

0 commit comments

Comments
 (0)