Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ANSI escape code wrapping of deprecation messages #477

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix ANSI escape code wrapping of multi-line deprecation messages
Previously the colourisation of the deprecation messages would break if
the output had prefixes added later (for example as happens when using
an untrusted builder, or when using Git).

Now, each line is wrapped in its own colour code + reset code, which resolves
the issue.
edmorley committed Mar 8, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
edmorley Ed Morley
commit 08129405590bf7a676e22e70003519388ed87234
17 changes: 12 additions & 5 deletions builder-classic-22/end-of-life-buildpack/bin/build
Original file line number Diff line number Diff line change
@@ -2,13 +2,20 @@

set -euo pipefail

ANSI_RED="\033[1;31m"
ANSI_RESET="\033[0m"

function display_error() {
local ansi_red="\033[1;31m"
local ansi_reset="\033[0m"
echo -e "\n${ansi_red}${1}${ansi_reset}\n" >&2
echo >&2
# We have to ANSI wrap each line separately to prevent breakage if line prefixes are added
# later (such as when the builder is untrusted, or when Git adds the "remote:" prefix).
while IFS= read -r line; do
echo -e "${ANSI_RED}${line}${ANSI_RESET}" >&2
done <<< "${1}"
echo >&2
}

read -r -d '' EOL_MESSAGE <<'EOF' || true
display_error "$(cat <<'EOF'
#######################################################################
WARNING: This builder image (heroku/builder-classic:22) is deprecated,
@@ -31,6 +38,6 @@ documentation for how to adjust the builder image used for your build.
#######################################################################
EOF
)"

display_error "${EOL_MESSAGE}"
exit 0
17 changes: 12 additions & 5 deletions buildpacks-20/end-of-life-buildpack/bin/build
Original file line number Diff line number Diff line change
@@ -2,13 +2,20 @@

set -euo pipefail

ANSI_RED="\033[1;31m"
ANSI_RESET="\033[0m"

function display_error() {
local ansi_red="\033[1;31m"
local ansi_reset="\033[0m"
echo -e "\n${ansi_red}${1}${ansi_reset}\n" >&2
echo >&2
# We have to ANSI wrap each line separately to prevent breakage if line prefixes are added
# later (such as when the builder is untrusted, or when Git adds the "remote:" prefix).
while IFS= read -r line; do
echo -e "${ANSI_RED}${line}${ANSI_RESET}" >&2
done <<< "${1}"
echo >&2
}

read -r -d '' EOL_MESSAGE <<'EOF' || true
display_error "$(cat <<'EOF'
#######################################################################
WARNING: This builder image (heroku/buildpacks:20) is deprecated,
@@ -31,6 +38,6 @@ documentation for how to adjust the builder image used for your build.
#######################################################################
EOF
)"

display_error "${EOL_MESSAGE}"
exit 0