forked from heroku/heroku-buildpack-apt
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
bin/report
script to capture buildpack metadata (heroku#110)
* Add `bin/report` script to capture buildpack metadata [W-15039947](https://gus.lightning.force.com/lightning/r/a07EE00001k7v4BYAQ/view)
- Loading branch information
1 parent
6d1fa4a
commit 31acd20
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
## Unreleased | ||
|
||
- Add `bin/report` script to capture buildpack metadata | ||
|
||
## 2021-03-10 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[@]}" |