Skip to content

Commit

Permalink
Add bin/report script to capture buildpack metadata (heroku#110)
Browse files Browse the repository at this point in the history
* Add `bin/report` script to capture buildpack metadata

[W-15039947](https://gus.lightning.force.com/lightning/r/a07EE00001k7v4BYAQ/view)
  • Loading branch information
colincasey authored and Frzk committed May 13, 2024
1 parent 6d1fa4a commit 31acd20
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Add `bin/report` script to capture buildpack metadata

## 2021-03-10

Expand Down
38 changes: 38 additions & 0 deletions bin/report
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# bin/report <build-dir> <cache-dir> <env-dir>

### Configure environment

set -o errexit # always exit on error
set -o pipefail # don't ignore exit codes when piping output

BUILD_DIR=${1:-}

packages=()
custom_packages=()
custom_repositories=()

while IFS= read -r line; do
if grep --silent -e "^:repo:" <<< "${line}"; then
custom_repositories+=("${line//:repo:/}")
elif [[ $line == *deb ]]; then
custom_packages+=("${line}")
else
packages+=("${line}")
fi
done < <(grep --invert-match -e "^#" -e "^\s*$" "${BUILD_DIR}/Aptfile")

output_key_value() {
local key value
key="$1"
shift
# sort & join the array values with a ',' then escape both '\' and '"' characters
value=$(printf '%s\n' "$@" | sort | tr '\n' ',' | sed 's/,$/\n/' | sed 's/\\/\\\\/g' | sed 's/"/\\"/g')
if [[ -n "${value}" ]]; then
echo "$key: \"$value\""
fi
}

output_key_value "packages" "${packages[@]}"
output_key_value "custom_packages" "${custom_packages[@]}"
output_key_value "custom_repositories" "${custom_repositories[@]}"

0 comments on commit 31acd20

Please sign in to comment.