name: Deploy
on:
workflow_run:
workflows: ["Build"]
types: [completed]
branches:
- master
- main
- 'release/**'
workflow_dispatch:
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
jobs:
deploy-staging:
if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success'
runs-on: cpu
timeout-minutes: 10
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 with:
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
- name: Deploy to staging
env:
DEPLOY_SHA: ${{ github.event.workflow_run.head_sha || github.sha }}
DEPLOY_PAT: ${{ secrets.DEPLOY_PAT }}
run: |
set -euo pipefail
# Fail loudly on a missing secret. Previously an unset DEPLOY_PAT sent
# `Authorization: token ` and GitHub replied 401 Bad credentials — but
# curl without --fail exits 0, so the step went green and this job
# reported a successful deploy that never dispatched anything. This
# repo shipped "successful" staging deploys that did nothing at all.
if [ -z "${DEPLOY_PAT:-}" ]; then
echo "::error::DEPLOY_PAT is not set on zakuro-ai/zc — cannot dispatch the staging deploy."
exit 1
fi
# Capture the status separately: repository_dispatch returns 204 with an
# empty body on success, so the body alone cannot be asserted on.
STATUS=$(curl -sS -X POST \
-o /tmp/dispatch-body.txt -w '%{http_code}' \
-H "Authorization: token ${DEPLOY_PAT}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/zakuro-ai/zakuro-infra/dispatches \
-d "{\"event_type\":\"deploy-staging\",\"client_payload\":{\"service\":\"zc\",\"sha\":\"$DEPLOY_SHA\"}}")
if [ "$STATUS" != "204" ]; then
echo "::error::zakuro-infra dispatch failed (HTTP $STATUS) — staging was NOT deployed."
cat /tmp/dispatch-body.txt
exit 1
fi
echo "Dispatched deploy-staging to zakuro-infra for zc @ ${DEPLOY_SHA} (HTTP 204)."