|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | +shopt -s inherit_errexit |
| 5 | + |
| 6 | +buildpack_registry_name="heroku/php" |
| 7 | +github_repository_shorthand="heroku/heroku-buildpack-php" |
| 8 | + |
| 9 | +function abort() { |
| 10 | + echo >&2 |
| 11 | + echo >&2 "Error: ${1}" |
| 12 | + exit 1 |
| 13 | +} |
| 14 | + |
| 15 | +echo >&2 "Checking environment..." |
| 16 | + |
| 17 | +if ! command -v gh >/dev/null; then |
| 18 | + abort "Install the GitHub CLI first: https://cli.github.com" |
| 19 | +fi |
| 20 | + |
| 21 | +if ! heroku buildpacks:publish --help >/dev/null; then |
| 22 | + abort "Install the Buildpack Registry plugin first: https://github.com/heroku/plugin-buildpack-registry" |
| 23 | +fi |
| 24 | + |
| 25 | +echo >&2 |
| 26 | +echo >&2 "GitHub CLI user info for active account:" |
| 27 | +if ! gh auth status --active; then |
| 28 | + abort "Log into the GitHub CLI first: gh auth login" |
| 29 | +fi |
| 30 | + |
| 31 | +echo >&2 |
| 32 | +echo >&2 "Heroku CLI user info for active account:" |
| 33 | +# Explicitly check the CLI is logged in, since the Buildpack Registry plugin doesn't handle re-authing |
| 34 | +# expired logins properly, which can otherwise lead to the release aborting partway through. |
| 35 | +if ! heroku whoami; then |
| 36 | + abort "Log into the Heroku CLI first: heroku login" |
| 37 | +fi |
| 38 | + |
| 39 | +if [[ $(gh repo view --json "owner,name" --jq '(.owner.login +"/"+ .name)') != "$github_repository_shorthand" ]]; then |
| 40 | + abort "Local Git repository remote 'origin' is not ${github_repository_shorthand}" |
| 41 | +fi |
| 42 | + |
| 43 | +echo >&2 |
| 44 | +echo >&2 "Fetching releases from GitHub..." |
| 45 | +current_github_release_version=$(gh release view --json tagName --jq '.tagName' | tr -d 'v') |
| 46 | +new_version="$((current_github_release_version + 1))" |
| 47 | +new_git_tag="v${new_version}" |
| 48 | + |
| 49 | +echo "Current release Git tag is v${current_github_release_version}, new tag will be ${new_git_tag}" |
| 50 | + |
| 51 | +echo >&2 "Extracting changelog entry for this release..." |
| 52 | +git fetch origin |
| 53 | +# Using `git show` to avoid having to disrupt the current branch/working directory. |
| 54 | +changelog_entry="$(git show origin/main:CHANGELOG.md | awk "/^## \[v${new_version}\]/{flag=1; next} /^## /{flag=0} flag")" |
| 55 | + |
| 56 | +if [[ -n "${changelog_entry}" ]]; then |
| 57 | + echo -e "${changelog_entry}\n" |
| 58 | +else |
| 59 | + abort "Unable to find changelog entry for v${new_version}. Has the prepare release PR been triggered/merged?" |
| 60 | +fi |
| 61 | + |
| 62 | +read -r -p "Release on GitHub as tag '${new_git_tag}' and publish to Buildpack Registry buildpack '${buildpack_registry_name}' [y/n]? " choice |
| 63 | +case "${choice}" in |
| 64 | + y | Y) ;; |
| 65 | + n | N) exit 0 ;; |
| 66 | + *) exit 1 ;; |
| 67 | +esac |
| 68 | + |
| 69 | +echo >&2 |
| 70 | +echo >&2 "Creating GitHub release and tag '${new_git_tag}'..." |
| 71 | +gh release create "${new_git_tag}" --title "${new_git_tag}" --notes "${changelog_entry}" |
| 72 | + |
| 73 | +echo >&2 |
| 74 | +echo >&2 "Publishing buildpack '${buildpack_registry_name}' using Git tag '${new_git_tag}' on Heroku Buildpack Registry..." |
| 75 | +heroku buildpacks:publish "${buildpack_registry_name}" "${new_git_tag}" || abort "Failed to publish to Buildpack Registry. |
| 76 | +See error message above for details. |
| 77 | +Publishing can be re-attempted using the following command: |
| 78 | +heroku buildpacks:publish ${buildpack_registry_name@Q} ${new_git_tag@Q}" |
| 79 | +echo >&2 |
| 80 | +heroku buildpacks:versions "${buildpack_registry_name}" | head -n 3 |
0 commit comments