From 28a103b3d5b3a9c1781d254ec9fc0bb0e5e2a356 Mon Sep 17 00:00:00 2001 From: Luis Rosales Date: Fri, 20 Mar 2026 12:04:13 +0100 Subject: [PATCH] feat(deploy-deployer): expose Deployer exit code and reason as workflow outputs Split the single deploy job into two: - `deploy`: captures Deployer stdout, exit code (0/1/2), and a parsed reason message; always exits 0 so outputs are available to callers - `assert-result`: fails strictly on any non-zero exit code, including warnings (exit 2), surfacing the reason via ::error:: annotation Callers can now consume `deploy_exit_code` and `deploy_reason` outputs from the workflow_call (e.g. for Slack notifications) regardless of whether the failure was an error or a warning. --- .github/workflows/deploy-deployer.yml | 38 ++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-deployer.yml b/.github/workflows/deploy-deployer.yml index b25f5d75e..34f1486ae 100644 --- a/.github/workflows/deploy-deployer.yml +++ b/.github/workflows/deploy-deployer.yml @@ -59,12 +59,22 @@ on: NPM_REGISTRY_TOKEN: description: Authentication for the private npm registry. required: false + outputs: + deploy_exit_code: + description: Deployer process exit code (0=success, 1=error, 2=warning). + value: ${{ jobs.deploy.outputs.exit_code }} + deploy_reason: + description: Human-readable deployment result message parsed from Deployer output. + value: ${{ jobs.deploy.outputs.reason }} jobs: deploy: runs-on: ubuntu-latest env: NODE_CACHE_MODE: '' COMPOSER_NO_DEV: 1 + outputs: + exit_code: ${{ steps.run-deployer.outputs.exit_code }} + reason: ${{ steps.run-deployer.outputs.reason }} steps: - name: Checkout @@ -154,10 +164,36 @@ jobs: ssh-keyscan -p ${{ secrets.DEPLOY_PORT }} ${{ secrets.DEPLOY_HOSTNAME }} >> ~/.ssh/known_hosts - name: Run Deployer + id: run-deployer env: DEPLOY_HOSTNAME: ${{ secrets.DEPLOY_HOSTNAME }} DEPLOY_PORT: ${{ secrets.DEPLOY_PORT }} DEPLOY_USER: ${{ secrets.DEPLOY_USER }} run: | cd deployment - ./$(composer config bin-dir)/dep deploy ${{ inputs.ENVIRONMENT }} -${{ inputs.VERBOSITY}} + set +e + output=$(./$(composer config bin-dir)/dep deploy ${{ inputs.ENVIRONMENT }} -${{ inputs.VERBOSITY}} 2>&1) + exit_code=$? + set -e + echo "$output" + echo "exit_code=${exit_code}" >> $GITHUB_OUTPUT + if [ "$exit_code" -eq 0 ]; then + reason="Deployment completed successfully" + elif [ "$exit_code" -eq 2 ]; then + reason=$(echo "$output" | grep -oE '\[WARNING\][^\n]+' | head -1 | sed 's/\[WARNING\] *//') + reason="${reason:-Deployment completed with warnings}" + else + reason=$(echo "$output" | grep -oE '\[(ERROR|CRITICAL)\][^\n]+' | head -1 | sed 's/\[\(ERROR\|CRITICAL\)\] *//') + reason="${reason:-Deployment failed}" + fi + echo "reason=${reason}" >> $GITHUB_OUTPUT + + assert-result: + needs: deploy + runs-on: ubuntu-latest + steps: + - name: Fail on deployment error or warning + if: needs.deploy.outputs.exit_code != '0' + run: | + echo "::error::Deployer exited with code ${{ needs.deploy.outputs.exit_code }}: ${{ needs.deploy.outputs.reason }}" + exit ${{ needs.deploy.outputs.exit_code }}