|
1 | 1 | #!/usr/bin/env bash
|
2 |
| -# shellcheck disable=SC2250 # TODO: Use braces around variable references even when not strictly required. |
3 | 2 |
|
4 | 3 | set -euo pipefail
|
5 | 4 | shopt -s inherit_errexit
|
6 | 5 |
|
7 |
| -BP_NAME=${1:-"heroku/python"} |
| 6 | +buildpack_registry_name="heroku/python" |
8 | 7 |
|
9 |
| -curVersion=$(heroku buildpacks:versions "$BP_NAME" | awk 'FNR == 3 { print $1 }') |
10 |
| -newVersion="v$((curVersion + 1))" |
| 8 | +function abort() { |
| 9 | + echo |
| 10 | + echo "Error: ${1}" >&2 |
| 11 | + exit 1 |
| 12 | +} |
11 | 13 |
|
12 |
| -read -r -p "Deploy as version: $newVersion [y/n]? " choice |
13 |
| -case "$choice" in |
14 |
| - 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) ;; |
15 | 55 | n | N) exit 0 ;;
|
16 | 56 | *) exit 1 ;;
|
17 | 57 | esac
|
18 | 58 |
|
19 |
| -git fetch origin |
20 |
| -originMain=$(git rev-parse origin/main) |
21 |
| -echo "Tagging commit $originMain with $newVersion... " |
22 |
| -git tag "$newVersion" "${originMain:?}" |
23 |
| -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}" |
24 | 61 |
|
25 |
| -echo -e "\nPublishing to the buildpack registry..." |
26 |
| -heroku buildpacks:publish "$BP_NAME" "$newVersion" |
| 62 | +echo -e "\nPublishing to the Heroku Buildpack Registry..." |
| 63 | +heroku buildpacks:publish "${buildpack_registry_name}" "${new_git_tag}" |
27 | 64 | echo
|
28 |
| -heroku buildpacks:versions "${BP_NAME}" | head -n 3 |
| 65 | +heroku buildpacks:versions "${buildpack_registry_name}" | head -n 3 |
0 commit comments