Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
H
heroku-buildpack-nodejs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
heroku-buildpack-nodejs
Commits
99ebd7cb
Unverified
Commit
99ebd7cb
authored
Mar 27, 2019
by
Jeremy Morrell
Committed by
GitHub
Mar 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename build-data module to metadata and update the callsites (#629)
parent
e9c7ff6c
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
180 additions
and
152 deletions
+180
-152
compile
bin/compile
+17
-17
build-data.sh
lib/build-data.sh
+0
-66
builddata.sh
lib/builddata.sh
+53
-0
cache.sh
lib/cache.sh
+3
-3
dependencies.sh
lib/dependencies.sh
+18
-18
failure.sh
lib/failure.sh
+2
-2
metadata.sh
lib/metadata.sh
+58
-17
monitor.sh
lib/monitor.sh
+2
-2
unit
test/unit
+27
-27
No files found.
bin/compile
View file @
99ebd7cb
...
@@ -50,8 +50,8 @@ source "$BP_DIR/lib/uuid.sh"
...
@@ -50,8 +50,8 @@ source "$BP_DIR/lib/uuid.sh"
source
"
$BP_DIR
/lib/kvstore.sh"
source
"
$BP_DIR
/lib/kvstore.sh"
# shellcheck source=lib/metadata.sh
# shellcheck source=lib/metadata.sh
source
"
$BP_DIR
/lib/metadata.sh"
source
"
$BP_DIR
/lib/metadata.sh"
# shellcheck source=lib/build
-
data.sh
# shellcheck source=lib/builddata.sh
source
"
$BP_DIR
/lib/build
-
data.sh"
source
"
$BP_DIR
/lib/builddata.sh"
export
PATH
=
"
$BUILD_DIR
/.heroku/node/bin:
$BUILD_DIR
/.heroku/yarn/bin"
:
$PATH
export
PATH
=
"
$BUILD_DIR
/.heroku/node/bin:
$BUILD_DIR
/.heroku/yarn/bin"
:
$PATH
...
@@ -86,7 +86,7 @@ handle_failure() {
...
@@ -86,7 +86,7 @@ handle_failure() {
trap
'handle_failure'
ERR
trap
'handle_failure'
ERR
### Initalize metadata store
### Initalize metadata store
bd
_create
"
$CACHE_DIR
"
meta
_create
"
$CACHE_DIR
"
### Check initial state
### Check initial state
...
@@ -137,13 +137,13 @@ install_bins() {
...
@@ -137,13 +137,13 @@ install_bins() {
npm_engine
=
$(
read_json
"
$BUILD_DIR
/package.json"
".engines.npm"
)
npm_engine
=
$(
read_json
"
$BUILD_DIR
/package.json"
".engines.npm"
)
yarn_engine
=
$(
read_json
"
$BUILD_DIR
/package.json"
".engines.yarn"
)
yarn_engine
=
$(
read_json
"
$BUILD_DIR
/package.json"
".engines.yarn"
)
bd
_set
"node-version-request"
"
$node_engine
"
meta
_set
"node-version-request"
"
$node_engine
"
bd
_set
"npm-version-request"
"
$npm_engine
"
meta
_set
"npm-version-request"
"
$npm_engine
"
bd
_set
"yarn-version-request"
"
$yarn_engine
"
meta
_set
"yarn-version-request"
"
$yarn_engine
"
bd
_set
"node-version-request"
"
$node_engine
"
meta
_set
"node-version-request"
"
$node_engine
"
bd
_set
"npm-version-request"
"
$npm_engine
"
meta
_set
"npm-version-request"
"
$npm_engine
"
bd
_set
"yarn-version-request"
"
$yarn_engine
"
meta
_set
"yarn-version-request"
"
$yarn_engine
"
if
[
-n
"
$iojs_engine
"
]
;
then
if
[
-n
"
$iojs_engine
"
]
;
then
echo
"engines.iojs (package.json):
$iojs_engine
(iojs)"
echo
"engines.iojs (package.json):
$iojs_engine
(iojs)"
...
@@ -169,7 +169,7 @@ install_bins() {
...
@@ -169,7 +169,7 @@ install_bins() {
monitor
"install-npm-binary"
install_npm
"
$npm_engine
"
"
$BUILD_DIR
/.heroku/node"
$NPM_LOCK
monitor
"install-npm-binary"
install_npm
"
$npm_engine
"
"
$BUILD_DIR
/.heroku/node"
$NPM_LOCK
node_version
=
"
$(
node
--version
)
"
node_version
=
"
$(
node
--version
)
"
mcount
"version.node.
$node_version
"
mcount
"version.node.
$node_version
"
bd
_set
"node-version"
"
$node_version
"
meta
_set
"node-version"
"
$node_version
"
fi
fi
# Download yarn if there is a yarn.lock file or if the user
# Download yarn if there is a yarn.lock file or if the user
...
@@ -181,10 +181,10 @@ install_bins() {
...
@@ -181,10 +181,10 @@ install_bins() {
if
$YARN
;
then
if
$YARN
;
then
mcount
"version.yarn.
$(
yarn
--version
)
"
mcount
"version.yarn.
$(
yarn
--version
)
"
bd
_set
"yarn-version"
"
$(
yarn
--version
)
"
meta
_set
"yarn-version"
"
$(
yarn
--version
)
"
else
else
mcount
"version.npm.
$(
npm
--version
)
"
mcount
"version.npm.
$(
npm
--version
)
"
bd
_set
"npm-version"
"
$(
npm
--version
)
"
meta
_set
"npm-version"
"
$(
npm
--version
)
"
fi
fi
warn_old_npm
warn_old_npm
...
@@ -235,7 +235,7 @@ restore_cache() {
...
@@ -235,7 +235,7 @@ restore_cache() {
fi
fi
mcount
"cache.
$cache_status
"
mcount
"cache.
$cache_status
"
bd
_set
"cache-status"
"
$cache_status
"
meta
_set
"cache-status"
"
$cache_status
"
}
}
restore_cache | output
"
$LOG_FILE
"
restore_cache | output
"
$LOG_FILE
"
...
@@ -305,7 +305,7 @@ summarize_build() {
...
@@ -305,7 +305,7 @@ summarize_build() {
fi
fi
mmeasure
'modules.size'
"
$(
measure_size
)
"
mmeasure
'modules.size'
"
$(
measure_size
)
"
bd
_set
"node-modules-size"
"
$(
measure_size
)
"
meta
_set
"node-modules-size"
"
$(
measure_size
)
"
}
}
install_plugin
"
$BP_DIR
"
"
$BUILD_DIR
"
install_plugin
"
$BP_DIR
"
"
$BUILD_DIR
"
...
@@ -313,8 +313,8 @@ install_plugin "$BP_DIR" "$BUILD_DIR"
...
@@ -313,8 +313,8 @@ install_plugin "$BP_DIR" "$BUILD_DIR"
header
"Build succeeded!"
| output
"
$LOG_FILE
"
header
"Build succeeded!"
| output
"
$LOG_FILE
"
mcount
"compile"
mcount
"compile"
summarize_build | output
"
$LOG_FILE
"
summarize_build | output
"
$LOG_FILE
"
bd
_set
"node-build-success"
"true"
meta
_set
"node-build-success"
"true"
bd
_time
"build-time"
"
$build_start_time
"
meta
_time
"build-time"
"
$build_start_time
"
warn_no_start
"
$BUILD_DIR
"
warn_no_start
"
$BUILD_DIR
"
warn_unmet_dep
"
$LOG_FILE
"
warn_unmet_dep
"
$LOG_FILE
"
...
@@ -327,4 +327,4 @@ echo ""
...
@@ -327,4 +327,4 @@ echo ""
echo
" Read more: https://devcenter.heroku.com/changelog-items/1573"
echo
" Read more: https://devcenter.heroku.com/changelog-items/1573"
echo
""
echo
""
log_
build
_data
>>
"
$BUILDPACK_LOG_FILE
"
log_
meta
_data
>>
"
$BUILDPACK_LOG_FILE
"
lib/build-data.sh
deleted
100644 → 0
View file @
e9c7ff6c
#!/usr/bin/env bash
# variable shared by this whole module
BUILD_DATA_FILE
=
""
PREVIOUS_BUILD_DATA_FILE
=
""
bd_create
()
{
local
cache_dir
=
"
$1
"
BUILD_DATA_FILE
=
"
$cache_dir
/build-data/nodejs"
PREVIOUS_BUILD_DATA_FILE
=
"
$cache_dir
/build-data/nodejs-prev"
# if the file already exists because it's from the last build, save it
if
[[
-f
"
$BUILD_DATA_FILE
"
]]
;
then
cp
"
$BUILD_DATA_FILE
"
"
$PREVIOUS_BUILD_DATA_FILE
"
fi
kv_create
"
$BUILD_DATA_FILE
"
# make sure this doesnt grow over time
kv_clear
"
$BUILD_DATA_FILE
"
}
bd_get
()
{
kv_get
"
$BUILD_DATA_FILE
"
"
$1
"
}
bd_set
()
{
kv_set
"
$BUILD_DATA_FILE
"
"
$1
"
"
$2
"
}
# similar to mtime from stdlib
bd_time
()
{
local
key
=
"
$1
"
local
start
=
"
$2
"
local
end
=
"
${
3
:-$(
nowms
)}
"
local time
time
=
"
$(
echo
"
${
start
}
"
"
${
end
}
"
|
awk
'{ printf "%.3f", ($2 - $1)/1000 }'
)
"
kv_set
"
$BUILD_DATA_FILE
"
"
$key
"
"
$time
"
}
# similar to mtime from stdlib
bd_time
()
{
local
key
=
"
$1
"
local
start
=
"
$2
"
local
end
=
"
${
3
:-$(
nowms
)}
"
local time
time
=
"
$(
echo
"
$start
"
"
$end
"
|
awk
'{ printf "%.3f", ($2 - $1)/1000 }'
)
"
kv_set
"
$BUILD_DATA_FILE
"
"
$1
"
"
$time
"
}
# Retrieve a value from a previous build if it exists
# This is useful to give the user context about what changed if the
# build has failed. Ex:
# - changed stacks
# - deployed with a new major version of Node
# - etc
bd_prev_get
()
{
kv_get
"
$PREVIOUS_BUILD_DATA_FILE
"
"
$1
"
}
log_build_data
()
{
# print all values on one line in logfmt format
# https://brandur.org/logfmt
# the echo call ensures that all values are printed on a single line
# shellcheck disable=SC2005 disable=SC2046
echo
$(
kv_list
"
$BUILD_DATA_FILE
"
)
}
lib/builddata.sh
0 → 100644
View file @
99ebd7cb
#!/usr/bin/env bash
log_initial_state
()
{
if
"
$YARN
"
;
then
meta_set
"node-package-manager"
"yarn"
meta_set
"has-node-lock-file"
"true"
else
meta_set
"node-package-manager"
"npm"
meta_set
"has-node-lock-file"
"
$NPM_LOCK
"
fi
meta_set
"stack"
"
$STACK
"
}
generate_uuids
()
{
# generate a unique id for each build
meta_set
"build-uuid"
"
$(
uuid
)
"
# propagate an app-uuid forward unless the cache is cleared
if
[[
-n
"
$(
meta_prev_get
"app-uuid"
)
"
]]
;
then
meta_set
"app-uuid"
"
$(
meta_prev_get
"app-uuid"
)
"
else
meta_set
"app-uuid"
"
$(
uuid
)
"
fi
}
log_build_script_opt_in
()
{
local
opted_in
=
"
$1
"
local
build_dir
=
"
$2
"
local
has_build_script has_heroku_build_script
has_build_script
=
$(
read_json
"
$build_dir
/package.json"
".scripts.build"
)
has_heroku_build_script
=
$(
read_json
"
$build_dir
/package.json"
".scripts[
\"
heroku-postbuild
\"
]"
)
# if this app will be affected by the change
if
[[
-z
"
$has_heroku_build_script
"
]]
&&
[[
-n
"
$has_build_script
"
]]
;
then
mcount
"affected-by-build-change"
if
[[
"
$opted_in
"
=
"true"
]]
;
then
mcount
"affected-by-build-change-opted-in"
meta_set
"affected-but-opted-in"
"true"
else
meta_set
"affected-but-opted-in"
"false"
fi
fi
if
[[
"
$opted_in
"
=
true
]]
;
then
meta_set
"build-script-opt-in"
"true"
else
meta_set
"build-script-opt-in"
"false"
fi
}
\ No newline at end of file
lib/cache.sh
View file @
99ebd7cb
...
@@ -114,13 +114,13 @@ save_default_cache_directories() {
...
@@ -114,13 +114,13 @@ save_default_cache_directories() {
# bower_components
# bower_components
if
[[
-e
"
$build_dir
/bower_components"
]]
;
then
if
[[
-e
"
$build_dir
/bower_components"
]]
;
then
mcount
"cache.saved-bower-components"
mcount
"cache.saved-bower-components"
bd
_set
"cached-bower-components"
"true"
meta
_set
"cached-bower-components"
"true"
echo
"- bower_components"
echo
"- bower_components"
mkdir
-p
"
$cache_dir
/node/cache/bower_components"
mkdir
-p
"
$cache_dir
/node/cache/bower_components"
cp
-a
"
$build_dir
/bower_components"
"
$(
dirname
"
$cache_dir
/node/cache/bower_components"
)
"
cp
-a
"
$build_dir
/bower_components"
"
$(
dirname
"
$cache_dir
/node/cache/bower_components"
)
"
fi
fi
bd
_set
"node-custom-cache-dirs"
"false"
meta
_set
"node-custom-cache-dirs"
"false"
}
}
save_custom_cache_directories
()
{
save_custom_cache_directories
()
{
...
@@ -142,5 +142,5 @@ save_custom_cache_directories() {
...
@@ -142,5 +142,5 @@ save_custom_cache_directories() {
fi
fi
done
done
bd
_set
"node-custom-cache-dirs"
"true"
meta
_set
"node-custom-cache-dirs"
"true"
}
}
lib/dependencies.sh
View file @
99ebd7cb
...
@@ -69,15 +69,15 @@ log_build_scripts() {
...
@@ -69,15 +69,15 @@ log_build_scripts() {
heroku_postbuild
=
$(
read_json
"
$build_dir
/package.json"
".scripts[
\"
heroku-postbuild
\"
]"
)
heroku_postbuild
=
$(
read_json
"
$build_dir
/package.json"
".scripts[
\"
heroku-postbuild
\"
]"
)
postinstall
=
$(
read_json
"
$build_dir
/package.json"
".scripts[
\"
heroku-postbuild
\"
]"
)
postinstall
=
$(
read_json
"
$build_dir
/package.json"
".scripts[
\"
heroku-postbuild
\"
]"
)
bd
_set
"build-script"
"
$build
"
meta
_set
"build-script"
"
$build
"
bd
_set
"postinstall-script"
"
$postinstall
"
meta
_set
"postinstall-script"
"
$postinstall
"
bd
_set
"heroku-prebuild-script"
"
$heroku_prebuild
"
meta
_set
"heroku-prebuild-script"
"
$heroku_prebuild
"
bd
_set
"heroku-postbuild-script"
"
$heroku_prebuild
"
meta
_set
"heroku-postbuild-script"
"
$heroku_prebuild
"
bd
_set
"build-script"
"
$build
"
meta
_set
"build-script"
"
$build
"
bd
_set
"postinstall-script"
"
$postinstall
"
meta
_set
"postinstall-script"
"
$postinstall
"
bd
_set
"heroku-prebuild-script"
"
$heroku_prebuild
"
meta
_set
"heroku-prebuild-script"
"
$heroku_prebuild
"
bd
_set
"heroku-postbuild-script"
"
$heroku_prebuild
"
meta
_set
"heroku-postbuild-script"
"
$heroku_prebuild
"
if
[
-n
"
$build
"
]
;
then
if
[
-n
"
$build
"
]
;
then
mcount
"scripts.build"
mcount
"scripts.build"
...
@@ -143,20 +143,20 @@ yarn_prune_devdependencies() {
...
@@ -143,20 +143,20 @@ yarn_prune_devdependencies() {
if
[
"
$NODE_ENV
"
==
"test"
]
;
then
if
[
"
$NODE_ENV
"
==
"test"
]
;
then
echo
"Skipping because NODE_ENV is 'test'"
echo
"Skipping because NODE_ENV is 'test'"
bd
_set
"skipped-prune"
"true"
meta
_set
"skipped-prune"
"true"
return
0
return
0
elif
[
"
$NODE_ENV
"
!=
"production"
]
;
then
elif
[
"
$NODE_ENV
"
!=
"production"
]
;
then
echo
"Skipping because NODE_ENV is not 'production'"
echo
"Skipping because NODE_ENV is not 'production'"
bd
_set
"skipped-prune"
"true"
meta
_set
"skipped-prune"
"true"
return
0
return
0
elif
[
-n
"
$YARN_PRODUCTION
"
]
;
then
elif
[
-n
"
$YARN_PRODUCTION
"
]
;
then
echo
"Skipping because YARN_PRODUCTION is '
$YARN_PRODUCTION
'"
echo
"Skipping because YARN_PRODUCTION is '
$YARN_PRODUCTION
'"
bd
_set
"skipped-prune"
"true"
meta
_set
"skipped-prune"
"true"
return
0
return
0
else
else
cd
"
$build_dir
"
||
return
cd
"
$build_dir
"
||
return
monitor
"yarn-prune"
yarn
install
--frozen-lockfile
--ignore-engines
--ignore-scripts
--prefer-offline
2>&1
monitor
"yarn-prune"
yarn
install
--frozen-lockfile
--ignore-engines
--ignore-scripts
--prefer-offline
2>&1
bd
_set
"skipped-prune"
"false"
meta
_set
"skipped-prune"
"false"
fi
fi
}
}
...
@@ -207,15 +207,15 @@ npm_prune_devdependencies() {
...
@@ -207,15 +207,15 @@ npm_prune_devdependencies() {
if
[
"
$NODE_ENV
"
==
"test"
]
;
then
if
[
"
$NODE_ENV
"
==
"test"
]
;
then
echo
"Skipping because NODE_ENV is 'test'"
echo
"Skipping because NODE_ENV is 'test'"
bd
_set
"skipped-prune"
"true"
meta
_set
"skipped-prune"
"true"
return
0
return
0
elif
[
"
$NODE_ENV
"
!=
"production"
]
;
then
elif
[
"
$NODE_ENV
"
!=
"production"
]
;
then
echo
"Skipping because NODE_ENV is not 'production'"
echo
"Skipping because NODE_ENV is not 'production'"
bd
_set
"skipped-prune"
"true"
meta
_set
"skipped-prune"
"true"
return
0
return
0
elif
[
-n
"
$NPM_CONFIG_PRODUCTION
"
]
;
then
elif
[
-n
"
$NPM_CONFIG_PRODUCTION
"
]
;
then
echo
"Skipping because NPM_CONFIG_PRODUCTION is '
$NPM_CONFIG_PRODUCTION
'"
echo
"Skipping because NPM_CONFIG_PRODUCTION is '
$NPM_CONFIG_PRODUCTION
'"
bd
_set
"skipped-prune"
"true"
meta
_set
"skipped-prune"
"true"
return
0
return
0
elif
[
"
$npm_version
"
==
"5.3.0"
]
;
then
elif
[
"
$npm_version
"
==
"5.3.0"
]
;
then
mcount
"skip-prune-issue-npm-5.3.0"
mcount
"skip-prune-issue-npm-5.3.0"
...
@@ -224,7 +224,7 @@ npm_prune_devdependencies() {
...
@@ -224,7 +224,7 @@ npm_prune_devdependencies() {
echo
""
echo
""
echo
"You can silence this warning by updating to at least npm 5.7.1 in your package.json"
echo
"You can silence this warning by updating to at least npm 5.7.1 in your package.json"
echo
"https://devcenter.heroku.com/articles/nodejs-support#specifying-an-npm-version"
echo
"https://devcenter.heroku.com/articles/nodejs-support#specifying-an-npm-version"
bd
_set
"skipped-prune"
"true"
meta
_set
"skipped-prune"
"true"
return
0
return
0
elif
[
"
$npm_version
"
==
"5.6.0"
]
||
elif
[
"
$npm_version
"
==
"5.6.0"
]
||
[
"
$npm_version
"
==
"5.5.1"
]
||
[
"
$npm_version
"
==
"5.5.1"
]
||
...
@@ -239,11 +239,11 @@ npm_prune_devdependencies() {
...
@@ -239,11 +239,11 @@ npm_prune_devdependencies() {
echo
""
echo
""
echo
"You can silence this warning by updating to at least npm 5.7.1 in your package.json"
echo
"You can silence this warning by updating to at least npm 5.7.1 in your package.json"
echo
"https://devcenter.heroku.com/articles/nodejs-support#specifying-an-npm-version"
echo
"https://devcenter.heroku.com/articles/nodejs-support#specifying-an-npm-version"
bd
_set
"skipped-prune"
"true"
meta
_set
"skipped-prune"
"true"
return
0
return
0
else
else
cd
"
$build_dir
"
||
return
cd
"
$build_dir
"
||
return
monitor
"npm-prune"
npm prune
--userconfig
"
$build_dir
/.npmrc"
2>&1
monitor
"npm-prune"
npm prune
--userconfig
"
$build_dir
/.npmrc"
2>&1
bd
_set
"skipped-prune"
"false"
meta
_set
"skipped-prune"
"false"
fi
fi
}
}
lib/failure.sh
View file @
99ebd7cb
...
@@ -513,9 +513,9 @@ warn_prebuilt_modules() {
...
@@ -513,9 +513,9 @@ warn_prebuilt_modules() {
if
[
-e
"
$build_dir
/node_modules"
]
;
then
if
[
-e
"
$build_dir
/node_modules"
]
;
then
warning
"node_modules checked into source control"
"https://blog.heroku.com/node-habits-2016#9-only-git-the-important-bits"
warning
"node_modules checked into source control"
"https://blog.heroku.com/node-habits-2016#9-only-git-the-important-bits"
mcount
'warnings.modules.prebuilt'
mcount
'warnings.modules.prebuilt'
bd
_set
"checked-in-node-modules"
"true"
meta
_set
"checked-in-node-modules"
"true"
else
else
bd
_set
"checked-in-node-modules"
"false"
meta
_set
"checked-in-node-modules"
"false"
fi
fi
}
}
...
...
lib/metadata.sh
View file @
99ebd7cb
#!/usr/bin/env bash
#!/usr/bin/env bash
log_initial_state
()
{
# variable shared by this whole module
if
"
$YARN
"
;
then
BUILD_DATA_FILE
=
""
bd_set
"node-package-manager"
"yarn"
PREVIOUS_BUILD_DATA_FILE
=
""
bd_set
"has-node-lock-file"
"true"
else
meta_create
()
{
bd_set
"node-package-manager"
"npm"
local
cache_dir
=
"
$1
"
bd_set
"has-node-lock-file"
"
$NPM_LOCK
"
BUILD_DATA_FILE
=
"
$cache_dir
/build-data/nodejs"
PREVIOUS_BUILD_DATA_FILE
=
"
$cache_dir
/build-data/nodejs-prev"
# if the file already exists because it's from the last build, save it
if
[[
-f
"
$BUILD_DATA_FILE
"
]]
;
then
cp
"
$BUILD_DATA_FILE
"
"
$PREVIOUS_BUILD_DATA_FILE
"
fi
fi
bd_set
"stack"
"
$STACK
"
kv_create
"
$BUILD_DATA_FILE
"
# make sure this doesnt grow over time
kv_clear
"
$BUILD_DATA_FILE
"
}
meta_get
()
{
kv_get
"
$BUILD_DATA_FILE
"
"
$1
"
}
}
generate_uuids
()
{
meta_set
()
{
# generate a unique id for each build
kv_set
"
$BUILD_DATA_FILE
"
"
$1
"
"
$2
"
bd_set
"build-uuid"
"
$(
uuid
)
"
}
# propagate an app-uuid forward unless the cache is cleared
# similar to mtime from stdlib
if
[[
-n
"
$(
bd_prev_get
"app-uuid"
)
"
]]
;
then
meta_time
()
{
bd_set
"app-uuid"
"
$(
bd_prev_get
"app-uuid"
)
"
local
key
=
"
$1
"
else
local
start
=
"
$2
"
bd_set
"app-uuid"
"
$(
uuid
)
"
local
end
=
"
${
3
:-$(
nowms
)}
"
fi
local time
time
=
"
$(
echo
"
${
start
}
"
"
${
end
}
"
|
awk
'{ printf "%.3f", ($2 - $1)/1000 }'
)
"
kv_set
"
$BUILD_DATA_FILE
"
"
$key
"
"
$time
"
}
# similar to mtime from stdlib
meta_time
()
{
local
key
=
"
$1
"
local
start
=
"
$2
"
local
end
=
"
${
3
:-$(
nowms
)}
"
local time
time
=
"
$(
echo
"
$start
"
"
$end
"
|
awk
'{ printf "%.3f", ($2 - $1)/1000 }'
)
"
kv_set
"
$BUILD_DATA_FILE
"
"
$1
"
"
$time
"
}
# Retrieve a value from a previous build if it exists
# This is useful to give the user context about what changed if the
# build has failed. Ex:
# - changed stacks
# - deployed with a new major version of Node
# - etc
meta_prev_get
()
{
kv_get
"
$PREVIOUS_BUILD_DATA_FILE
"
"
$1
"
}
log_meta_data
()
{
# print all values on one line in logfmt format
# https://brandur.org/logfmt
# the echo call ensures that all values are printed on a single line
# shellcheck disable=SC2005 disable=SC2046
echo
$(
kv_list
"
$BUILD_DATA_FILE
"
)
}
}
lib/monitor.sh
View file @
99ebd7cb
...
@@ -59,6 +59,6 @@ monitor() {
...
@@ -59,6 +59,6 @@ monitor() {
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
"
)
"
bd
_time
"
$command_name
-time"
"
$start
"
meta
_time
"
$command_name
-time"
"
$start
"
bd
_set
"
$command_name
-memory"
"
$(
cat
"
$peak_mem_output
"
)
"
meta
_set
"
$command_name
-memory"
"
$(
cat
"
$peak_mem_output
"
)
"
}
}
test/unit
View file @
99ebd7cb
...
@@ -171,71 +171,71 @@ testKeyValueNoFile() {
...
@@ -171,71 +171,71 @@ testKeyValueNoFile() {
testBuildData
()
{
testBuildData
()
{
local
cache_dir
=
$(
mktemp
-d
)
local
cache_dir
=
$(
mktemp
-d
)
bd
_create
$cache_dir
meta
_create
$cache_dir
bd
_set
"test"
"foo"
meta
_set
"test"
"foo"
assertEquals
"test=foo"
"
$(
log_
build
_data
)
"
assertEquals
"test=foo"
"
$(
log_
meta
_data
)
"
bd
_set
"test"
"different-foo"
meta
_set
"test"
"different-foo"
assertEquals
"test=different-foo"
"
$(
log_
build
_data
)
"
assertEquals
"test=different-foo"
"
$(
log_
meta
_data
)
"
bd
_set
"foo"
"value with spaces"
meta
_set
"foo"
"value with spaces"
assertEquals
"foo=
\"
value with spaces
\"
test=different-foo"
"
$(
log_
build
_data
)
"
assertEquals
"foo=
\"
value with spaces
\"
test=different-foo"
"
$(
log_
meta
_data
)
"
# values are printed with the keys sorted alphabetically
# values are printed with the keys sorted alphabetically
# this isn't required, and this test serves as documentation
# this isn't required, and this test serves as documentation
bd
_set
"a"
"this should come first"
meta
_set
"a"
"this should come first"
assertEquals
"a=
\"
this should come first
\"
foo=
\"
value with spaces
\"
test=different-foo"
"
$(
log_
build
_data
)
"
assertEquals
"a=
\"
this should come first
\"
foo=
\"
value with spaces
\"
test=different-foo"
"
$(
log_
meta
_data
)
"
# dates generated by running `nowms; sleep 10; nowms`
# dates generated by running `nowms; sleep 10; nowms`
bd
_time
"time"
"1545178120033"
"1545178130043"
meta
_time
"time"
"1545178120033"
"1545178130043"
assertEquals
"10.010"
"
$(
bd
_get
time
)
"
assertEquals
"10.010"
"
$(
meta
_get
time
)
"
# dates generated by running `nowms; sleep 1; nowms`
# dates generated by running `nowms; sleep 1; nowms`
bd
_time
"time"
"1545178503025"
"1545178504027"
meta
_time
"time"
"1545178503025"
"1545178504027"
assertEquals
"1.002"
"
$(
bd
_get
time
)
"
assertEquals
"1.002"
"
$(
meta
_get
time
)
"
# dates generated by running `nowms; sleep 30; nowms`
# dates generated by running `nowms; sleep 30; nowms`
bd
_time
"time"
"1545178521204"
"1545178551206"
meta
_time
"time"
"1545178521204"
"1545178551206"
assertEquals
"30.002"
"
$(
bd
_get
time
)
"
assertEquals
"30.002"
"
$(
meta
_get
time
)
"
}
}
testBuildDataPreviousBuild
()
{
testBuildDataPreviousBuild
()
{
local
cache_dir
=
$(
mktemp
-d
)
local
cache_dir
=
$(
mktemp
-d
)
# the first time, there will be no previous build file
# the first time, there will be no previous build file
bd
_create
"
$cache_dir
"
meta
_create
"
$cache_dir
"
assertContains
"nodejs"
"
$BUILD_DATA_FILE
"
assertContains
"nodejs"
"
$BUILD_DATA_FILE
"
assertContains
"nodejs-prev"
"
$PREVIOUS_BUILD_DATA_FILE
"
assertContains
"nodejs-prev"
"
$PREVIOUS_BUILD_DATA_FILE
"
assertFileExists
"
$BUILD_DATA_FILE
"
assertFileExists
"
$BUILD_DATA_FILE
"
# set a value in the build data file
# set a value in the build data file
bd
_set
"test"
"foo"
meta
_set
"test"
"foo"
assertFileContains
"test=foo"
"
$BUILD_DATA_FILE
"
assertFileContains
"test=foo"
"
$BUILD_DATA_FILE
"
assertFileDoesNotExist
"
$PREVIOUS_BUILD_DATA_FILE
"
assertFileDoesNotExist
"
$PREVIOUS_BUILD_DATA_FILE
"
assertEquals
"
$(
bd
_get
test
)
"
"foo"
assertEquals
"
$(
meta
_get
test
)
"
"foo"
assertEquals
"
$(
bd
_prev_get
test
)
"
""
assertEquals
"
$(
meta
_prev_get
test
)
"
""
# the second time this is called (cache restored)
# the second time this is called (cache restored)
# there will be a previous build file
# there will be a previous build file
bd
_create
"
$cache_dir
"
meta
_create
"
$cache_dir
"
assertFileExists
"
$BUILD_DATA_FILE
"
assertFileExists
"
$BUILD_DATA_FILE
"
assertFileExists
"
$PREVIOUS_BUILD_DATA_FILE
"
assertFileExists
"
$PREVIOUS_BUILD_DATA_FILE
"
# the data stored in the previous build should now be in the second file
# the data stored in the previous build should now be in the second file
assertFileNotContains
"test=foo"
"
$BUILD_DATA_FILE
"
assertFileNotContains
"test=foo"
"
$BUILD_DATA_FILE
"
assertFileContains
"test=foo"
"
$PREVIOUS_BUILD_DATA_FILE
"
assertFileContains
"test=foo"
"
$PREVIOUS_BUILD_DATA_FILE
"
assertEquals
"
$(
bd
_get
test
)
"
""
assertEquals
"
$(
meta
_get
test
)
"
""
assertEquals
"
$(
bd
_prev_get
test
)
"
"foo"
assertEquals
"
$(
meta
_prev_get
test
)
"
"foo"
bd
_set
"test"
"bar"
meta
_set
"test"
"bar"
# doing it once more does not result in an error
# doing it once more does not result in an error
bd
_create
"
$cache_dir
"
meta
_create
"
$cache_dir
"
assertFileExists
"
$BUILD_DATA_FILE
"
assertFileExists
"
$BUILD_DATA_FILE
"
assertFileExists
"
$PREVIOUS_BUILD_DATA_FILE
"
assertFileExists
"
$PREVIOUS_BUILD_DATA_FILE
"
assertEquals
"
$(
bd
_prev_get
test
)
"
"bar"
assertEquals
"
$(
meta
_prev_get
test
)
"
"bar"
assertEquals
"
$(
bd
_get
test
)
"
""
assertEquals
"
$(
meta
_get
test
)
"
""
}
}
testWebConcurrencyProfileScript
()
{
testWebConcurrencyProfileScript
()
{
...
@@ -371,8 +371,8 @@ source "$(pwd)"/lib/json.sh
...
@@ -371,8 +371,8 @@ source "$(pwd)"/lib/json.sh
source
"
$(
pwd
)
"
/lib/monitor.sh
source
"
$(
pwd
)
"
/lib/monitor.sh
source
"
$(
pwd
)
"
/lib/output.sh
source
"
$(
pwd
)
"
/lib/output.sh
source
"
$(
pwd
)
"
/lib/kvstore.sh
source
"
$(
pwd
)
"
/lib/kvstore.sh
source
"
$(
pwd
)
"
/lib/build-data.sh
source
"
$(
pwd
)
"
/lib/experiments.sh
source
"
$(
pwd
)
"
/lib/experiments.sh
source
"
$(
pwd
)
"
/lib/metadata.sh
source
"
$(
pwd
)
"
/profile/WEB_CONCURRENCY.sh
source
"
$(
pwd
)
"
/profile/WEB_CONCURRENCY.sh
# testing utils
# testing utils
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment