Skip to content

Commit 4f25153

Browse files
authored
docs: refresh json variant walkthrough (#2915)
* docs: refresh json variant walkthrough * ci: gate gpt translate workflow behind manual trigger
1 parent 00427c6 commit 4f25153

File tree

3 files changed

+256
-570
lines changed

3 files changed

+256
-570
lines changed

.github/workflows/docs-commit.translate.yaml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
name: GPT Translate per PR
22

33
on:
4-
pull_request:
5-
types: [closed]
6-
branches:
7-
- main
4+
workflow_dispatch:
5+
inputs:
6+
pr_number:
7+
description: "Optional: PR number or link to sync"
8+
required: false
89

910
jobs:
1011
gpt_translate:
11-
if: >
12-
github.event.pull_request.merged == true &&
13-
!startsWith(github.event.pull_request.head.ref, 'translation-')
1412
runs-on: ubuntu-latest
1513

1614
steps:
@@ -22,6 +20,8 @@ jobs:
2220
- name: Collect changed documentation files
2321
id: collect
2422
uses: actions/github-script@v7
23+
env:
24+
PR_INPUT: ${{ inputs.pr_number }}
2525
with:
2626
script: |
2727
const isDoc = (path) =>
@@ -31,7 +31,21 @@ jobs:
3131
const toCnPath = (path) =>
3232
`docs/cn/${path.slice('docs/en/'.length)}`;
3333
34-
const prNumber = context.payload.pull_request.number;
34+
const rawInput = (process.env.PR_INPUT || '').trim();
35+
let prNumber = null;
36+
if (rawInput) {
37+
const match = rawInput.match(/\d+$/);
38+
if (match) {
39+
prNumber = Number.parseInt(match[0], 10);
40+
}
41+
}
42+
if (!prNumber) {
43+
core.setFailed('Please provide the PR number (or a link ending with the number).');
44+
return;
45+
}
46+
47+
core.setOutput('pr_number', String(prNumber));
48+
3549
const files = await github.paginate(
3650
github.rest.pulls.listFiles,
3751
{
@@ -69,11 +83,12 @@ jobs:
6983
core.setOutput('removed_cn', removals);
7084
core.setOutput('has_inputs', inputSet.size > 0 ? 'true' : 'false');
7185
core.setOutput('has_removals', removedSet.size > 0 ? 'true' : 'false');
86+
core.setOutput('pr_number', String(prNumber));
7287
7388
- name: Exit if no documentation changes
7489
if: steps.collect.outputs.has_inputs != 'true' && steps.collect.outputs.has_removals != 'true'
7590
run: |
76-
echo "No English documentation additions, updates, or deletions detected in PR #${{ github.event.pull_request.number }}."
91+
echo "No English documentation additions, updates, or deletions detected in PR #${{ steps.collect.outputs.pr_number }}."
7792
exit 0
7893
7994
- name: Snapshot existing translation branches
@@ -145,7 +160,7 @@ jobs:
145160
git config user.name "github-actions[bot]"
146161
git config user.email "github-actions[bot]@users.noreply.github.com"
147162
git add -A
148-
git commit -m "chore: sync deletions for PR #${{ github.event.pull_request.number }}"
163+
git commit -m "chore: sync deletions for PR #${{ steps.collect.outputs.pr_number }}"
149164
git push origin "$TRANSLATION_BRANCH"
150165
else
151166
echo "No deletions to commit."
@@ -170,9 +185,9 @@ jobs:
170185
uses: peter-evans/create-pull-request@v6
171186
with:
172187
token: ${{ secrets.GITHUB_TOKEN }}
173-
branch: translation-pr-${{ github.event.pull_request.number }}
188+
branch: translation-pr-${{ steps.collect.outputs.pr_number }}
174189
base: main
175-
commit-message: "chore: sync deletions for PR #${{ github.event.pull_request.number }}"
176-
title: "AI Translate cleanup for PR #${{ github.event.pull_request.number }}"
190+
commit-message: "chore: sync deletions for PR #${{ steps.collect.outputs.pr_number }}"
191+
title: "AI Translate cleanup for PR #${{ steps.collect.outputs.pr_number }}"
177192
body: |
178-
This automated PR removes translated files that no longer have an English source from PR #${{ github.event.pull_request.number }}.
193+
This automated PR removes translated files that no longer have an English source from PR #${{ steps.collect.outputs.pr_number }}.

0 commit comments

Comments
 (0)