-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run lint and unit tests on Buildkite (#17)
- Loading branch information
Showing
2 changed files
with
73 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash -eu | ||
|
||
PLATFORM=$(uname -s) | ||
ARCHITECTURE=$(uname -m) | ||
NODE_VERSION=$(node --version) | ||
PACKAGE_HASH=$(hash_file package-lock.json) | ||
|
||
CACHEKEY="$BUILDKITE_PIPELINE_SLUG-npm-$PLATFORM-$ARCHITECTURE-node-$NODE_VERSION-$PACKAGE_HASH" | ||
|
||
LOCAL_NPM_CACHE=./vendor/npm | ||
mkdir -p $LOCAL_NPM_CACHE | ||
echo "--- :npm: Set npm to use $LOCAL_NPM_CACHE for cache" | ||
npm set cache $LOCAL_NPM_CACHE | ||
echo "npm cache set to $(npm get cache)" | ||
|
||
echo "--- :npm: Restore npm cache if present" | ||
restore_cache "$CACHEKEY" | ||
|
||
echo "--- :npm: Install Node dependencies" | ||
|
||
MAX_SOCKETS=15 # Default value from npm | ||
|
||
# To avoid constant ECONNRESET errors a limit is set for Linux, | ||
# as this is not happening with the Mac jobs. | ||
# This issue is being tracked here: | ||
# https://github.com/npm/cli/issues/4652 | ||
if [ "$PLATFORM" = "Linux" ]; then | ||
MAX_SOCKETS=1 | ||
fi | ||
|
||
npm ci \ | ||
--unsafe-perm \ | ||
--prefer-offline \ | ||
--no-audit \ | ||
--no-progress \ | ||
--maxsockets "$MAX_SOCKETS" \ | ||
"$@" | ||
|
||
echo "--- :npm: Save cache if necessary" | ||
# Notice that we don't cache the local node_modules. | ||
# Those get regenerated by npm ci as per Node reccomendations. | ||
# What we are caching is the root npm folder, which stores pacakge downloads so they are available if the package.json resolution demands them. | ||
# | ||
# npm stores temporary files in ~/.npm that we don't want to extract because they might run into naming conflicts. | ||
# So, before archiving it, we remove those tmp files. | ||
# | ||
# Example: https://buildkite.com/automattic/gutenberg-mobile/builds/8857#018e37eb-7afc-4280-b736-cba76f02f1a3/524 | ||
rm -rf "$LOCAL_NPM_CACHE/_cacache/tmp" | ||
save_cache "$LOCAL_NPM_CACHE" "$CACHEKEY" |
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