Skip to content

Commit d4328bf

Browse files
committed
feat: update sync docs
1 parent 36f798e commit d4328bf

File tree

3 files changed

+35
-24
lines changed

3 files changed

+35
-24
lines changed

.github/workflows/update-en-docs.yml renamed to .github/workflows/sync-docs.yml

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Update Next.js English Documentation
1+
name: Sync Next.js Official Documentation
22

33
on:
44
workflow_dispatch: # Manual trigger
@@ -13,61 +13,71 @@ permissions:
1313
pull-requests: write
1414

1515
jobs:
16-
update-docs:
17-
name: Update Next.js Docs
16+
check-branch:
17+
name: Check if PR branch exists
1818
runs-on: ubuntu-latest
19+
outputs:
20+
should_sync: ${{ steps.check_branch.outputs.should_sync }}
1921
steps:
20-
- name: Checkout repository
21-
uses: actions/checkout@v4
22-
with:
23-
fetch-depth: 0
24-
2522
- name: Check if PR branch exists
2623
id: check_branch
2724
run: |
28-
if git ls-remote --heads origin "docs/sync-nextjs-documentation" | grep -q "docs/sync-nextjs-documentation"; then
25+
if git ls-remote --heads https://github.com/${{ github.repository }}.git | grep -q "docs/sync-nextjs-documentation"; then
2926
echo "Branch already exists, skipping update"
30-
echo "branch_exists=true" >> $GITHUB_OUTPUT
27+
echo "should_sync=false" >> $GITHUB_OUTPUT
3128
else
3229
echo "Branch does not exist, proceeding with update"
33-
echo "branch_exists=false" >> $GITHUB_OUTPUT
30+
echo "should_sync=true" >> $GITHUB_OUTPUT
3431
fi
3532
33+
sync-docs:
34+
name: Sync Next.js Docs
35+
runs-on: ubuntu-latest
36+
needs: check-branch
37+
if: needs.check-branch.outputs.should_sync == 'true'
38+
steps:
39+
- name: Checkout repository
40+
uses: actions/checkout@v4
41+
with:
42+
fetch-depth: 0
43+
3644
- name: Clone Next.js repository (canary)
37-
if: steps.check_branch.outputs.branch_exists == 'false'
3845
run: |
3946
git clone --depth 1 --branch canary --single-branch https://github.com/vercel/next.js.git nextjs-canary
4047
mkdir -p apps/docs/content/en/docs
4148
rsync -av --delete nextjs-canary/docs/ apps/docs/content/en/docs/ --exclude="13" --exclude="14"
4249
rm -rf nextjs-canary
4350
4451
- name: Clone Next.js repository (v14.2.28)
45-
if: steps.check_branch.outputs.branch_exists == 'false'
4652
run: |
4753
git clone --depth 1 --branch v14.2.28 --single-branch https://github.com/vercel/next.js.git nextjs-v14
4854
mkdir -p apps/docs/content/en/docs/14
4955
rsync -av --delete nextjs-v14/docs/ apps/docs/content/en/docs/14/
5056
rm -rf nextjs-v14
5157
5258
- name: Clone Next.js repository (v13.5.11)
53-
if: steps.check_branch.outputs.branch_exists == 'false'
5459
run: |
5560
git clone --depth 1 --branch v13.5.11 --single-branch https://github.com/vercel/next.js.git nextjs-v13
5661
mkdir -p apps/docs/content/en/docs/13
5762
rsync -av --delete nextjs-v13/docs/ apps/docs/content/en/docs/13/
5863
rm -rf nextjs-v13
5964
65+
- name: Setup Tools
66+
uses: ./.github/actions/setup
67+
68+
- name: Sync blog & learn
69+
run: |
70+
node packages/crawler/dist/index.js
71+
6072
- name: Find available translation locales
61-
if: steps.check_branch.outputs.branch_exists == 'false'
6273
id: find_locales
6374
run: |
6475
cd apps/docs/content
65-
LOCALES=$(find . -maxdepth 1 -type d | grep -v "^.$" | grep -v "/en$" | sed 's|^\./||')
76+
LOCALES=$(find . -maxdepth 1 -type d | grep -v "^.$" | grep -v "/en$" | sed 's|^\./||' | tr '\n' ' ' | sed 's/ $//')
6677
echo "Available translation locales: $LOCALES"
6778
echo "locales=$LOCALES" >> $GITHUB_OUTPUT
6879
6980
- name: Stage changes to detect renames
70-
if: steps.check_branch.outputs.branch_exists == 'false'
7181
run: |
7282
# Stage all changes so Git can detect renames
7383
git add .
@@ -76,13 +86,12 @@ jobs:
7686
git status --porcelain
7787
7888
- name: Process file renames and deletions
79-
if: steps.check_branch.outputs.branch_exists == 'false'
8089
run: |
8190
# Get list of renamed files from git status
82-
RENAMES=$(git status --porcelain | grep -E "^R[[:space:]]+apps/docs/content/en/docs" | sed 's/^R[[:space:]]*//')
91+
RENAMES=$(git status --porcelain | grep -E "^R[[:space:]]+apps/docs/content/en" | sed 's/^R[[:space:]]*//')
8392
8493
# Get list of deleted files from git status
85-
DELETES=$(git status --porcelain | grep -E "^D[[:space:]]+apps/docs/content/en/docs" | sed 's/^D[[:space:]]*//')
94+
DELETES=$(git status --porcelain | grep -E "^D[[:space:]]+apps/docs/content/en" | sed 's/^D[[:space:]]*//')
8695
8796
# Generate current timestamp in ISO format
8897
CURRENT_TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z")
@@ -184,7 +193,6 @@ jobs:
184193
fi
185194
186195
- name: Check for modifications
187-
if: steps.check_branch.outputs.branch_exists == 'false'
188196
id: check_changes
189197
run: |
190198
if [[ $(git status --porcelain | grep -E "apps/docs/content/" | wc -l) -gt 0 ]]; then
@@ -196,7 +204,7 @@ jobs:
196204
fi
197205
198206
- name: Create Pull Request
199-
if: steps.check_branch.outputs.branch_exists == 'false' && steps.check_changes.outputs.has_changes == 'true'
207+
if: steps.check_changes.outputs.has_changes == 'true'
200208
uses: peter-evans/create-pull-request@v5
201209
with:
202210
token: ${{ secrets.GITHUB_TOKEN }}
@@ -207,6 +215,8 @@ jobs:
207215
- Updates from `canary` branch to `apps/docs/content/en/docs`
208216
- Updates from `v14.2.28` branch to `apps/docs/content/en/docs/14`
209217
- Updates from `v13.5.11` branch to `apps/docs/content/en/docs/13`
218+
- Updates blog to `apps/docs/content/en/blog`
219+
- Updates learn to `apps/docs/content/en/learn`
210220
branch: docs/sync-nextjs-documentation
211221
delete-branch: true
212222
base: main

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"docs:dev": "pnpm --filter @next-i18n/docs dev",
1919
"docs:build": "pnpm --filter @next-i18n/docs build",
2020
"docs:start": "pnpm --filter @next-i18n/docs start",
21-
"docs:update-search-index": "pnpm --filter @next-i18n/docs update-search-index"
21+
"docs:update-search-index": "pnpm --filter @next-i18n/docs update-search-index",
22+
"crawler": "node packages/crawler/dist/index.js"
2223
},
2324
"keywords": [],
2425
"devDependencies": {

packages/crawler/src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function writeFiles(learns: Writeable[]) {
2222
try {
2323
await fs$.mkdir(dirname, { recursive: true });
2424
await fs$.writeFile(fileName, learn.content);
25-
console.log(`Written file to ${fileName}`);
25+
console.log(`Write file to ${fileName}`);
2626
} catch (error) {
2727
console.error(`Failed to write file ${learn.filename}:`, error);
2828
}

0 commit comments

Comments
 (0)