From 7930debce32f8b56ed951cbbae6a45e0df9c9e76 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Tue, 30 Jun 2020 19:46:46 -0700 Subject: [PATCH 1/8] added ability to customize the buildup/builddown yarn command --- scripts/builddown | 2 +- scripts/buildup | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/builddown b/scripts/builddown index 181f08dbca389..4f484078e99fd 100755 --- a/scripts/builddown +++ b/scripts/builddown @@ -19,7 +19,7 @@ else fi fi -${scriptdir}/foreach.sh --down yarn build +${scriptdir}/foreach.sh --down yarn ${1:-build} ${scriptdir}/foreach.sh --reset echo "************************************************************" diff --git a/scripts/buildup b/scripts/buildup index 3fea629af9976..a640120392132 100755 --- a/scripts/buildup +++ b/scripts/buildup @@ -19,7 +19,7 @@ else fi fi -${scriptdir}/foreach.sh --up yarn build +${scriptdir}/foreach.sh --up yarn ${1:-build} ${scriptdir}/foreach.sh --reset echo "************************************************************" From 2929bdfcacc22128b76f2b848ec628580a0f2c97 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Tue, 30 Jun 2020 20:47:56 -0700 Subject: [PATCH 2/8] more robust argumenting --- scripts/builddown | 24 +++++++++++++++++------- scripts/buildup | 24 +++++++++++++++++------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/scripts/builddown b/scripts/builddown index 4f484078e99fd..128de6bbd3da3 100755 --- a/scripts/builddown +++ b/scripts/builddown @@ -7,19 +7,29 @@ echo " builddown usage:" echo " - execute 'builddown --resume' to resume after failure" echo " - execute 'builddown' to restart the build from the start" echo "" +echo " - execute 'buildup [yarn argument]' to run specifc script" +echo " - i.e. 'buildup test' to run topo. sorted 'yarn test'" +echo "" echo " for advanced usage, see ${scriptdir}/foreach.sh" echo "************************************************************" -if [ "$#" -eq 0 ]; then +RESUME=0 +YARN_ARGS="" + +for arg in "$@" +do + case "$arg" in + -r | --resume) RESUME=1 ;; + *) YARN_ARGS="$YARN_ARGS$arg" ;; + esac + shift +done + +if [ "$RESUME" -eq 0 ]; then ${scriptdir}/foreach.sh --reset -else - if [ "$1" != "--resume" ]; then - echo "Unknown option: $1" - exit 1 - fi fi -${scriptdir}/foreach.sh --down yarn ${1:-build} +${scriptdir}/foreach.sh --down yarn ${YARN_ARGS:-build} ${scriptdir}/foreach.sh --reset echo "************************************************************" diff --git a/scripts/buildup b/scripts/buildup index a640120392132..f3b43408ce350 100755 --- a/scripts/buildup +++ b/scripts/buildup @@ -7,19 +7,29 @@ echo " buildup usage:" echo " - execute 'buildup --resume' to resume after failure" echo " - execute 'buildup' to restart the build from the start" echo "" +echo " - execute 'buildup [yarn argument]' to run specifc script" +echo " - i.e. 'buildup test' to run topo. sorted 'yarn test'" +echo "" echo " for advanced usage, see ${scriptdir}/foreach.sh" echo "************************************************************" -if [ "$#" -eq 0 ]; then +RESUME=0 +YARN_ARGS="" + +for arg in "$@" +do + case "$arg" in + -r | --resume) RESUME=1 ;; + *) YARN_ARGS="$YARN_ARGS$arg" ;; + esac + shift +done + +if [ "$RESUME" -eq 0 ]; then ${scriptdir}/foreach.sh --reset -else - if [ "$1" != "--resume" ]; then - echo "Unknown option: $1" - exit 1 - fi fi -${scriptdir}/foreach.sh --up yarn ${1:-build} +${scriptdir}/foreach.sh --up yarn ${YARN_ARGS:-build} ${scriptdir}/foreach.sh --reset echo "************************************************************" From ad58b683486dff6671c8da94df4e1cd362190c1b Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Wed, 1 Jul 2020 12:27:43 -0700 Subject: [PATCH 3/8] adjust foreach.sh to allow for forcing reset + reset after successful finish --- scripts/builddown | 24 +++------- scripts/buildup | 24 +++------- scripts/foreach.sh | 109 ++++++++++++++++++++++++++++----------------- 3 files changed, 83 insertions(+), 74 deletions(-) diff --git a/scripts/builddown b/scripts/builddown index 128de6bbd3da3..683ba61491be0 100755 --- a/scripts/builddown +++ b/scripts/builddown @@ -7,29 +7,19 @@ echo " builddown usage:" echo " - execute 'builddown --resume' to resume after failure" echo " - execute 'builddown' to restart the build from the start" echo "" -echo " - execute 'buildup [yarn argument]' to run specifc script" -echo " - i.e. 'buildup test' to run topo. sorted 'yarn test'" -echo "" echo " for advanced usage, see ${scriptdir}/foreach.sh" echo "************************************************************" -RESUME=0 -YARN_ARGS="" - -for arg in "$@" -do - case "$arg" in - -r | --resume) RESUME=1 ;; - *) YARN_ARGS="$YARN_ARGS$arg" ;; - esac - shift -done - -if [ "$RESUME" -eq 0 ]; then +if [[ "$#" -eq 0 ]]; then ${scriptdir}/foreach.sh --reset +else + if [ "$1" != "--resume" ]; then + echo "Unknown option: $1" + exit 1 + fi fi -${scriptdir}/foreach.sh --down yarn ${YARN_ARGS:-build} +${scriptdir}/foreach.sh --down yarn build ${scriptdir}/foreach.sh --reset echo "************************************************************" diff --git a/scripts/buildup b/scripts/buildup index f3b43408ce350..5476e3e510aa6 100755 --- a/scripts/buildup +++ b/scripts/buildup @@ -7,29 +7,19 @@ echo " buildup usage:" echo " - execute 'buildup --resume' to resume after failure" echo " - execute 'buildup' to restart the build from the start" echo "" -echo " - execute 'buildup [yarn argument]' to run specifc script" -echo " - i.e. 'buildup test' to run topo. sorted 'yarn test'" -echo "" echo " for advanced usage, see ${scriptdir}/foreach.sh" echo "************************************************************" -RESUME=0 -YARN_ARGS="" - -for arg in "$@" -do - case "$arg" in - -r | --resume) RESUME=1 ;; - *) YARN_ARGS="$YARN_ARGS$arg" ;; - esac - shift -done - -if [ "$RESUME" -eq 0 ]; then +if [[ "$#" -eq 0 ]]; then ${scriptdir}/foreach.sh --reset +else + if [ "$1" != "--resume" ]; then + echo "Unknown option: $1" + exit 1 + fi fi -${scriptdir}/foreach.sh --up yarn ${YARN_ARGS:-build} +${scriptdir}/foreach.sh --up yarn build ${scriptdir}/foreach.sh --reset echo "************************************************************" diff --git a/scripts/foreach.sh b/scripts/foreach.sh index 1a389a5d60a3a..1ca795937ab92 100755 --- a/scripts/foreach.sh +++ b/scripts/foreach.sh @@ -13,13 +13,16 @@ # if a task fails, it will stop, and then to resume, simply run `foreach.sh` again (with or without the same command). # # to reset the session (either when all tasks finished or if you wish to run a different session), run: -# foreach.sh --reset +# foreach.sh [-r | --reset] +# +# to force a reset and run a session with the current, run: +# foreach.sh [-f | --force] [-u | --up || -d | --down] COMMAND # # to run the command only against the current module and its dependencies: -# foreach.sh --up COMMAND +# foreach.sh [-u | --up] COMMAND # # to run the command only against the current module and its consumers: -# foreach.sh --down COMMAND +# foreach.sh [-d | --down] COMMAND # # -------------------------------------------------------------------------------------------------- set -euo pipefail @@ -41,52 +44,78 @@ function success { printf "\e[32;5;81m$@\e[0m\n" } -if [[ "${1:-}" == "--reset" ]]; then - rm -f "${statedir}/.foreach."* - success "state cleared. you are free to start a new command." - exit 0 +function reset { + rm -f "${statedir}/.foreach."* + success "state cleared. you are free to start a new command." +} + +DIRECTION="" +RESET=0 +FORCE=0 +SKIP=0 +command_arg="" + +for arg in "$@" +do + case "$arg" in + -r | --reset) RESET=1 ;; + -s | --skip) SKIP=1 ;; + -f | --force) FORCE=1 ;; + -u | --up) DIRECTION="UP" ;; + -d | --down) DIRECTION="DOWN" ;; + *) command_arg="$command_arg$arg " ;; + esac + shift +done + +if [[ "$FORCE" -eq 1 && "$DIRECTION" == "" ]]; then + error "running force requires a direction to run." + exit 1 fi -if [[ "${1:-}" == "--skip" ]]; then - if [ ! -f ${statefile} ]; then - error "skip failed. no active sessions found." - exit 1 - fi - next=$(head -1 ${statefile}) - if [ -z "${next}" ]; then - error "skip failed. queue is empty. to reset:" - error " $0 --reset" - exit 1 - fi - tail -n +2 "${statefile}" > "${statefile}.tmp" - cp "${statefile}.tmp" "${statefile}" - success "directory '$next' skipped. re-run the original foreach command to resume." +if [[ "$RESET" -eq 1 || "$FORCE" -eq 1 ]]; then + reset + if [[ "$RESET" -eq 1 ]]; then exit 0 + fi +fi + +if [[ "$SKIP" -eq 1 ]]; then + if [ ! -f ${statefile} ]; then + error "skip failed. no active sessions found." + exit 1 + fi + next=$(head -1 ${statefile}) + if [ -z "${next}" ]; then + error "skip failed. queue is empty. to reset:" + error " $0 --reset" + exit 1 + fi + tail -n +2 "${statefile}" > "${statefile}.tmp" + cp "${statefile}.tmp" "${statefile}" + success "directory '$next' skipped. re-run the original foreach command to resume." + exit 0 fi direction="" direction_desc="" -if [[ "${1:-}" == "--up" || "${1:-}" == "--down" ]]; then - if [ ! -f package.json ]; then - echo "--up or --down can only be executed from within a module directory (looking for package.json)" - exit 1 - fi - - scope=$(node -p "require('./package.json').name") +if [[ "$DIRECTION" == "UP" || "$DIRECTION" == "DOWN" ]]; then + if [ ! -f package.json ]; then + error "--up or --down can only be executed from within a module directory (looking for package.json)" + exit 1 + fi - if [[ "${1:-}" == "--up" ]]; then - direction=" --scope ${scope} --include-dependencies" - direction_desc="('${scope}' and its dependencies)" - else # --down - direction=" --scope ${scope} --include-dependents" - direction_desc="('${scope}' and its consumers)" - fi + scope=$(node -p "require('./package.json').name") - shift + if [[ "$DIRECTION" == "UP" ]]; then + direction=" --scope ${scope} --include-dependencies" + direction_desc="('${scope}' and its dependencies)" + else # --down + direction=" --scope ${scope} --include-dependents" + direction_desc="('${scope}' and its consumers)" + fi fi -command_arg="${@:-}" - if [ -f "${statefile}" ] && [ -f "${commandfile}" ]; then command="$(cat ${commandfile})" if [ ! -z "${command_arg}" ] && [ "${command}" != "${command_arg}" ]; then @@ -110,8 +139,8 @@ fi next="$(head -n1 ${statefile})" if [ -z "${next}" ]; then - success "done (queue is empty). to reset:" - success " $0 --reset" + success "done (queue is empty). reseting queue:" + reset exit 0 fi From 04207356c27a4b50821e54da6d76c69db79d2813 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Wed, 1 Jul 2020 12:30:18 -0700 Subject: [PATCH 4/8] revert buildup/builddown --- scripts/builddown | 12 ++++++------ scripts/buildup | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/builddown b/scripts/builddown index 683ba61491be0..181f08dbca389 100755 --- a/scripts/builddown +++ b/scripts/builddown @@ -10,13 +10,13 @@ echo "" echo " for advanced usage, see ${scriptdir}/foreach.sh" echo "************************************************************" -if [[ "$#" -eq 0 ]]; then +if [ "$#" -eq 0 ]; then ${scriptdir}/foreach.sh --reset -else - if [ "$1" != "--resume" ]; then - echo "Unknown option: $1" - exit 1 - fi +else + if [ "$1" != "--resume" ]; then + echo "Unknown option: $1" + exit 1 + fi fi ${scriptdir}/foreach.sh --down yarn build diff --git a/scripts/buildup b/scripts/buildup index 5476e3e510aa6..3fea629af9976 100755 --- a/scripts/buildup +++ b/scripts/buildup @@ -10,13 +10,13 @@ echo "" echo " for advanced usage, see ${scriptdir}/foreach.sh" echo "************************************************************" -if [[ "$#" -eq 0 ]]; then +if [ "$#" -eq 0 ]; then ${scriptdir}/foreach.sh --reset -else - if [ "$1" != "--resume" ]; then - echo "Unknown option: $1" - exit 1 - fi +else + if [ "$1" != "--resume" ]; then + echo "Unknown option: $1" + exit 1 + fi fi ${scriptdir}/foreach.sh --up yarn build From a64e78b0e93bd47308ce8d3cb4c38d56b56695d1 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Thu, 9 Jul 2020 10:27:46 -0700 Subject: [PATCH 5/8] address partial suggestions --- scripts/foreach.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/foreach.sh b/scripts/foreach.sh index 1ca795937ab92..8bd19dc54f466 100755 --- a/scripts/foreach.sh +++ b/scripts/foreach.sh @@ -75,9 +75,10 @@ fi if [[ "$RESET" -eq 1 || "$FORCE" -eq 1 ]]; then reset - if [[ "$RESET" -eq 1 ]]; then - exit 0 - fi +fi + +if [[ "$RESET" -eq 1 ]]; then + exit 0 fi if [[ "$SKIP" -eq 1 ]]; then @@ -93,7 +94,7 @@ if [[ "$SKIP" -eq 1 ]]; then fi tail -n +2 "${statefile}" > "${statefile}.tmp" cp "${statefile}.tmp" "${statefile}" - success "directory '$next' skipped. re-run the original foreach command to resume." + success "directory '$next' skipped. re-run the original foreach command (without --force) to resume." exit 0 fi From 11d3f5d93310989a025f6b2f89c1a15256292eb2 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Mon, 13 Jul 2020 15:30:43 -0700 Subject: [PATCH 6/8] allow --reset --up/--down to automatically start new run --- scripts/builddown | 3 +-- scripts/buildup | 3 +-- scripts/foreach.sh | 15 ++++----------- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/scripts/builddown b/scripts/builddown index 181f08dbca389..d456b040d46ba 100755 --- a/scripts/builddown +++ b/scripts/builddown @@ -11,7 +11,7 @@ echo " for advanced usage, see ${scriptdir}/foreach.sh" echo "************************************************************" if [ "$#" -eq 0 ]; then - ${scriptdir}/foreach.sh --reset + ${scriptdir}/foreach.sh --reset --down yarn build else if [ "$1" != "--resume" ]; then echo "Unknown option: $1" @@ -20,7 +20,6 @@ else fi ${scriptdir}/foreach.sh --down yarn build -${scriptdir}/foreach.sh --reset echo "************************************************************" echo "builddown done" diff --git a/scripts/buildup b/scripts/buildup index 3fea629af9976..c0c8128bbcb61 100755 --- a/scripts/buildup +++ b/scripts/buildup @@ -11,7 +11,7 @@ echo " for advanced usage, see ${scriptdir}/foreach.sh" echo "************************************************************" if [ "$#" -eq 0 ]; then - ${scriptdir}/foreach.sh --reset + ${scriptdir}/foreach.sh --reset --up yarn build else if [ "$1" != "--resume" ]; then echo "Unknown option: $1" @@ -20,7 +20,6 @@ else fi ${scriptdir}/foreach.sh --up yarn build -${scriptdir}/foreach.sh --reset echo "************************************************************" echo "buildup done" diff --git a/scripts/foreach.sh b/scripts/foreach.sh index 8bd19dc54f466..19f8ccd8e6a02 100755 --- a/scripts/foreach.sh +++ b/scripts/foreach.sh @@ -16,7 +16,7 @@ # foreach.sh [-r | --reset] # # to force a reset and run a session with the current, run: -# foreach.sh [-f | --force] [-u | --up || -d | --down] COMMAND +# foreach.sh [-r | --reset] [-u | --up || -d | --down] COMMAND # # to run the command only against the current module and its dependencies: # foreach.sh [-u | --up] COMMAND @@ -51,7 +51,6 @@ function reset { DIRECTION="" RESET=0 -FORCE=0 SKIP=0 command_arg="" @@ -60,7 +59,6 @@ do case "$arg" in -r | --reset) RESET=1 ;; -s | --skip) SKIP=1 ;; - -f | --force) FORCE=1 ;; -u | --up) DIRECTION="UP" ;; -d | --down) DIRECTION="DOWN" ;; *) command_arg="$command_arg$arg " ;; @@ -68,16 +66,11 @@ do shift done -if [[ "$FORCE" -eq 1 && "$DIRECTION" == "" ]]; then - error "running force requires a direction to run." - exit 1 -fi - -if [[ "$RESET" -eq 1 || "$FORCE" -eq 1 ]]; then +if [[ "$RESET" -eq 1 ]]; then reset fi -if [[ "$RESET" -eq 1 ]]; then +if [[ "$RESET" -eq 1 && "$DIRECTION" == "" ]]; then exit 0 fi @@ -94,7 +87,7 @@ if [[ "$SKIP" -eq 1 ]]; then fi tail -n +2 "${statefile}" > "${statefile}.tmp" cp "${statefile}.tmp" "${statefile}" - success "directory '$next' skipped. re-run the original foreach command (without --force) to resume." + success "directory '$next' skipped. re-run the original foreach command (without --reset) to resume." exit 0 fi From e432a0e1c7d8aba262999168bab93dd5a837d4e6 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Thu, 30 Jul 2020 08:24:27 -0700 Subject: [PATCH 7/8] move foreach into else statement --- scripts/builddown | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/builddown b/scripts/builddown index d456b040d46ba..55c98e0fa9140 100755 --- a/scripts/builddown +++ b/scripts/builddown @@ -17,10 +17,9 @@ else echo "Unknown option: $1" exit 1 fi + ${scriptdir}/foreach.sh --down yarn build fi -${scriptdir}/foreach.sh --down yarn build - echo "************************************************************" echo "builddown done" echo "************************************************************" From e31c90738a7b3d26ca75a6d53b1d5104b8854ca5 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Thu, 30 Jul 2020 08:25:16 -0700 Subject: [PATCH 8/8] move foreach script into else statement --- scripts/buildup | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/buildup b/scripts/buildup index c0c8128bbcb61..e7dcd324d91ff 100755 --- a/scripts/buildup +++ b/scripts/buildup @@ -17,10 +17,9 @@ else echo "Unknown option: $1" exit 1 fi + ${scriptdir}/foreach.sh --up yarn build fi -${scriptdir}/foreach.sh --up yarn build - echo "************************************************************" echo "buildup done" echo "************************************************************"