1616 runs-on : ubuntu-latest
1717 timeout-minutes : 15
1818 steps :
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+
1950 - name : Record GitHub merge
2051 env :
2152 TEABLE_WEBHOOK_URL : ${{ secrets.TEABLE_WEBHOOK_URL }}
@@ -40,14 +71,24 @@ jobs:
4071 --arg t "$MERGED_AT" \
4172 '{docs_branch:$b, mintlify_status:$s, pr_number:$p, pr_url:$r, merge_sha:$m, merged_at:$t}')"
4273
43- - name : Wait for Mintlify deployment
44- id : wait
74+ - name : Resolve Mintlify deployment status
75+ id : mintlify
4576 env :
4677 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
4778 REPO : ${{ github.repository }}
4879 SHA : ${{ github.event.pull_request.merge_commit_sha }}
80+ NEEDS_MINTLIFY_DEPLOY : ${{ steps.relevance.outputs.needs_mintlify_deploy }}
4981 run : |
5082 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+
5192 echo "Waiting for Mintlify staging deployment of $SHA"
5293 DEADLINE=$(( $(date +%s) + 720 ))
5394 LAST_DEPLOYMENT_ID=""
@@ -106,23 +147,24 @@ jobs:
106147 TEABLE_WEBHOOK_URL : ${{ secrets.TEABLE_WEBHOOK_URL }}
107148 TEABLE_WEBHOOK_TOKEN : ${{ secrets.TEABLE_WEBHOOK_TOKEN }}
108149 DOCS_BRANCH : ${{ github.event.pull_request.head.ref }}
109- DOCS_URL : ${{ steps.wait .outputs.docs_url }}
110- MINTLIFY_STATUS : ${{ steps.wait .outputs.mintlify_status }}
111- MINTLIFY_DEPLOYMENT_ID : ${{ steps.wait .outputs.mintlify_deployment_id }}
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 }}
112153 PR_NUMBER : ${{ github.event.pull_request.number }}
113154 PR_URL : ${{ github.event.pull_request.html_url }}
114155 MERGE_SHA : ${{ github.event.pull_request.merge_commit_sha }}
115156 MERGED_AT : ${{ github.event.pull_request.merged_at }}
116157 run : |
117158 set -euo pipefail
159+ STATUS="${MINTLIFY_STATUS:-error}"
118160 curl -fsS -X POST \
119161 "$TEABLE_WEBHOOK_URL" \
120162 -H "Authorization: Bearer $TEABLE_WEBHOOK_TOKEN" \
121163 -H "Content-Type: application/json" \
122164 -d "$(jq -nc \
123165 --arg b "$DOCS_BRANCH" \
124166 --arg u "$DOCS_URL" \
125- --arg s "$MINTLIFY_STATUS " \
167+ --arg s "$STATUS " \
126168 --arg d "$MINTLIFY_DEPLOYMENT_ID" \
127169 --arg p "$PR_NUMBER" \
128170 --arg r "$PR_URL" \
@@ -131,7 +173,7 @@ jobs:
131173 '{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}')"
132174
133175 - name : Fail if Mintlify did not deploy
134- if : steps.wait .outputs.mintlify_status != 'success'
176+ if : steps.relevance.outputs.needs_mintlify_deploy == 'true' && steps.mintlify .outputs.mintlify_status != 'success'
135177 run : |
136- echo "Mintlify did not deploy successfully: ${{ steps.wait .outputs.mintlify_status }}" >&2
178+ echo "Mintlify did not deploy successfully: ${{ steps.mintlify .outputs.mintlify_status }}" >&2
137179 exit 1
0 commit comments