diff --git a/.github/actions/wait-for-deployment/action.yml b/.github/actions/wait-for-deployment/action.yml index aee1c6dbaf..af25f7578a 100644 --- a/.github/actions/wait-for-deployment/action.yml +++ b/.github/actions/wait-for-deployment/action.yml @@ -1,18 +1,18 @@ name: Wait for Next.js Deployment description: Waits for a Pantheon Next.js deployment to complete by polling the build API -# A more mature way to fulfill this need will be done via https://getpantheon.atlassian.net/browse/DEVX-6685 +# A more mature way to fulfill this need will be done via https://getpantheon.atlassian.net/browse/DEVX-6685 inputs: pantheon_site_name: - description: The Pantheon site name + description: The Pantheon site machine name required: true env_name: description: The environment name (e.g., dev, pr-123) required: true - max_wait_minutes: - description: Maximum number of minutes to wait for deployment + max_wait_seconds: + description: Maximum number of seconds to wait for deployment required: false - default: '30' + default: '1200' pantheon_machine_token: description: Pantheon machine token for API authentication required: true @@ -47,92 +47,8 @@ runs: env: PANTHEON_SITE_NAME: ${{ inputs.pantheon_site_name }} ENV_NAME: ${{ inputs.env_name }} - MAX_WAIT_MINUTES: ${{ inputs.max_wait_minutes }} + MAX_WAIT_SECONDS: ${{ inputs.max_wait_minutes }} PANTHEON_MACHINE_TOKEN: ${{ inputs.pantheon_machine_token }} EXPECTED_COMMIT: ${{ inputs.expected_commit }} run: | - echo "Waiting for Pantheon deployment to complete..." - echo "Site: ${PANTHEON_SITE_NAME}.${ENV_NAME}" - echo "Expected commit: ${EXPECTED_COMMIT}" - - # Get site UUID - SITE_UUID=$(terminus site:info "${PANTHEON_SITE_NAME}" --field=id) - echo "Site UUID: $SITE_UUID" - - # Exchange machine token for API session token - SESSION_RESPONSE=$(curl -s -X POST https://api.pantheon.io/v0/authorize/machine-token \ - -H "Content-Type: application/json" \ - -d "{\"machine_token\": \"${PANTHEON_MACHINE_TOKEN}\", \"client\": \"github-actions\"}") - - SESSION_TOKEN=$(echo "$SESSION_RESPONSE" | jq -r '.session') - - if [ -z "$SESSION_TOKEN" ] || [ "$SESSION_TOKEN" == "null" ]; then - echo "::error::Failed to get API session token" - echo "Response: $SESSION_RESPONSE" - exit 1 - fi - - echo "Authenticated with Pantheon API" - - # Calculate max attempts based on wait minutes - SLEEP_TIME=10 - MAX_ATTEMPTS=$(( (MAX_WAIT_MINUTES * 60) / SLEEP_TIME )) - ATTEMPT=0 - - echo "Will check up to $MAX_ATTEMPTS times (${MAX_WAIT_MINUTES} minutes)" - - while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do - ATTEMPT=$((ATTEMPT + 1)) - echo "Check $ATTEMPT of $MAX_ATTEMPTS..." - - # Get build list for this environment (Next.js-specific endpoint) - BUILDS_RESPONSE=$(curl -s "https://terminus.pantheon.io/api/sites/$SITE_UUID/environment/${ENV_NAME}/build/list?limit=10" \ - -H "X-Pantheon-Session: $SESSION_TOKEN") - - # Validate response is JSON before parsing (API may return HTML errors) - if ! echo "$BUILDS_RESPONSE" | jq -e . >/dev/null 2>&1; then - echo "Received non-JSON response, retrying..." - sleep $SLEEP_TIME - continue - fi - - # Find build matching this commit SHA - BUILD=$(echo "$BUILDS_RESPONSE" | jq -r ".[] | select(.commit == \"$EXPECTED_COMMIT\")" 2>/dev/null) - - if [ -z "$BUILD" ] || [ "$BUILD" == "null" ]; then - echo "No build found yet for commit ${EXPECTED_COMMIT:0:7}" - sleep $SLEEP_TIME - continue - fi - - BUILD_ID=$(echo "$BUILD" | jq -r '.id') - BUILD_STATUS=$(echo "$BUILD" | jq -r '.status') - BUILD_COMMIT=$(echo "$BUILD" | jq -r '.commit') - - echo "Build ID: $BUILD_ID" - echo "Commit: ${BUILD_COMMIT:0:7}" - echo "Status: $BUILD_STATUS" - - if [ "$BUILD_STATUS" == "DEPLOYMENT_SUCCESS" ]; then - echo "Deployment successful" - echo "deployment_ready=true" >> $GITHUB_OUTPUT - echo "build_status=$BUILD_STATUS" >> $GITHUB_OUTPUT - exit 0 - elif [[ "$BUILD_STATUS" == *"FAILURE"* ]]; then - echo "::error::Build or deployment failed (status: $BUILD_STATUS)" - echo "deployment_ready=false" >> $GITHUB_OUTPUT - echo "build_status=$BUILD_STATUS" >> $GITHUB_OUTPUT - exit 1 - elif [[ "$BUILD_STATUS" == *"WORKING"* ]] || [[ "$BUILD_STATUS" == *"QUEUED"* ]]; then - echo "Still processing..." - else - echo "Status: $BUILD_STATUS" - fi - - sleep $SLEEP_TIME - done - - echo "::error::Timeout after ${MAX_WAIT_MINUTES} minutes" - echo "deployment_ready=false" >> $GITHUB_OUTPUT - echo "build_status=TIMEOUT" >> $GITHUB_OUTPUT - exit 1 + terminus node:builds:wait ${PANTHEON_SITE_NAME}.${ENV_NAME} --commit=${EXPECTED_COMMIT} --max=${MAX_WAIT_SECONDS}