Unverified Commit 2be1b8d8 authored by Jeremy Morrell's avatar Jeremy Morrell Committed by GitHub

Move more files to shellcheck (#605)

* Add lib/build-data.sh and lib/cache.sh to shellcheck
parent e2a1b61c
...@@ -165,8 +165,8 @@ install_bins | output "$LOG_FILE" ...@@ -165,8 +165,8 @@ install_bins | output "$LOG_FILE"
restore_cache() { restore_cache() {
local cache_status cache_directories local cache_status cache_directories
cache_status="$(get_cache_status)" cache_status="$(get_cache_status "$CACHE_DIR")"
cache_directories="$(get_cache_directories)" cache_directories="$(get_cache_directories "$BUILD_DIR")"
if $YARN; then if $YARN; then
if [ -e "$BUILD_DIR/node_modules" ]; then if [ -e "$BUILD_DIR/node_modules" ]; then
...@@ -213,7 +213,7 @@ build_dependencies() { ...@@ -213,7 +213,7 @@ build_dependencies() {
run_if_present 'heroku-prebuild' run_if_present 'heroku-prebuild'
cache_status="$(get_cache_status)" cache_status="$(get_cache_status "$CACHE_DIR")"
start=$(nowms) start=$(nowms)
if $YARN; then if $YARN; then
...@@ -243,9 +243,9 @@ build_dependencies | output "$LOG_FILE" ...@@ -243,9 +243,9 @@ build_dependencies | output "$LOG_FILE"
cache_build() { cache_build() {
local cache_directories local cache_directories
cache_directories="$(get_cache_directories)" cache_directories="$(get_cache_directories "$BUILD_DIR")"
clear_cache clear_cache "$CACHE_DIR"
if ! ${NODE_MODULES_CACHE:-true}; then if ! ${NODE_MODULES_CACHE:-true}; then
# we've already warned that caching is disabled in the restore step # we've already warned that caching is disabled in the restore step
# so be silent here # so be silent here
...@@ -257,7 +257,7 @@ cache_build() { ...@@ -257,7 +257,7 @@ cache_build() {
header "Caching build" header "Caching build"
save_custom_cache_directories "$BUILD_DIR" "$CACHE_DIR" "$cache_directories" save_custom_cache_directories "$BUILD_DIR" "$CACHE_DIR" "$cache_directories"
fi fi
save_signature save_signature "$CACHE_DIR"
} }
cache_build | output "$LOG_FILE" cache_build | output "$LOG_FILE"
......
#!/usr/bin/env bash
# variable shared by this whole module # variable shared by this whole module
BUILD_DATA_FILE="" BUILD_DATA_FILE=""
bd_create() { bd_create() {
local cache_dir="$1" local cache_dir="$1"
BUILD_DATA_FILE="$cache_dir/build-data/node" BUILD_DATA_FILE="$cache_dir/build-data/node"
kv_create $BUILD_DATA_FILE kv_create "$BUILD_DATA_FILE"
} }
bd_get() { bd_get() {
kv_get $BUILD_DATA_FILE "$1" kv_get "$BUILD_DATA_FILE" "$1"
} }
bd_set() { bd_set() {
kv_set $BUILD_DATA_FILE "$1" "$2" kv_set "$BUILD_DATA_FILE" "$1" "$2"
} }
log_build_data() { log_build_data() {
# print all values on one line in logfmt format # print all values on one line in logfmt format
# https://brandur.org/logfmt # https://brandur.org/logfmt
echo $(kv_list $BUILD_DATA_FILE) # the echo call ensures that all values are printed on a single line
# shellcheck disable=SC2005 disable=SC2046
echo $(kv_list "$BUILD_DATA_FILE")
} }
#!/usr/bin/env bash #!/usr/bin/env bash
source $BP_DIR/lib/binaries.sh
create_signature() { create_signature() {
echo "v2; ${STACK}; $(node --version); $(npm --version); $(yarn --version 2>/dev/null || true); ${PREBUILD}" echo "v2; ${STACK}; $(node --version); $(npm --version); $(yarn --version 2>/dev/null || true); ${PREBUILD}"
} }
save_signature() { save_signature() {
create_signature > $CACHE_DIR/node/signature local cache_dir="$1"
create_signature > "$cache_dir/node/signature"
} }
load_signature() { load_signature() {
if test -f $CACHE_DIR/node/signature; then local cache_dir="$1"
cat $CACHE_DIR/node/signature if test -f "$cache_dir/node/signature"; then
cat "$cache_dir/node/signature"
else else
echo "" echo ""
fi fi
} }
get_cache_status() { get_cache_status() {
local cache_dir="$1"
if ! ${NODE_MODULES_CACHE:-true}; then if ! ${NODE_MODULES_CACHE:-true}; then
echo "disabled" echo "disabled"
elif ! test -d "${CACHE_DIR}/node/"; then elif ! test -d "$cache_dir/node/"; then
echo "not-found" echo "not-found"
elif [ "$(create_signature)" != "$(load_signature)" ]; then elif [ "$(create_signature)" != "$(load_signature "$cache_dir")" ]; then
echo "new-signature" echo "new-signature"
else else
echo "valid" echo "valid"
...@@ -31,9 +32,10 @@ get_cache_status() { ...@@ -31,9 +32,10 @@ get_cache_status() {
} }
get_cache_directories() { get_cache_directories() {
local build_dir="$1"
local dirs1 dirs2 local dirs1 dirs2
dirs1=$(read_json "$BUILD_DIR/package.json" ".cacheDirectories | .[]?") dirs1=$(read_json "$build_dir/package.json" ".cacheDirectories | .[]?")
dirs2=$(read_json "$BUILD_DIR/package.json" ".cache_directories | .[]?") dirs2=$(read_json "$build_dir/package.json" ".cache_directories | .[]?")
if [ -n "$dirs1" ]; then if [ -n "$dirs1" ]; then
echo "$dirs1" echo "$dirs1"
...@@ -88,9 +90,10 @@ restore_custom_cache_directories() { ...@@ -88,9 +90,10 @@ restore_custom_cache_directories() {
} }
clear_cache() { clear_cache() {
rm -rf $CACHE_DIR/node local cache_dir="$1"
mkdir -p $CACHE_DIR/node rm -rf "$cache_dir/node"
mkdir -p $CACHE_DIR/node/cache mkdir -p "$cache_dir/node"
mkdir -p "$cache_dir/node/cache"
} }
save_default_cache_directories() { save_default_cache_directories() {
......
...@@ -2,7 +2,7 @@ test: heroku-18 heroku-16 cedar-14 ...@@ -2,7 +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 @shellcheck -x lib/binaries.sh lib/build-data.sh lib/cache.sh
@echo TODO shellcheck -x lib/**/*.sh @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