2626 set -euo pipefail
2727 echo "Waiting for Mintlify staging deployment of $SHA"
2828 DEADLINE=$(( $(date +%s) + 720 ))
29+ LAST_DEPLOYMENT_ID=""
30+ LAST_DEPLOYMENT_STATE=""
31+
2932 while [ "$(date +%s)" -lt "$DEADLINE" ]; do
3033 DEPS=$(curl -fsS -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
3134 "https://api.github.com/repos/$REPO/deployments?sha=$SHA&environment=staging&per_page=20")
@@ -36,39 +39,73 @@ jobs:
3639 print(d['id']); break
3740 ")
3841 if [ -n "$DID" ]; then
42+ LAST_DEPLOYMENT_ID="$DID"
3943 STATE=$(curl -fsS -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
4044 "https://api.github.com/repos/$REPO/deployments/$DID/statuses?per_page=1" \
4145 | python3 -c "import json,sys;ss=json.load(sys.stdin);print(ss[0]['state'] if ss else '')")
46+ LAST_DEPLOYMENT_STATE="$STATE"
4247 echo "deployment=$DID state=$STATE"
4348 case "$STATE" in
4449 success)
4550 ENV_URL=$(curl -fsS -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
4651 "https://api.github.com/repos/$REPO/deployments/$DID/statuses?per_page=1" \
4752 | python3 -c "import json,sys;ss=json.load(sys.stdin);print(ss[0].get('environment_url') or ss[0].get('target_url') or '')")
4853 echo "docs_url=$ENV_URL" >> "$GITHUB_OUTPUT"
54+ echo "mintlify_status=success" >> "$GITHUB_OUTPUT"
55+ echo "mintlify_deployment_id=$DID" >> "$GITHUB_OUTPUT"
4956 exit 0
5057 ;;
5158 failure|error)
5259 echo "Mintlify deployment $DID failed: $STATE" >&2
53- exit 1
60+ echo "mintlify_status=$STATE" >> "$GITHUB_OUTPUT"
61+ echo "mintlify_deployment_id=$DID" >> "$GITHUB_OUTPUT"
62+ exit 0
5463 ;;
5564 esac
5665 fi
5766 sleep 15
5867 done
59- echo "Timed out waiting for Mintlify deployment of $SHA" >&2
60- exit 1
68+
69+ if [ -n "$LAST_DEPLOYMENT_ID" ]; then
70+ echo "Timed out waiting for Mintlify deployment $LAST_DEPLOYMENT_ID to succeed; last state: ${LAST_DEPLOYMENT_STATE:-unknown}" >&2
71+ echo "mintlify_status=deployment_timeout" >> "$GITHUB_OUTPUT"
72+ echo "mintlify_deployment_id=$LAST_DEPLOYMENT_ID" >> "$GITHUB_OUTPUT"
73+ else
74+ echo "Timed out waiting for Mintlify to create a deployment for $SHA" >&2
75+ echo "mintlify_status=deployment_not_created" >> "$GITHUB_OUTPUT"
76+ echo "mintlify_deployment_id=" >> "$GITHUB_OUTPUT"
77+ fi
6178
6279 - name : Notify Teable webhook
80+ if : always()
6381 env :
6482 TEABLE_WEBHOOK_URL : ${{ secrets.TEABLE_WEBHOOK_URL }}
6583 TEABLE_WEBHOOK_TOKEN : ${{ secrets.TEABLE_WEBHOOK_TOKEN }}
6684 DOCS_BRANCH : ${{ github.event.pull_request.head.ref }}
6785 DOCS_URL : ${{ steps.wait.outputs.docs_url }}
86+ MINTLIFY_STATUS : ${{ steps.wait.outputs.mintlify_status }}
87+ MINTLIFY_DEPLOYMENT_ID : ${{ steps.wait.outputs.mintlify_deployment_id }}
88+ PR_NUMBER : ${{ github.event.pull_request.number }}
89+ PR_URL : ${{ github.event.pull_request.html_url }}
90+ MERGE_SHA : ${{ github.event.pull_request.merge_commit_sha }}
6891 run : |
6992 set -euo pipefail
7093 curl -fsS -X POST \
7194 "$TEABLE_WEBHOOK_URL" \
7295 -H "Authorization: Bearer $TEABLE_WEBHOOK_TOKEN" \
7396 -H "Content-Type: application/json" \
74- -d "$(jq -nc --arg b "$DOCS_BRANCH" --arg u "$DOCS_URL" '{docs_branch:$b, docs_url:$u}')"
97+ -d "$(jq -nc \
98+ --arg b "$DOCS_BRANCH" \
99+ --arg u "$DOCS_URL" \
100+ --arg s "$MINTLIFY_STATUS" \
101+ --arg d "$MINTLIFY_DEPLOYMENT_ID" \
102+ --arg p "$PR_NUMBER" \
103+ --arg r "$PR_URL" \
104+ --arg m "$MERGE_SHA" \
105+ '{docs_branch:$b, docs_url:$u, mintlify_status:$s, mintlify_deployment_id:$d, pr_number:$p, pr_url:$r, merge_sha:$m}')"
106+
107+ - name : Fail if Mintlify did not deploy
108+ if : steps.wait.outputs.mintlify_status != 'success'
109+ run : |
110+ echo "Mintlify did not deploy successfully: ${{ steps.wait.outputs.mintlify_status }}" >&2
111+ exit 1
0 commit comments