@@ -16,16 +16,84 @@ jobs:
1616 runs-on : ubuntu-latest
1717 timeout-minutes : 15
1818 steps :
19- - name : Wait for Mintlify deployment
20- id : wait
19+ - name : Detect Mintlify relevance
20+ id : relevance
21+ env :
22+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
23+ REPO : ${{ github.repository }}
24+ PR_NUMBER : ${{ github.event.pull_request.number }}
25+ run : |
26+ set -euo pipefail
27+ FILES="[]"
28+ PAGE=1
29+ while true; do
30+ PAGE_FILES=$(curl -fsS -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
31+ "https://api.github.com/repos/$REPO/pulls/$PR_NUMBER/files?per_page=100&page=$PAGE")
32+ COUNT=$(echo "$PAGE_FILES" | python3 -c "import json,sys;print(len(json.load(sys.stdin)))")
33+ FILES=$(jq -s 'add' <(echo "$FILES") <(echo "$PAGE_FILES"))
34+ if [ "$COUNT" -lt 100 ]; then
35+ break
36+ fi
37+ PAGE=$((PAGE + 1))
38+ done
39+ NEEDS_DEPLOY=$(echo "$FILES" | python3 -c "
40+ import json,sys
41+ paths = [f.get('filename','') for f in json.load(sys.stdin)]
42+ prefixes = ('en/', 'zh/', 'images/', 'snippets/', 'api-reference/')
43+ exact = {'docs.json', 'mint.json', 'swagger.json', 'style.css', 'changelog-toc.js'}
44+ needs = any(p in exact or p.startswith(prefixes) for p in paths)
45+ print('true' if needs else 'false')
46+ ")
47+ echo "needs_mintlify_deploy=$NEEDS_DEPLOY" >> "$GITHUB_OUTPUT"
48+ echo "needs_mintlify_deploy=$NEEDS_DEPLOY"
49+
50+ - name : Record GitHub merge
51+ env :
52+ TEABLE_WEBHOOK_URL : ${{ secrets.TEABLE_WEBHOOK_URL }}
53+ TEABLE_WEBHOOK_TOKEN : ${{ secrets.TEABLE_WEBHOOK_TOKEN }}
54+ DOCS_BRANCH : ${{ github.event.pull_request.head.ref }}
55+ PR_NUMBER : ${{ github.event.pull_request.number }}
56+ PR_URL : ${{ github.event.pull_request.html_url }}
57+ MERGE_SHA : ${{ github.event.pull_request.merge_commit_sha }}
58+ MERGED_AT : ${{ github.event.pull_request.merged_at }}
59+ run : |
60+ set -euo pipefail
61+ curl -fsS -X POST \
62+ "$TEABLE_WEBHOOK_URL" \
63+ -H "Authorization: Bearer $TEABLE_WEBHOOK_TOKEN" \
64+ -H "Content-Type: application/json" \
65+ -d "$(jq -nc \
66+ --arg b "$DOCS_BRANCH" \
67+ --arg s "pending" \
68+ --arg p "$PR_NUMBER" \
69+ --arg r "$PR_URL" \
70+ --arg m "$MERGE_SHA" \
71+ --arg t "$MERGED_AT" \
72+ '{docs_branch:$b, mintlify_status:$s, pr_number:$p, pr_url:$r, merge_sha:$m, merged_at:$t}')"
73+
74+ - name : Resolve Mintlify deployment status
75+ id : mintlify
2176 env :
2277 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
2378 REPO : ${{ github.repository }}
2479 SHA : ${{ github.event.pull_request.merge_commit_sha }}
80+ NEEDS_MINTLIFY_DEPLOY : ${{ steps.relevance.outputs.needs_mintlify_deploy }}
2581 run : |
2682 set -euo pipefail
83+
84+ if [ "$NEEDS_MINTLIFY_DEPLOY" != "true" ]; then
85+ echo "Mintlify deployment not required for this PR"
86+ echo "docs_url=" >> "$GITHUB_OUTPUT"
87+ echo "mintlify_status=not_required" >> "$GITHUB_OUTPUT"
88+ echo "mintlify_deployment_id=" >> "$GITHUB_OUTPUT"
89+ exit 0
90+ fi
91+
2792 echo "Waiting for Mintlify staging deployment of $SHA"
2893 DEADLINE=$(( $(date +%s) + 720 ))
94+ LAST_DEPLOYMENT_ID=""
95+ LAST_DEPLOYMENT_STATE=""
96+
2997 while [ "$(date +%s)" -lt "$DEADLINE" ]; do
3098 DEPS=$(curl -fsS -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
3199 "https://api.github.com/repos/$REPO/deployments?sha=$SHA&environment=staging&per_page=20")
@@ -36,39 +104,76 @@ jobs:
36104 print(d['id']); break
37105 ")
38106 if [ -n "$DID" ]; then
107+ LAST_DEPLOYMENT_ID="$DID"
39108 STATE=$(curl -fsS -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
40109 "https://api.github.com/repos/$REPO/deployments/$DID/statuses?per_page=1" \
41110 | python3 -c "import json,sys;ss=json.load(sys.stdin);print(ss[0]['state'] if ss else '')")
111+ LAST_DEPLOYMENT_STATE="$STATE"
42112 echo "deployment=$DID state=$STATE"
43113 case "$STATE" in
44114 success)
45115 ENV_URL=$(curl -fsS -H "Authorization: Bearer $GH_TOKEN" -H "Accept: application/vnd.github+json" \
46116 "https://api.github.com/repos/$REPO/deployments/$DID/statuses?per_page=1" \
47117 | python3 -c "import json,sys;ss=json.load(sys.stdin);print(ss[0].get('environment_url') or ss[0].get('target_url') or '')")
48118 echo "docs_url=$ENV_URL" >> "$GITHUB_OUTPUT"
119+ echo "mintlify_status=success" >> "$GITHUB_OUTPUT"
120+ echo "mintlify_deployment_id=$DID" >> "$GITHUB_OUTPUT"
49121 exit 0
50122 ;;
51123 failure|error)
52124 echo "Mintlify deployment $DID failed: $STATE" >&2
53- exit 1
125+ echo "mintlify_status=$STATE" >> "$GITHUB_OUTPUT"
126+ echo "mintlify_deployment_id=$DID" >> "$GITHUB_OUTPUT"
127+ exit 0
54128 ;;
55129 esac
56130 fi
57131 sleep 15
58132 done
59- echo "Timed out waiting for Mintlify deployment of $SHA" >&2
60- exit 1
133+
134+ if [ -n "$LAST_DEPLOYMENT_ID" ]; then
135+ echo "Timed out waiting for Mintlify deployment $LAST_DEPLOYMENT_ID to succeed; last state: ${LAST_DEPLOYMENT_STATE:-unknown}" >&2
136+ echo "mintlify_status=deployment_timeout" >> "$GITHUB_OUTPUT"
137+ echo "mintlify_deployment_id=$LAST_DEPLOYMENT_ID" >> "$GITHUB_OUTPUT"
138+ else
139+ echo "Timed out waiting for Mintlify to create a deployment for $SHA" >&2
140+ echo "mintlify_status=deployment_not_created" >> "$GITHUB_OUTPUT"
141+ echo "mintlify_deployment_id=" >> "$GITHUB_OUTPUT"
142+ fi
61143
62144 - name : Notify Teable webhook
145+ if : always()
63146 env :
64147 TEABLE_WEBHOOK_URL : ${{ secrets.TEABLE_WEBHOOK_URL }}
65148 TEABLE_WEBHOOK_TOKEN : ${{ secrets.TEABLE_WEBHOOK_TOKEN }}
66149 DOCS_BRANCH : ${{ github.event.pull_request.head.ref }}
67- DOCS_URL : ${{ steps.wait.outputs.docs_url }}
150+ DOCS_URL : ${{ steps.mintlify.outputs.docs_url }}
151+ MINTLIFY_STATUS : ${{ steps.mintlify.outputs.mintlify_status }}
152+ MINTLIFY_DEPLOYMENT_ID : ${{ steps.mintlify.outputs.mintlify_deployment_id }}
153+ PR_NUMBER : ${{ github.event.pull_request.number }}
154+ PR_URL : ${{ github.event.pull_request.html_url }}
155+ MERGE_SHA : ${{ github.event.pull_request.merge_commit_sha }}
156+ MERGED_AT : ${{ github.event.pull_request.merged_at }}
68157 run : |
69158 set -euo pipefail
159+ STATUS="${MINTLIFY_STATUS:-error}"
70160 curl -fsS -X POST \
71161 "$TEABLE_WEBHOOK_URL" \
72162 -H "Authorization: Bearer $TEABLE_WEBHOOK_TOKEN" \
73163 -H "Content-Type: application/json" \
74- -d "$(jq -nc --arg b "$DOCS_BRANCH" --arg u "$DOCS_URL" '{docs_branch:$b, docs_url:$u}')"
164+ -d "$(jq -nc \
165+ --arg b "$DOCS_BRANCH" \
166+ --arg u "$DOCS_URL" \
167+ --arg s "$STATUS" \
168+ --arg d "$MINTLIFY_DEPLOYMENT_ID" \
169+ --arg p "$PR_NUMBER" \
170+ --arg r "$PR_URL" \
171+ --arg m "$MERGE_SHA" \
172+ --arg t "$MERGED_AT" \
173+ '{docs_branch:$b, docs_url:$u, mintlify_status:$s, mintlify_deployment_id:$d, pr_number:$p, pr_url:$r, merge_sha:$m, merged_at:$t}')"
174+
175+ - name : Fail if Mintlify did not deploy
176+ if : steps.relevance.outputs.needs_mintlify_deploy == 'true' && steps.mintlify.outputs.mintlify_status != 'success'
177+ run : |
178+ echo "Mintlify did not deploy successfully: ${{ steps.mintlify.outputs.mintlify_status }}" >&2
179+ exit 1
0 commit comments