From d0b32897ef72762e045c41b988997032a02ebef7 Mon Sep 17 00:00:00 2001 From: Jerry Kindall <52084730+Jerry-AWS@users.noreply.github.com> Date: Thu, 30 Jul 2020 09:08:52 -0700 Subject: [PATCH 1/2] ShellScriptAction prop name -> actionName name is the old name for actionName --- packages/@aws-cdk/pipelines/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/pipelines/README.md b/packages/@aws-cdk/pipelines/README.md index ba5085e94e1d0..ff92b365d56e0 100644 --- a/packages/@aws-cdk/pipelines/README.md +++ b/packages/@aws-cdk/pipelines/README.md @@ -376,7 +376,7 @@ const pipeline = new CdkPipeline(this, 'Pipeline', { }); const validationAction = new ShellScriptAction({ - name: 'TestUsingSourceArtifact', + actionName: 'TestUsingSourceArtifact', additionalArtifacts: [sourceArtifact], // 'test.sh' comes from the source repository From 3cf6a946d7c2d3766fbfa97ef9504af62f7e1a5b Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Thu, 30 Jul 2020 09:30:28 -0700 Subject: [PATCH 2/2] chore(scripts): allow --reset --up/--down to automatically run script (#8826) **[ISSUE]** Honestly, kind of miss being able to use `lerna` for any kind of npm test through parameters with the old `builddown`. Wanted to be able to run something like `builddown build+test` or `builddown test`. **[APPROACH]** Added a `-r | --reset` flag to allow the `foreach.sh` script to reset and run in one line like `builddown`/`buildup`. **[NOTE]** Won't change anyone's current workflow because `--reset` is still in codebase. Also arguments for the script aren't restricted by order (i.e. `foreach.sh --reset --up yarn build ` and `builddown yarn build --up --reset` will produce the same results)! ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- scripts/builddown | 6 +-- scripts/buildup | 6 +-- scripts/foreach.sh | 105 +++++++++++++++++++++++++++------------------ 3 files changed, 68 insertions(+), 49 deletions(-) diff --git a/scripts/builddown b/scripts/builddown index 181f08dbca389..55c98e0fa9140 100755 --- a/scripts/builddown +++ b/scripts/builddown @@ -11,17 +11,15 @@ 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" exit 1 fi + ${scriptdir}/foreach.sh --down yarn build fi -${scriptdir}/foreach.sh --down yarn build -${scriptdir}/foreach.sh --reset - echo "************************************************************" echo "builddown done" echo "************************************************************" diff --git a/scripts/buildup b/scripts/buildup index 3fea629af9976..e7dcd324d91ff 100755 --- a/scripts/buildup +++ b/scripts/buildup @@ -11,17 +11,15 @@ 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" exit 1 fi + ${scriptdir}/foreach.sh --up yarn build fi -${scriptdir}/foreach.sh --up yarn build -${scriptdir}/foreach.sh --reset - echo "************************************************************" echo "buildup done" echo "************************************************************" diff --git a/scripts/foreach.sh b/scripts/foreach.sh index 1a389a5d60a3a..19f8ccd8e6a02 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 [-r | --reset] [-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,72 @@ 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 +SKIP=0 +command_arg="" + +for arg in "$@" +do + case "$arg" in + -r | --reset) RESET=1 ;; + -s | --skip) SKIP=1 ;; + -u | --up) DIRECTION="UP" ;; + -d | --down) DIRECTION="DOWN" ;; + *) command_arg="$command_arg$arg " ;; + esac + shift +done + +if [[ "$RESET" -eq 1 ]]; then + reset 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." - exit 0 +if [[ "$RESET" -eq 1 && "$DIRECTION" == "" ]]; then + exit 0 +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 (without --reset) 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 +133,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