mirror of
https://github.com/ChainSafe/lodestar.git
synced 2026-01-10 08:08:16 -05:00
Add build if changed script (#3543)
* Add build if changed script * Remove stale comment
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -56,4 +56,7 @@ packages/lodestar/.tmpdb/
|
||||
# Git artifacts
|
||||
packages/cli/.git-data.json
|
||||
|
||||
# Build artifacts
|
||||
.last_build_unixsec
|
||||
|
||||
temp/
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
"build:lib:watch": "lerna run build:lib:watch --parallel",
|
||||
"build:types:watch": "lerna run build:types:watch --parallel",
|
||||
"build:watch": "run-p build:lib:watch build:types:watch",
|
||||
"build:ifchanged": "lerna exec -- ../../scripts/build_if_changed.sh",
|
||||
"lint": "lerna run lint --no-bail",
|
||||
"check-types": "lerna run check-types --no-bail",
|
||||
"coverage": "lerna run coverage --no-bail",
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"lib/**/*.js.map"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "exit 0",
|
||||
"check-types": "tsc --noEmit",
|
||||
"download-spec-tests": "node -r ts-node/register test/downloadTests.ts",
|
||||
"check-tests": "mocha test/checkTests.test.ts",
|
||||
|
||||
0
packages/spec-test-runner/src/.empty
Normal file
0
packages/spec-test-runner/src/.empty
Normal file
48
scripts/build_if_changed.sh
Executable file
48
scripts/build_if_changed.sh
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Writes the last build time in packages/*/last_build_unixsec
|
||||
# Then reads the file and checks if there has been any changes since then
|
||||
# If so, do a build
|
||||
|
||||
# Exit on errors
|
||||
set -e
|
||||
|
||||
LAST_BUILD_FILEPATH=.last_build_unixsec
|
||||
|
||||
# Check being run from a package directory
|
||||
[ ! -d ./src ] && echo "Must be run in a package dir, no src"
|
||||
[ ! -f ./package.json ] && echo "Must be run in a package dir, no package.json"
|
||||
|
||||
CURRENT_UNIXSEC=$(date +%s)
|
||||
|
||||
if [ -f "$LAST_BUILD_FILEPATH" ]; then
|
||||
# Exists
|
||||
LAST_BUILD_UNIXSEC=$(cat $LAST_BUILD_FILEPATH)
|
||||
SINCE_LAST_BUILD_SEC=$(($CURRENT_UNIXSEC - $LAST_BUILD_UNIXSEC))
|
||||
SINCE_LAST_BUILD_MIN=$(($SINCE_LAST_BUILD_SEC / 60 + 1))
|
||||
# Only with DEBUG=true, log math
|
||||
if [ ! -z "$DEBUG" ]; then
|
||||
echo "LAST_BUILD_UNIXSEC: $LAST_BUILD_UNIXSEC SINCE_LAST_BUILD_SEC: $SINCE_LAST_BUILD_SEC SINCE_LAST_BUILD_MIN: $SINCE_LAST_BUILD_MIN"
|
||||
fi
|
||||
|
||||
CHANGED_FILES=$(find src package.json -cmin -$SINCE_LAST_BUILD_MIN)
|
||||
if [ -z "$CHANGED_FILES" ]; then
|
||||
# Empty, no changes
|
||||
SHOULD_BUILD=false
|
||||
else
|
||||
# Not empty, build
|
||||
SHOULD_BUILD=true
|
||||
fi
|
||||
else
|
||||
# Does not exist, always build
|
||||
SHOULD_BUILD=true
|
||||
fi
|
||||
|
||||
# If there are changes, build
|
||||
if [ "$SHOULD_BUILD" = true ]; then
|
||||
npm run build
|
||||
fi
|
||||
|
||||
# Persist current time after a successful build
|
||||
echo $CURRENT_UNIXSEC > $LAST_BUILD_FILEPATH
|
||||
|
||||
Reference in New Issue
Block a user