From 3c8db4eedf5603335ed5c0600edaa1f858ff3cc4 Mon Sep 17 00:00:00 2001 From: Edouard Bozon Date: Thu, 11 Jan 2024 10:32:07 +0100 Subject: [PATCH] docs(core): improve run commands in parallel section (#21083) Co-authored-by: Isaac Mann Co-authored-by: Altan Stalker --- docs/shared/monorepo-ci-github-actions.md | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/docs/shared/monorepo-ci-github-actions.md b/docs/shared/monorepo-ci-github-actions.md index 1ef0f1a3ae..bcfa5ad60f 100644 --- a/docs/shared/monorepo-ci-github-actions.md +++ b/docs/shared/monorepo-ci-github-actions.md @@ -163,22 +163,30 @@ jobs: - name: Run commands in parallel run: | + # initialize an array to store process IDs (PIDs) pids=() + + # function to run commands and store the PID + function run_command() { + local command=$1 + $command & # run the command in the background + pids+=($!) # store the PID of the background process + } + # list of commands to be run on main has env flag NX_CLOUD_DISTRIBUTED_EXECUTION set to false - NX_CLOUD_DISTRIBUTED_EXECUTION=false npx nx-cloud record -- npx nx format:check & pids+=($!) + run_command "NX_CLOUD_DISTRIBUTED_EXECUTION=false npx nx-cloud record -- npx nx format:check" # list of commands to be run on agents - npx nx affected -t lint,test,build --parallel=3 & - pids+=($!) + run_command "npx nx affected -t lint,test,build --parallel=3" - # run all commands in parallel and bail if one of them fails + # wait for all background processes to finish for pid in ${pids[*]}; do if ! wait $pid; then - exit 1 + exit 1 # exit with an error status if any process fails fi done - exit 0 + exit 0 # exits with success status if a all processes complete successfully agents: name: Agent ${{ matrix.agent }}