Skip to content

Commit d932e41

Browse files
authored
Improve automated workflows (#441)
1 parent 225919a commit d932e41

4 files changed

Lines changed: 87 additions & 27 deletions

File tree

.github/workflows/improve-docs.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ jobs:
5050
# - name: Install Codex
5151
# run: npm install -g @openai/codex
5252

53+
# ── Generate a random suffix for the branch name ─────────────────
54+
- name: Generate branch suffix
55+
id: suffix
56+
run: echo "value=$(openssl rand -hex 2)" >> "$GITHUB_OUTPUT"
57+
5358
# ── Run the improvement script ────────────────────────────────────
5459
- name: Improve documentation
5560
id: improve
@@ -71,13 +76,26 @@ jobs:
7176
} >> "$GITHUB_OUTPUT"
7277
fi
7378
79+
# Pass the AI-generated PR title to subsequent steps
80+
if [ -f /tmp/ai_pr_title.txt ]; then
81+
delimiter="EOF_$(openssl rand -hex 8)"
82+
{
83+
echo "pr_title<<${delimiter}"
84+
cat /tmp/ai_pr_title.txt
85+
echo ""
86+
echo "${delimiter}"
87+
} >> "$GITHUB_OUTPUT"
88+
else
89+
echo "pr_title=[Auto] [Improve] Documentation improvement" >> "$GITHUB_OUTPUT"
90+
fi
91+
7492
# ── Create Pull Request ───────────────────────────────────────────
7593
- name: Create Pull Request
7694
uses: peter-evans/create-pull-request@v7
7795
with:
7896
token: ${{ secrets.GITHUB_TOKEN }}
79-
commit-message: ${{ steps.improve.outputs.summary }}
80-
title: "Auto: Improve documentation"
97+
commit-message: ${{ steps.improve.outputs.pr_title }}
98+
title: ${{ steps.improve.outputs.pr_title }}
8199
body: |
82100
This PR was automatically generated by the **Improve documentation** workflow.
83101
@@ -92,6 +110,6 @@ jobs:
92110
93111
**Please review the changes carefully before merging.**
94112
base: main
95-
branch: auto/improve-docs
113+
branch: auto/improve-docs-${{ steps.suffix.outputs.value }}
96114
delete-branch: true
97-
labels: automated,documentation
115+
labels: automated,improvement

.github/workflows/update-docs-from-commits.yml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ jobs:
5050
# - name: Install Codex
5151
# run: npm install -g @openai/codex
5252

53+
# ── Generate a random suffix for the branch name ─────────────────
54+
- name: Generate branch suffix
55+
id: suffix
56+
run: echo "value=$(openssl rand -hex 2)" >> "$GITHUB_OUTPUT"
57+
5358
# ── Run the update script ─────────────────────────────────────────
5459
- name: Update documentation from recent commits
5560
id: update
@@ -80,13 +85,26 @@ jobs:
8085
} >> "$GITHUB_OUTPUT"
8186
fi
8287
88+
# Pass the AI-generated PR title to subsequent steps
89+
if [ -f /tmp/ai_pr_title.txt ]; then
90+
delimiter="EOF_$(openssl rand -hex 8)"
91+
{
92+
echo "pr_title<<${delimiter}"
93+
cat /tmp/ai_pr_title.txt
94+
echo ""
95+
echo "${delimiter}"
96+
} >> "$GITHUB_OUTPUT"
97+
else
98+
echo "pr_title=[Auto] [Update] Documentation update from commits" >> "$GITHUB_OUTPUT"
99+
fi
100+
83101
# ── Create Pull Request ───────────────────────────────────────────
84102
- name: Create Pull Request
85103
uses: peter-evans/create-pull-request@v7
86104
with:
87105
token: ${{ secrets.GITHUB_TOKEN }}
88-
commit-message: ${{ steps.update.outputs.summary }}
89-
title: "Auto: Update documentation based on recent GDevelop changes"
106+
commit-message: ${{ steps.update.outputs.pr_title }}
107+
title: ${{ steps.update.outputs.pr_title }}
90108
body: |
91109
This PR was automatically generated by the **Update docs from GDevelop commits** workflow.
92110
@@ -103,6 +121,6 @@ jobs:
103121
104122
**Please review the changes carefully before merging.**
105123
base: main
106-
branch: auto/update-docs-from-commits
124+
branch: auto/update-docs-from-commits-${{ steps.suffix.outputs.value }}
107125
delete-branch: true
108-
labels: automated,documentation
126+
labels: automated,update

scripts/improve-docs.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,23 @@ IMPORTANT CONSTRAINTS
179179
180180
WHEN YOU ARE DONE
181181
-----------------
182-
Edit the file "automated_updates_data.json" in ${REPO_ROOT}/ and add a new
183-
entry at the END of the "last_improved_things" array with this format:
182+
1. Edit the file "automated_updates_data.json" in ${REPO_ROOT}/ and add a new
183+
entry at the END of the "last_improved_things" array with this format:
184184
185-
{ "date": "${today}", "summary": "<one-line description of what you improved>" }
185+
{ "date": "${today}", "summary": "<one-line description of what you improved>" }
186186
187-
For example, the file might look like:
188-
{
189-
"last_automated_updates_commit": null,
190-
"last_improved_things": [
191-
{ "date": "${today}", "summary": "Improved objects/sprite/index.md — clarified animation looping behaviour" }
192-
]
193-
}
187+
For example, the file might look like:
188+
{
189+
"last_automated_updates_commit": null,
190+
"last_improved_things": [
191+
{ "date": "${today}", "summary": "Improved objects/sprite/index.md — clarified animation looping behaviour" }
192+
]
193+
}
194+
195+
2. Create a file at /tmp/ai_pr_title.txt containing ONLY a single line of
196+
10–15 words that summarises the changes you made. This will be used as the
197+
pull-request title. Prefix it with "[Auto] [Improve]".
198+
Example: [Auto] [Improve] Clarified sprite animation looping and added missing tween parameters
194199
195200
Make your changes now.`;
196201
}
@@ -204,17 +209,24 @@ function invokeAI(promptFile, cwd) {
204209

205210
if (AI_PROVIDER === "claude") {
206211
// ── Claude Code ──────────────────────────────────────────────────────
207-
cmd = `cat "${promptFile}" | claude -p --dangerously-skip-permissions`;
212+
cmd = `cat "${promptFile}" | claude -p --verbose --dangerously-skip-permissions 2>&1`;
208213
// ── To use Codex instead, comment the block above and uncomment below.
209214
} else if (AI_PROVIDER === "codex") {
210215
// ── OpenAI Codex ─────────────────────────────────────────────────────
211-
cmd = `codex --full-auto -q "$(cat '${promptFile}')"`;
216+
cmd = `codex --full-auto -q "$(cat '${promptFile}')" 2>&1`;
212217
opts.shell = "/bin/bash";
213218
} else {
214219
throw new Error(`Unknown AI_PROVIDER: "${AI_PROVIDER}". Use "claude" or "codex".`);
215220
}
216221

217-
const output = execSync(cmd, { ...opts, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
222+
let output;
223+
try {
224+
output = execSync(cmd, { ...opts, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
225+
} catch (err) {
226+
console.error(`AI command exited with code ${err.status}`);
227+
output = (err.stdout || "") + (err.stderr || "");
228+
}
229+
218230
console.log("── AI agent output ─────────────────────────────────────────");
219231
console.log(output);
220232
console.log("── End of AI agent output ──────────────────────────────────");

scripts/update-docs-from-commits.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,14 @@ IMPORTANT CONSTRAINTS
213213
214214
WHEN YOU ARE DONE
215215
-----------------
216-
Output a brief summary (2-3 lines) of the documentation changes you made,
217-
or state that no changes were needed. This summary will be included in the
218-
pull request description.
216+
1. Output a brief summary (2-3 lines) of the documentation changes you made,
217+
or state that no changes were needed. This summary will be included in the
218+
pull request description.
219+
220+
2. Create a file at /tmp/ai_pr_title.txt containing ONLY a single line of
221+
10–15 words that summarises the changes you made. This will be used as the
222+
pull-request title. Prefix it with "[Auto] [Update]".
223+
Example: [Auto] [Update] Updated publishing docs to reflect new export options for Android
219224
220225
Make your changes now.`;
221226
}
@@ -229,17 +234,24 @@ function invokeAI(promptFile, cwd) {
229234

230235
if (AI_PROVIDER === "claude") {
231236
// ── Claude Code ──────────────────────────────────────────────────────
232-
cmd = `cat "${promptFile}" | claude -p --dangerously-skip-permissions`;
237+
cmd = `cat "${promptFile}" | claude -p --verbose --dangerously-skip-permissions 2>&1`;
233238
// ── To use Codex instead, comment the block above and uncomment below.
234239
} else if (AI_PROVIDER === "codex") {
235240
// ── OpenAI Codex ─────────────────────────────────────────────────────
236-
cmd = `codex --full-auto -q "$(cat '${promptFile}')"`;
241+
cmd = `codex --full-auto -q "$(cat '${promptFile}')" 2>&1`;
237242
opts.shell = "/bin/bash";
238243
} else {
239244
throw new Error(`Unknown AI_PROVIDER: "${AI_PROVIDER}". Use "claude" or "codex".`);
240245
}
241246

242-
const output = execSync(cmd, { ...opts, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
247+
let output;
248+
try {
249+
output = execSync(cmd, { ...opts, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
250+
} catch (err) {
251+
console.error(`AI command exited with code ${err.status}`);
252+
output = (err.stdout || "") + (err.stderr || "");
253+
}
254+
243255
console.log("── AI agent output ─────────────────────────────────────────");
244256
console.log(output);
245257
console.log("── End of AI agent output ──────────────────────────────────");

0 commit comments

Comments
 (0)