From f34eaa35509ea4be5b1a6f75446b8faa69ef7d56 Mon Sep 17 00:00:00 2001 From: Benjamin Rasmussen Date: Wed, 18 Oct 2023 23:14:15 +0200 Subject: [PATCH 1/2] Tweak the waiting, to have an actual max and a detection limit. --- action.yml | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/action.yml b/action.yml index 01d6085..5e3401b 100644 --- a/action.yml +++ b/action.yml @@ -34,8 +34,8 @@ inputs: type: string PSH_DETECTION_WAIT: - description: "How long should we maximum wait for PSH to detect the push? If the branch doesnt exist in the PlatformSH GIT Remote, this is how long the action will take. Actually inactive environments get detected instantly. Default: 120 seconds." - default: 120 + description: "How long should we maximum wait for PSH to detect the push? If the branch doesnt exist in the PlatformSH GIT Remote, this is how long the action will take. Actually inactive environments get detected instantly. Default: 60 seconds." + default: 60 required: false type: integer @@ -72,23 +72,26 @@ runs: ~/.platformsh/bin/platform activity:cancel --type=environment.cron --all; \ fi - TRIES=0 + DETECTION_TRIES=0 + TOTAL_TRIES=0 SUCCESS=0 DELAY_BETWEEN_ATTEMPTS=5; - MAX_SECONDS=${{ inputs.PSH_DETECTION_WAIT }}; - MAX_TRIES=$(( MAX_SECONDS / DELAY_BETWEEN_ATTEMPTS )); - - while [ $TRIES -le $MAX_TRIES ]; do \ - TRIES=$((TRIES+1)); \ - ACTS=$(~/.platformsh/bin/platform activities --columns=state --incomplete --no-header --format=plain --no-interaction --type=${{ inputs.ACTIVITY_TYPES }} 2>&1 || true); \ - if [[ "$ACTS" =~ "Specified environment not found" ]]; then break; fi; \ - if [[ "$ACTS" =~ "Exception]" ]]; then break; fi; \ + MAX_DETECTION_SECONDS=${{ inputs.PSH_DETECTION_WAIT }}; + MAX_DETECTION_TRIES=$(( MAX_DETECTION_SECONDS / DELAY_BETWEEN_ATTEMPTS )); + MAX_TRIES=$(( 600 / DELAY_BETWEEN_ATTEMPTS )); + + while [ $DETECTION_TRIES -le $MAX_DETECTION_TRIES ] && [ $TOTAL_TRIES -le $MAX_TRIES ]; do \ + DETECTION_TRIES=$((DETECTION_TRIES+1)); \ + TOTAL_TRIES=$((TOTAL_TRIES+1)); \ + ACTS=$(~/.platformsh/bin/platform activities --columns=id,state --incomplete --no-header --no-interaction --type=${{ inputs.ACTIVITY_TYPES }} 2>&1 || true); \ + if [[ "$ACTS" =~ "pending" || "$ACTS" =~ "in progress" ]]; then TOTAL_TRIES=0; fi; \ if [[ "$ACTS" =~ "No activities found" ]]; then SUCCESS=1; break; fi; \ echo ""; \ echo "Current deploy state(s):"; \ echo "$ACTS"; \ + echo "-----------------"; \ sleep $DELAY_BETWEEN_ATTEMPTS; \ done \ From bdf735249d3fcfd4cae6ba8d50eb0bab9e73bafe Mon Sep 17 00:00:00 2001 From: Benjamin Rasmussen Date: Thu, 19 Oct 2023 23:38:47 +0200 Subject: [PATCH 2/2] Fix waiting period, and log more info. --- action.yml | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/action.yml b/action.yml index 5e3401b..4c62307 100644 --- a/action.yml +++ b/action.yml @@ -58,8 +58,7 @@ runs: run: | set +e - echo "Giving psh a chance to detect the git update.." - sleep 10s + sleep 5s export PLATFORMSH_CLI_NO_INTERACTION=1; export PLATFORM_PROJECT=${{ inputs.PLATFORMSH_ID }}; @@ -73,28 +72,41 @@ runs: fi DETECTION_TRIES=0 - TOTAL_TRIES=0 + TRIES=0 SUCCESS=0 DELAY_BETWEEN_ATTEMPTS=5; MAX_DETECTION_SECONDS=${{ inputs.PSH_DETECTION_WAIT }}; MAX_DETECTION_TRIES=$(( MAX_DETECTION_SECONDS / DELAY_BETWEEN_ATTEMPTS )); - MAX_TRIES=$(( 600 / DELAY_BETWEEN_ATTEMPTS )); + MAX_WAIT_SECONDS=900; + echo "We will wait for a maximum of $MAX_DETECTION_SECONDS secs for PSH to detect a deploy, and a max of $MAX_WAIT_SECONDS secs for the deployment to finish." + MAX_TRIES=$(( 900 / DELAY_BETWEEN_ATTEMPTS )); - while [ $DETECTION_TRIES -le $MAX_DETECTION_TRIES ] && [ $TOTAL_TRIES -le $MAX_TRIES ]; do \ + echo "We will now detect the PSH activities. You can view the deployment log using"; + echo " platform activity:log [ID] -p ${{ inputs.PLATFORMSH_ID }} -e ${{ inputs.ENVIRONMENT_NAME }}"; + echo "----------------------"; + echo ""; + + while [ $DETECTION_TRIES -le $MAX_DETECTION_TRIES ] && [ $TRIES -le $MAX_TRIES ]; do \ DETECTION_TRIES=$((DETECTION_TRIES+1)); \ - TOTAL_TRIES=$((TOTAL_TRIES+1)); \ - ACTS=$(~/.platformsh/bin/platform activities --columns=id,state --incomplete --no-header --no-interaction --type=${{ inputs.ACTIVITY_TYPES }} 2>&1 || true); \ - if [[ "$ACTS" =~ "pending" || "$ACTS" =~ "in progress" ]]; then TOTAL_TRIES=0; fi; \ + TRIES=$((TRIES+1)); \ + ACTS=$(~/.platformsh/bin/platform activities --format=plain --columns=id,state --incomplete --no-header --no-interaction --type=${{ inputs.ACTIVITY_TYPES }} 2>&1 || true); \ + if [[ "$ACTS" =~ "pending" || "$ACTS" =~ "in progress" ]]; then \ + DETECTION_TRIES=0; \ + else \ + echo "detect tries: $DETECTION_TRIES / $MAX_DETECTION_TRIES"; \ + fi; \ + if [[ "$ACTS" =~ "No activities found" ]]; then SUCCESS=1; break; fi; \ - echo ""; \ - echo "Current deploy state(s):"; \ + echo "total tries: $TRIES / $MAX_TRIES"; \ + echo "$ACTS"; \ - echo "-----------------"; \ + echo "----------------------"; \ sleep $DELAY_BETWEEN_ATTEMPTS; \ - done \ + done + echo "" STATUS=$(~/.platformsh/bin/platform env:info status 2>&1 || true) @@ -111,7 +123,7 @@ runs: CURL_HTTP_STATUS=$(curl -L -s -o /dev/null -w "%{http_code}" $URL) if [[ "$CURL_HTTP_STATUS" != "200" ]]; then \ - echo "PlatformSH reports the environment is ready, but cURL could not connect to it."; \ + echo "PlatformSH reports the environment is ready, but cURL could not connect to it. You may have pushed a broken build."; \ echo "URL: $URL"; \ echo "HTTP Status Code: $CURL_HTTP_STATUS"; \ exit 2; \