Unverified Commit fc26df7e authored by Jeremy Morrell's avatar Jeremy Morrell Committed by GitHub

Add rest of lib/* to shellcheck (#609)

* Add rest of lib/* to shellcheck
parent 91e367f1
#!/usr/bin/env bash
kv_create() { kv_create() {
local f=$1 local f=$1
mkdir -p $(dirname $f) mkdir -p "$(dirname "$f")"
touch $f touch "$f"
} }
kv_clear() { kv_clear() {
local f=$1 local f=$1
echo "" > $f echo "" > "$f"
} }
kv_set() { kv_set() {
if [[ $# -eq 3 ]]; then if [[ $# -eq 3 ]]; then
local f=$1 local f=$1
if [[ -f $f ]]; then if [[ -f $f ]]; then
echo "$2=$3" >> $f echo "$2=$3" >> "$f"
fi fi
fi fi
} }
# get the value, but don't unwrap quotes
kv_get() { kv_get() {
if [[ $# -eq 2 ]]; then if [[ $# -eq 2 ]]; then
local f=$1 local f=$1
if [[ -f $f ]]; then if [[ -f $f ]]; then
grep "^$2=" $f | sed -e "s/^$2=//" | tail -n 1 grep "^$2=" "$f" | sed -e "s/^$2=//" | tail -n 1
fi fi
fi fi
} }
# get the value, but wrap it in quotes if it contains a space
kv_get_escaped() { kv_get_escaped() {
local value=$(kv_get $1 $2 $3) local value
value=$(kv_get "$1" "$2")
if [[ $value =~ [[:space:]]+ ]]; then if [[ $value =~ [[:space:]]+ ]]; then
echo "\"$value\"" echo "\"$value\""
else else
echo $value echo "$value"
fi fi
} }
...@@ -46,7 +48,7 @@ kv_keys() { ...@@ -46,7 +48,7 @@ kv_keys() {
# get list of keys # get list of keys
while IFS="=" read -r key value; do while IFS="=" read -r key value; do
keys+=("$key") keys+=("$key")
done < $f done < "$f"
echo "${keys[@]}" | tr ' ' '\n' | sort -u echo "${keys[@]}" | tr ' ' '\n' | sort -u
fi fi
...@@ -55,9 +57,9 @@ kv_keys() { ...@@ -55,9 +57,9 @@ kv_keys() {
kv_list() { kv_list() {
local f=$1 local f=$1
kv_keys $f | tr ' ' '\n' | while read -r key; do kv_keys "$f" | tr ' ' '\n' | while read -r key; do
if [[ -n $key ]]; then if [[ -n $key ]]; then
echo "$key=$(kv_get_escaped $f $key)" echo "$key=$(kv_get_escaped "$f" "$key")"
fi fi
done done
} }
#!/usr/bin/env bash
monitor_memory_usage() { monitor_memory_usage() {
local output_file="$1" local output_file="$1"
...@@ -12,7 +13,7 @@ monitor_memory_usage() { ...@@ -12,7 +13,7 @@ monitor_memory_usage() {
pid=$! pid=$!
# if this build process is SIGTERM'd # if this build process is SIGTERM'd
trap "kill -TERM $pid" TERM trap 'kill -TERM $pid' TERM
# set the peak memory usage to 0 to start # set the peak memory usage to 0 to start
peak="0" peak="0"
...@@ -29,7 +30,7 @@ monitor_memory_usage() { ...@@ -29,7 +30,7 @@ monitor_memory_usage() {
done done
# ps gives us kb, let's convert to mb for convenience # ps gives us kb, let's convert to mb for convenience
echo "$(($peak / 1024))" > $output_file echo "$((peak / 1024))" > "$output_file"
# After wait returns we can get the exit code of $command # After wait returns we can get the exit code of $command
wait $pid wait $pid
...@@ -43,16 +44,18 @@ monitor_memory_usage() { ...@@ -43,16 +44,18 @@ monitor_memory_usage() {
} }
monitor() { monitor() {
local peak_mem_output start
local command_name=$1 local command_name=$1
shift shift
local command=( "$@" ) local command=( "$@" )
local peak_mem_output=$(mktemp)
local start=$(nowms) peak_mem_output=$(mktemp)
start=$(nowms)
# execute the subcommand and save the peak memory usage # execute the subcommand and save the peak memory usage
monitor_memory_usage $peak_mem_output "${command[@]}" monitor_memory_usage "$peak_mem_output" "${command[@]}"
mtime "exec.$command_name.time" "${start}" mtime "exec.$command_name.time" "${start}"
mmeasure "exec.$command_name.memory" "$(cat $peak_mem_output)" mmeasure "exec.$command_name.memory" "$(cat "$peak_mem_output")"
} }
#!/usr/bin/env bash
# TODO: Merge these with the output helpers in buildpack-stdlib: # TODO: Merge these with the output helpers in buildpack-stdlib:
# https://github.com/heroku/buildpack-stdlib # https://github.com/heroku/buildpack-stdlib
......
#!/usr/bin/env bash
get_node_major_version() { get_node_major_version() {
local node_version="$(node --version)" local node_version
node_version="$(node --version)"
# major_string will be ex: "6." "8." "10" # major_string will be ex: "6." "8." "10"
local major_string=${node_version:1:2} local major_string=${node_version:1:2}
# strip any "."s from major_string # strip any "."s from major_string
local major=${major_string//.} local major=${major_string//.}
echo $major echo "$major"
} }
install_plugin() { install_plugin() {
local major
local bp_dir="$1" local bp_dir="$1"
local build_dir="$2" local build_dir="$2"
local major=$(get_node_major_version) major=$(get_node_major_version)
local plugin="${bp_dir}/plugin/heroku-nodejs-plugin-node-${major}.tar.gz" local plugin="${bp_dir}/plugin/heroku-nodejs-plugin-node-${major}.tar.gz"
# If we have a version of the plugin compiled for this version of node, and the # If we have a version of the plugin compiled for this version of node, and the
...@@ -19,6 +23,6 @@ install_plugin() { ...@@ -19,6 +23,6 @@ install_plugin() {
# It will be included at runtime once the user opts into the Node metrics feature # It will be included at runtime once the user opts into the Node metrics feature
if [[ -f "${plugin}" ]] && [[ -z "$HEROKU_SKIP_NODE_PLUGIN" ]]; then if [[ -f "${plugin}" ]] && [[ -z "$HEROKU_SKIP_NODE_PLUGIN" ]]; then
mkdir -p "${build_dir}/.heroku/" mkdir -p "${build_dir}/.heroku/"
tar -xzf ${plugin} -C "${build_dir}/.heroku/" tar -xzf "${plugin}" -C "${build_dir}/.heroku/"
fi fi
} }
...@@ -2,8 +2,7 @@ test: heroku-18 heroku-16 cedar-14 ...@@ -2,8 +2,7 @@ test: heroku-18 heroku-16 cedar-14
shellcheck: shellcheck:
@shellcheck -x bin/compile bin/detect bin/release bin/test bin/test-compile @shellcheck -x bin/compile bin/detect bin/release bin/test bin/test-compile
@shellcheck -x lib/binaries.sh lib/build-data.sh lib/cache.sh lib/dependencies.sh lib/environment.sh lib/json.sh lib/failure.sh @shellcheck -x lib/**
@echo TODO shellcheck -x lib/**/*.sh
@echo TODO shellcheck -x ci-profile/**/*.sh @echo TODO shellcheck -x ci-profile/**/*.sh
@echo TODO shellcheck -x etc/**/*.sh @echo TODO shellcheck -x etc/**/*.sh
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment