Raw
1 name: Cloud Docs Automation
2
3 on:
4 repository_dispatch:
5 types:
6 - cloud-deployment
7
8
9 jobs:
10 cloud-docs-automation:
11 runs-on: ubuntu-latest
12 permissions:
13 contents: write
14 pull-requests: write
15 steps:
16 - name: Generate GitHub App token
17 id: app-token
18 uses: actions/create-github-app-token@v1
19 with:
20 app-id: ${{ secrets.MEDUSA_APP_ID }}
21 private-key: ${{ secrets.MEDUSA_APP_PRIVATE_KEY }}
22
23 - name: Checkout repository
24 uses: actions/checkout@v4
25 with:
26 fetch-depth: 0
27 token: ${{ steps.app-token.outputs.token }}
28
29 - name: Setup Node.js
30 uses: actions/setup-node@v4
31 with:
32 node-version: 22
33 cache: "yarn"
34
35 - name: Install monorepo dependencies
36 uses: ./.github/actions/cache-deps
37 with:
38 extension: cloud-docs-automation
39
40 - name: Install www dependencies
41 working-directory: www
42 run: yarn install
43
44 - name: Build www packages
45 working-directory: www
46 run: yarn build:packages
47
48 - name: Install www/utils dependencies
49 working-directory: www/utils
50 run: yarn install
51
52 - name: Build www/utils packages
53 working-directory: www/utils
54 run: yarn build
55
56 - name: Write dispatch payload to file
57 id: write-payload
58 run: |
59 node --input-type=module << 'EOF'
60 import { writeFileSync } from "fs"
61 const payload = ${{ toJSON(github.event.client_payload) }}
62 writeFileSync("/tmp/cloud-dispatch.json", JSON.stringify(payload, null, 2))
63 console.log("Payload written to /tmp/cloud-dispatch.json")
64 EOF
65
66 - name: Analyze cloud deployment
67 id: analyze
68 working-directory: www/utils/packages/docs-automator
69 run: yarn analyze-cloud --dispatch-file /tmp/cloud-dispatch.json --output /tmp/analysis.json
70 continue-on-error: true
71
72 - name: Check if documentation changes are needed
73 id: check
74 run: |
75 if [ "${{ steps.analyze.outcome }}" = "failure" ]; then
76 echo "needs_docs=false" >> "$GITHUB_OUTPUT"
77 exit 0
78 fi
79 node --input-type=module << 'EOF'
80 import { readFileSync, appendFileSync } from "fs"
81 const a = JSON.parse(readFileSync("/tmp/analysis.json", "utf8"))
82 const needed = a.affectedProjects.length > 0 ? "true" : "false"
83 appendFileSync(process.env.GITHUB_OUTPUT, `needs_docs=${needed}\n`)
84 EOF
85
86 - name: Configure git
87 if: steps.check.outputs.needs_docs == 'true'
88 run: |
89 git config user.name "github-actions[bot]"
90 git config user.email "github-actions[bot]@users.noreply.github.com"
91
92 - name: Extract Claude prompt
93 id: extract-prompt
94 if: steps.check.outputs.needs_docs == 'true'
95 run: |
96 node --input-type=module << 'EOF'
97 import { readFileSync, appendFileSync } from "fs"
98 const a = JSON.parse(readFileSync("/tmp/analysis.json", "utf8"))
99 const prefix = "IMPORTANT: Only make file changes using the Write and Edit tools. Never use git commands to stage, commit, or push files.\n\nIMPORTANT: To load the writing-docs skill, use the Skill tool directly with skill='writing-docs'. Do NOT spawn a sub-agent or use the Task tool to load it.\n\n"
100 const suffix = "\n\n---\n\nIMPORTANT — final step: after applying all documentation changes, write these two files using the Write tool:\n\n1. /tmp/pr-title.txt — a single-line pull request title. It MUST start with \"docs: \", followed by a concise summary of what was changed, and MUST end with \" [automated]\". Keep it under 100 characters. Example: \"docs: document new environment variables page [automated]\"\n2. /tmp/pr-summary.md — a short summary (2-4 sentences, or a few bullet points) of what was updated. Plain markdown, no top-level heading.\n\nIf you made no documentation changes, do not create either file.\n"
101 const delimiter = "CLAUDE_PROMPT_EOF"
102 appendFileSync(
103 process.env.GITHUB_OUTPUT,
104 `CLAUDE_PROMPT<<${delimiter}\n${prefix}${a.claudePrompt}${suffix}\n${delimiter}\n`
105 )
106 EOF
107
108 - name: Run Claude Code to update cloud docs
109 if: steps.check.outputs.needs_docs == 'true'
110 uses: anthropics/claude-code-base-action@132be24009ca6f292db66a3d1d5a17249cf68a5d # main, installs Claude Code 2.1.282
111 with:
112 anthropic_api_key: ${{ secrets.CLAUDE_CODE_API_TOKEN }}
113 claude_args: >-
114 --model claude-opus-5-5
115 --max-turns 40
116 --allowedTools "Skill,Read,Write,Edit,Glob,Grep,Bash(git diff:*),Bash(ls:*),Bash(find:*),Bash(cat:*)"
117 prompt: ${{ steps.extract-prompt.outputs.CLAUDE_PROMPT }}
118
119 - name: Read changelog entry metadata
120 id: changelog
121 if: steps.check.outputs.needs_docs == 'true'
122 run: |
123 node --input-type=module << 'EOF'
124 import { readFileSync, appendFileSync } from "fs"
125 const a = JSON.parse(readFileSync("/tmp/analysis.json", "utf8"))
126 const entry = a.changelogEntry ?? {}
127 appendFileSync(
128 process.env.GITHUB_OUTPUT,
129 `date=${entry.date ?? ""}\ndisplay_date=${entry.displayDate ?? ""}\nfile=${entry.file ?? ""}\n`
130 )
131 EOF
132
133 # Runs after Claude, since the banner is attached to the entry file Claude
134 # writes. A missing banner is not worth failing the run over — the entry is
135 # the deliverable and the image is decoration — so this only warns.
136 - name: Render and upload the changelog banner
137 id: banner
138 if: steps.check.outputs.needs_docs == 'true' && steps.changelog.outputs.file != ''
139 continue-on-error: true
140 env:
141 CLOUDINARY_URL: ${{ secrets.CLOUDINARY_URL }}
142 ENTRY_FILE: ${{ steps.changelog.outputs.file }}
143 ENTRY_DATE: ${{ steps.changelog.outputs.display_date }}
144 run: |
145 if [ ! -f "$ENTRY_FILE" ]; then
146 echo "Claude wrote no changelog entry for $ENTRY_DATE — skipping the banner."
147 exit 0
148 fi
149
150 if [ -z "$CLOUDINARY_URL" ]; then
151 echo "::warning::CLOUDINARY_URL is not set — skipping the changelog banner"
152 exit 1
153 fi
154
155 # Called directly rather than through `yarn upload` so that the only
156 # thing captured here is the URL the CLI prints.
157 BANNER_URL=$(node www/utils/packages/release-banner/dist/cli.js upload \
158 --type cloud-changelog --date "$ENTRY_DATE")
159
160 node www/apps/cloud/scripts/set-changelog-image.mjs \
161 --file "$ENTRY_FILE" --url "$BANNER_URL"
162
163 - name: Run prep script for cloud project
164 if: steps.check.outputs.needs_docs == 'true'
165 run: |
166 echo "Running prep for cloud..."
167 (cd "www/apps/cloud" && yarn prep) || true
168
169 - name: Run lint:content for cloud project
170 if: steps.check.outputs.needs_docs == 'true'
171 run: |
172 echo "Running lint:content for cloud..."
173 (cd "www/apps/cloud" && yarn lint:content) || true
174
175 - name: Check for documentation changes
176 id: changes
177 if: steps.check.outputs.needs_docs == 'true'
178 run: |
179 # Untracked files are listed too, since new documentation pages and
180 # new changelog entry files under `generated/changelog` don't show up
181 # in `git diff`.
182 PATHS="www/apps/cloud/app www/apps/cloud/generated www/apps/cloud/sidebar.mjs"
183 CHANGES=$( { git diff --name-only -- $PATHS; \
184 git ls-files --others --exclude-standard -- $PATHS; } \
185 | grep -E '\.(mdx|json|mjs)$' || true)
186 if [ -n "$CHANGES" ]; then
187 echo "has_changes=true" >> "$GITHUB_OUTPUT"
188 else
189 echo "has_changes=false" >> "$GITHUB_OUTPUT"
190 echo "No documentation changes found."
191 fi
192
193 - name: Build PR metadata
194 id: pr-body
195 if: steps.check.outputs.needs_docs == 'true' && steps.changes.outputs.has_changes == 'true'
196 run: |
197 node --input-type=module << 'EOF'
198 import { existsSync, readFileSync, appendFileSync } from "fs"
199
200 const a = JSON.parse(readFileSync("/tmp/analysis.json", "utf8"))
201 const flagged = Array.isArray(a.featureFlaggedFeatures) ? a.featureFlaggedFeatures : []
202
203 // Title generated by Claude, with a fallback if it is missing or malformed
204 let title = existsSync("/tmp/pr-title.txt")
205 ? readFileSync("/tmp/pr-title.txt", "utf8").split("\n")[0].trim()
206 : ""
207 if (!title.startsWith("docs: ") || !title.endsWith("[automated]")) {
208 title = "docs: update cloud documentation [automated]"
209 }
210
211 const summary = existsSync("/tmp/pr-summary.md")
212 ? readFileSync("/tmp/pr-summary.md", "utf8").trim()
213 : ""
214
215 const lines = [
216 "## Automated Cloud Documentation Updates",
217 "",
218 "This PR contains automated documentation changes triggered by Cloud production deployments.",
219 "",
220 summary || "_No summary was generated._",
221 "",
222 "> Review carefully before merging. Claude may have missed context or made incorrect assumptions.",
223 ]
224
225 if (flagged.length > 0) {
226 lines.push("")
227 lines.push("---")
228 lines.push("")
229 lines.push("### ⚠️ Feature flag warning")
230 lines.push("")
231 lines.push(
232 "The following features appear to be gated by a feature flag. " +
233 "**Confirm they have been fully rolled out before merging this PR:**"
234 )
235 lines.push("")
236 for (const f of flagged) {
237 lines.push(`- ${f}`)
238 }
239 }
240
241 const body = lines.join("\n")
242 const delimiter = "PR_BODY_EOF"
243 appendFileSync(process.env.GITHUB_OUTPUT, `TITLE=${title}\n`)
244 appendFileSync(process.env.GITHUB_OUTPUT, `BODY<<${delimiter}\n${body}\n${delimiter}\n`)
245 EOF
246
247 - name: Create Pull Request
248 if: steps.check.outputs.needs_docs == 'true' && steps.changes.outputs.has_changes == 'true'
249 uses: peter-evans/create-pull-request@38e0b6e68b4c852a5500a94740f0e535e0d7ba54 # v4
250 with:
251 token: ${{ steps.app-token.outputs.token }}
252 commit-message: "chore(docs): automated cloud documentation update"
253 base: develop
254 branch: docs/cloud-docs
255 branch-suffix: timestamp
256 title: ${{ steps.pr-body.outputs.TITLE }}
257 labels: "type: docs"
258 add-paths: |
259 www/apps/cloud/app
260 www/apps/cloud/generated
261 www/apps/cloud/sidebar.mjs
262 body: ${{ steps.pr-body.outputs.BODY }}