forked from langchain-ai/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (116 loc) Β· 4.5 KB
/
mintlify-trigger-preview.yml
File metadata and controls
137 lines (116 loc) Β· 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
---
name: Trigger Mintlify Preview Deployment
on:
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
# Avoid duplicate preview triggers for the same PR.
concurrency:
group: mintlify-preview-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
jobs:
trigger-preview:
runs-on: ubuntu-latest
# Secrets are not available to PRs from forks.
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
steps:
- name: Trigger Mintlify preview deployment (capture response)
id: call
env:
MINTLIFY_API_KEY: ${{ secrets.MINTLIFY_API_KEY }}
MINTLIFY_PROJECT_ID: ${{ secrets.MINTLIFY_PROJECT_ID }}
BRANCH: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref_name }}
run: |
set -euo pipefail
if [ -z "${MINTLIFY_API_KEY:-}" ] || [ -z "${MINTLIFY_PROJECT_ID:-}" ]; then
echo "Missing required secrets."
echo "Set secrets.MINTLIFY_API_KEY (admin key starting with mint_) and secrets.MINTLIFY_PROJECT_ID."
exit 1
fi
response="$(curl -sS -X POST \
"https://api.mintlify.com/v1/project/preview/${MINTLIFY_PROJECT_ID}" \
-H "Authorization: Bearer ${MINTLIFY_API_KEY}" \
-H "Content-Type: application/json" \
--data "{\"branch\":\"${BRANCH}\"}")"
echo "response<<EOF" >> "$GITHUB_OUTPUT"
echo "$response" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Parse response
id: parse
env:
RESPONSE: ${{ steps.call.outputs.response }}
run: |
set -euo pipefail
python - <<'PY'
import json
import os
import sys
response = os.environ.get("RESPONSE", "")
try:
data = json.loads(response) if response else {}
except Exception:
print("Failed to parse Mintlify API response as JSON.", file=sys.stderr)
print(response, file=sys.stderr)
sys.exit(1)
status_id = data.get("statusId", "")
preview_url = data.get("previewUrl", "")
error = data.get("error", "")
if error and not (status_id or preview_url):
print(f"Mintlify API error: {error}", file=sys.stderr)
sys.exit(1)
out = os.environ["GITHUB_OUTPUT"]
with open(out, "a", encoding="utf-8") as f:
f.write(f"status_id={status_id}\n")
f.write(f"preview_url={preview_url}\n")
PY
- name: Comment preview link on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v8
env:
PREVIEW_URL: ${{ steps.parse.outputs.preview_url }}
STATUS_ID: ${{ steps.parse.outputs.status_id }}
BRANCH: ${{ github.event.pull_request.head.ref }}
with:
script: |
const previewUrl = process.env.PREVIEW_URL || '';
const statusId = process.env.STATUS_ID || '';
const branch = process.env.BRANCH || '';
const lines = [];
lines.push('## Mintlify preview');
lines.push('');
if (previewUrl) {
lines.push(`- **Preview URL**: ${previewUrl}`);
}
if (statusId) {
lines.push(`- **Status ID**: \`${statusId}\``);
}
if (branch) {
lines.push(`- **Branch**: \`${branch}\``);
}
const body = lines.join('\n');
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.data.find(c =>
c.user?.type === 'Bot' && (c.body || '').includes('## Mintlify preview')
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}