-
Notifications
You must be signed in to change notification settings - Fork 4
107 lines (95 loc) · 4.01 KB
/
Copy pathsync-docs.yml
File metadata and controls
107 lines (95 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: Sync protocol docs to docs.farcaster.xyz
on:
workflow_dispatch:
# Disabled automatic sync — run manually via workflow_dispatch when ready
# push:
# branches: [main]
# paths:
# - "apps/docs/src/app/(docs)/**"
# - "apps/docs/src/components/docs/**"
# - "apps/docs/src/app/SKILL.md/**"
# - "apps/docs/snap-sidebar.json"
jobs:
sync-docs:
concurrency:
group: sync-docs-main
cancel-in-progress: true
runs-on: ubuntu-latest
steps:
- name: Checkout source repo
uses: actions/checkout@v4
with:
path: snap
- name: Checkout docs repo
uses: actions/checkout@v4
with:
repository: farcasterxyz/docs
token: ${{ secrets.DOCS_SYNC_TOKEN }}
path: docs
ref: main
- name: Sync protocol docs to docs repo
run: |
SNAP_DOCS="$GITHUB_WORKSPACE/snap/apps/docs/src/app/(docs)"
SNAP_COMPONENTS="$GITHUB_WORKSPACE/snap/apps/docs/src/components/docs"
DOCS_DEST="$GITHUB_WORKSPACE/docs/src/app/(docs)/snap"
DOCS_COMPONENTS="$GITHUB_WORKSPACE/docs/src/components/docs"
# Clean destination
rm -rf "$DOCS_DEST"
mkdir -p "$DOCS_DEST"
# Copy MDX pages, flattening route groups like (learn), (create), (spec), (integrate)
find "$SNAP_DOCS" -name "page.mdx" | while read -r file; do
# Get path relative to SNAP_DOCS
rel="${file#$SNAP_DOCS/}"
# Strip route group dirs from path: (learn)/examples/page.mdx → examples/page.mdx
dest=$(echo "$rel" | sed 's|([^)]*)/||g')
dest_dir=$(dirname "$dest")
mkdir -p "$DOCS_DEST/$dest_dir"
cp "$file" "$DOCS_DEST/$dest"
done
# Copy snap-layout.tsx as layout.tsx for the snap section
cp "$SNAP_DOCS/snap-layout.tsx" "$DOCS_DEST/layout.tsx"
# Copy interactive components (clean up stale subdirectory from earlier workflow versions)
rm -rf "$DOCS_COMPONENTS/snap"
mkdir -p "$DOCS_COMPONENTS"
shopt -s nullglob
snap_component_files=("$SNAP_COMPONENTS"/*.tsx)
shopt -u nullglob
if [ ${#snap_component_files[@]} -gt 0 ]; then
cp "${snap_component_files[@]}" "$DOCS_COMPONENTS/"
fi
# Rewrite internal absolute markdown links to live under /snap.
find "$DOCS_DEST" -name "page.mdx" | while read -r file; do
# Fix bare root link [text](/) to [text](/snap)
sed -i 's|\](/)|](/snap)|g' "$file"
# Fix /llms.txt → /snap/llms.txt
sed -i 's|\](/llms.txt)|](/snap/llms.txt)|g' "$file"
# Rewrite docs-style absolute links, skipping those already under /snap
# and machine-readable/file endpoints with an extension in the first segment.
perl -0pi -e 's{\]\(/(?!snap(?:/|[#?]|$))([A-Za-z0-9_-]+(?:/[A-Za-z0-9_-]+)*)([?#][^)]+)?\)}{](/snap/$1$2)}g' "$file"
done
# Copy sidebar JSON for docs nav
SNAP_SIDEBAR="$GITHUB_WORKSPACE/snap/apps/docs/snap-sidebar.json"
if [ -f "$SNAP_SIDEBAR" ]; then
cp "$SNAP_SIDEBAR" "$GITHUB_WORKSPACE/docs/src/lib/snap-sidebar.json"
fi
# Copy SKILL.md from public dir
SNAP_SKILL="$GITHUB_WORKSPACE/snap/apps/docs/public/SKILL.md"
DOCS_SKILL="$GITHUB_WORKSPACE/docs/public/snap"
if [ -f "$SNAP_SKILL" ]; then
mkdir -p "$DOCS_SKILL"
cp "$SNAP_SKILL" "$DOCS_SKILL/SKILL.md"
fi
- name: Push changes
working-directory: docs
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
if git diff --cached --quiet; then
echo "No changes to sync"
else
git commit \
-m "chore: sync protocol docs" \
-m "Source: ${{ github.sha }}"
git push origin main
fi