Skip to content

Commit a827231

Browse files
committed
Add workflow to auto-update docs on velopack PR merges
1 parent fa1dd58 commit a827231

1 file changed

Lines changed: 202 additions & 0 deletions

File tree

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
name: Sync Docs from Velopack PR
2+
3+
# Reviews a merged (or any) PR on the velopack/velopack repo and, if the change
4+
# warrants it, updates these docs and opens a PR here. It NEVER pushes to master:
5+
# every change produced by this workflow is opened as a pull request for review.
6+
#
7+
# Triggers:
8+
# - workflow_dispatch: run it by hand, typing the velopack PR number.
9+
# - repository_dispatch (type: velopack-pr-merged): fired by the velopack repo
10+
# when a PR merges (see .github/workflows/notify-docs.yml over there).
11+
#
12+
# Only English source under docs/ is edited; the translation workflow regenerates
13+
# i18n/** afterwards, and docs/reference/** is auto-generated so it's left alone.
14+
15+
on:
16+
workflow_dispatch:
17+
inputs:
18+
pr_number:
19+
description: 'velopack/velopack PR number to review'
20+
required: true
21+
type: string
22+
repository_dispatch:
23+
types: [velopack-pr-merged]
24+
25+
permissions:
26+
contents: write
27+
pull-requests: write
28+
29+
concurrency:
30+
# one run per source PR; a newer dispatch for the same PR cancels the older one
31+
group: sync-docs-${{ github.event.inputs.pr_number || github.event.client_payload.pr_number }}
32+
cancel-in-progress: true
33+
34+
env:
35+
SOURCE_REPO: velopack/velopack
36+
PR_NUMBER: ${{ github.event.inputs.pr_number || github.event.client_payload.pr_number }}
37+
38+
jobs:
39+
sync:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Validate input
43+
run: |
44+
if [ -z "$PR_NUMBER" ]; then
45+
echo "::error::No PR number provided (inputs.pr_number / client_payload.pr_number)."
46+
exit 1
47+
fi
48+
echo "Reviewing $SOURCE_REPO#$PR_NUMBER"
49+
50+
- name: Checkout docs
51+
uses: actions/checkout@v4
52+
53+
- name: Set up Node
54+
uses: actions/setup-node@v4
55+
with:
56+
node-version: '20'
57+
58+
- name: Install dependencies
59+
run: npm ci
60+
61+
- name: Fetch source PR context
62+
env:
63+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
run: |
65+
set -euo pipefail
66+
ctx="$RUNNER_TEMP/pr-context.md"
67+
gh pr view "$PR_NUMBER" --repo "$SOURCE_REPO" \
68+
--json number,title,body,state,merged,mergedAt,author,headRefName,baseRefName,url,files \
69+
> "$RUNNER_TEMP/pr.json"
70+
71+
{
72+
echo "# velopack/velopack PR #$PR_NUMBER"
73+
echo
74+
echo "- Title: $(jq -r '.title' "$RUNNER_TEMP/pr.json")"
75+
echo "- URL: $(jq -r '.url' "$RUNNER_TEMP/pr.json")"
76+
echo "- State: $(jq -r '.state' "$RUNNER_TEMP/pr.json") (merged: $(jq -r '.merged' "$RUNNER_TEMP/pr.json"))"
77+
echo "- Base <- Head: $(jq -r '.baseRefName' "$RUNNER_TEMP/pr.json") <- $(jq -r '.headRefName' "$RUNNER_TEMP/pr.json")"
78+
echo
79+
echo "## Description"
80+
echo
81+
jq -r '.body // "(no description)"' "$RUNNER_TEMP/pr.json"
82+
echo
83+
echo "## Files changed"
84+
echo
85+
jq -r '.files[] | "- \(.path) (+\(.additions)/-\(.deletions))"' "$RUNNER_TEMP/pr.json"
86+
echo
87+
echo "## Full diff"
88+
echo
89+
echo '```diff'
90+
gh pr diff "$PR_NUMBER" --repo "$SOURCE_REPO"
91+
echo '```'
92+
} > "$ctx"
93+
94+
echo "PR_CONTEXT_FILE=$ctx" >> "$GITHUB_ENV"
95+
echo "PR_BODY_FILE=$RUNNER_TEMP/docs-pr-body.md" >> "$GITHUB_ENV"
96+
echo "Wrote $(wc -l < "$ctx") lines of PR context."
97+
98+
- name: Review PR and update docs
99+
uses: anthropics/claude-code-action@v1
100+
with:
101+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
102+
claude_args: |
103+
--model claude-sonnet-4-6
104+
--max-turns 40
105+
--allowedTools Read,Edit,Write,Glob,Grep,Bash(npm run build),Bash(npm run typecheck),Bash(ls:*),Bash(cat:*),Bash(rg:*)
106+
--disallowedTools Bash(git push:*),Bash(git commit:*),Bash(git checkout:*),Bash(gh:*)
107+
prompt: |
108+
You are maintaining the Velopack documentation site (Docusaurus 3). A pull
109+
request was merged into the velopack/velopack source repository, and your job
110+
is to decide whether these docs need to change as a result, and if so, make
111+
the changes.
112+
113+
The full context of the source PR (title, description, changed files, and the
114+
complete diff) is in this file — read it first:
115+
116+
${{ env.PR_CONTEXT_FILE }}
117+
118+
Read AGENTS.md in the repo root for the documentation conventions, structure,
119+
and rules. Follow them exactly.
120+
121+
## Your task
122+
123+
1. Carefully review the source PR diff. Determine whether it changes anything
124+
user-facing that the docs describe: new or changed CLI flags/commands, new
125+
SDK APIs or options, changed default behavior, new features, removed
126+
features, renamed concepts, changed config, new platform support, etc.
127+
2. Decide:
128+
A) Do any EXISTING doc pages under docs/ need updating to stay accurate?
129+
B) Do any NEW doc pages need to be written to cover new functionality?
130+
3. If either is true, make the edits under docs/ (and update sidebars.ts /
131+
docusaurus.config.ts redirects only if you add or move pages). Match the
132+
existing style, MDX/frontmatter format, and linking conventions.
133+
4. Run `npm run build` to confirm the site still builds and you introduced no
134+
broken links (the build throws on broken links). Fix anything you broke.
135+
136+
## Hard rules
137+
138+
- Write ENGLISH ONLY. NEVER touch anything under i18n/ — the translation
139+
workflow regenerates it from the English source after this merges.
140+
- NEVER edit anything under docs/reference/** — it is auto-generated from
141+
source code and will be overwritten.
142+
- Do NOT commit, push, create branches, or use git/gh — only edit files. The
143+
workflow handles branching and opening the PR.
144+
- Be conservative. Pure internal refactors, CI/build changes, test-only
145+
changes, dependency bumps, and anything with no user-facing or documented
146+
effect should result in NO doc changes. It is correct and expected to change
147+
nothing when the PR doesn't affect the docs. Do not invent content.
148+
149+
## Output
150+
151+
When you are done, write a concise markdown summary to this exact file:
152+
153+
${{ env.PR_BODY_FILE }}
154+
155+
- If you made doc changes, the summary should explain what you changed and why,
156+
referencing the source PR, and list the affected pages. It becomes the body
157+
of the docs PR.
158+
- If you decided NO doc changes are needed, write a single line to that file:
159+
`NO_CHANGES: <one-sentence reason>`
160+
161+
- name: Open docs PR if changed
162+
env:
163+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
164+
run: |
165+
set -euo pipefail
166+
git config --global user.name "github-actions[bot]"
167+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
168+
169+
if git diff --quiet && git diff --cached --quiet; then
170+
echo "No documentation changes were made for $SOURCE_REPO#$PR_NUMBER."
171+
if [ -f "$PR_BODY_FILE" ]; then echo "Reason: $(cat "$PR_BODY_FILE")"; fi
172+
exit 0
173+
fi
174+
175+
branch="docs/velopack-pr-${PR_NUMBER}-${GITHUB_RUN_ID}"
176+
git checkout -b "$branch"
177+
git add -A
178+
git commit -m "docs: sync for velopack/velopack#${PR_NUMBER}"
179+
git push origin "$branch"
180+
181+
title="docs: sync for velopack#${PR_NUMBER}"
182+
src_url="https://github.com/${SOURCE_REPO}/pull/${PR_NUMBER}"
183+
{
184+
echo "Automated documentation update for [velopack/velopack#${PR_NUMBER}](${src_url})."
185+
echo
186+
if [ -f "$PR_BODY_FILE" ]; then cat "$PR_BODY_FILE"; fi
187+
echo
188+
echo "---"
189+
echo "_Generated by the \`sync-from-velopack-pr\` workflow. Review before merging; English only — translations regenerate on merge._"
190+
} > "$RUNNER_TEMP/final-pr-body.md"
191+
192+
gh pr create \
193+
--title "$title" \
194+
--body-file "$RUNNER_TEMP/final-pr-body.md" \
195+
--base master \
196+
--head "$branch" \
197+
--label documentation 2>/dev/null \
198+
|| gh pr create \
199+
--title "$title" \
200+
--body-file "$RUNNER_TEMP/final-pr-body.md" \
201+
--base master \
202+
--head "$branch"

0 commit comments

Comments
 (0)