-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (122 loc) · 4.48 KB
/
Copy pathsync-wiki.yml
File metadata and controls
147 lines (122 loc) · 4.48 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: Wiki Sync
on:
push:
branches: [main]
paths:
- "help/documentation/**"
- "help/examples/**"
workflow_dispatch:
concurrency:
# Serialize runs so two rapid pushes to `main` don't race when writing to
# the wiki repo (the second run would clobber the first). Cancelling is
# NOT what we want here — we want both runs to land in order — so
# `cancel-in-progress: false` queues instead of dropping.
group: sync-wiki-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: write
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout main repo
uses: actions/checkout@v7.0.0
- name: Checkout wiki repo
uses: actions/checkout@v7.0.0
with:
repository: ${{ github.repository }}.wiki
path: wiki
token: ${{ secrets.GITHUB_TOKEN }}
- name: Sync documentation to wiki
run: |
set -euo pipefail
cd wiki
# Remove old pages (except .git)
find . -maxdepth 1 -name '*.md' -delete
# Build a mapping of old filenames to new wiki page names
declare -A LINK_MAP
for f in ../help/documentation/*.md; do
filename=$(basename "$f")
[ "$filename" = "README.md" ] && continue
clean=$(echo "$filename" \
| sed 's/^[0-9]*-//' \
| sed 's/\.md$//' \
| sed 's/-/ /g' \
| sed 's/\b\(.\)/\u\1/g')
# Map "01-getting-started.md" -> "Getting-Started" (wiki link format)
wiki_link=$(echo "$clean" | sed 's/ /-/g')
LINK_MAP["$filename"]="$wiki_link"
done
# Copy, rename, and rewrite internal links
for f in ../help/documentation/*.md; do
filename=$(basename "$f")
if [ "$filename" = "README.md" ]; then
dest="Home.md"
else
clean=$(echo "$filename" \
| sed 's/^[0-9]*-//' \
| sed 's/\.md$//' \
| sed 's/-/ /g' \
| sed 's/\b\(.\)/\u\1/g')
dest="${clean}.md"
fi
cp "$f" "$dest"
# Rewrite markdown links: [text](01-getting-started.md) -> [text](Getting-Started)
for old_name in "${!LINK_MAP[@]}"; do
wiki_link="${LINK_MAP[$old_name]}"
sed -i "s|(${old_name})|(${wiki_link})|g" "$dest"
done
done
- name: Sync examples to wiki
run: |
set -euo pipefail
cd wiki
# Each subfolder in help/examples/ becomes a wiki page
for dir in ../help/examples/*/; do
dirname=$(basename "$dir")
[ "$dirname" = ".DS_Store" ] && continue
# Convert folder name to page title: "collection-features" -> "Examples Collection Features"
title=$(echo "$dirname" \
| sed 's/-/ /g' \
| sed 's/\b\(.\)/\u\1/g')
dest="Examples ${title}.md"
echo "# Examples: ${title}" > "$dest"
echo "" >> "$dest"
echo "Sample files for the **${title}** feature." >> "$dest"
echo "" >> "$dest"
# Collect all files recursively (skip .DS_Store)
find "$dir" -type f ! -name '.DS_Store' | sort | while read -r f; do
fname=$(basename "$f")
relpath="${f#$dir}"
ext="${fname##*.}"
echo "---" >> "$dest"
echo "" >> "$dest"
echo "## \`${relpath}\`" >> "$dest"
echo "" >> "$dest"
# Pick syntax hint for the code block
case "$ext" in
md) lang="markdown" ;;
js) lang="javascript" ;;
collection) lang="yaml" ;;
*) lang="" ;;
esac
echo "\`\`\`${lang}" >> "$dest"
cat "$f" >> "$dest"
echo "" >> "$dest"
echo "\`\`\`" >> "$dest"
echo "" >> "$dest"
done
done
- name: Commit and push to wiki
run: |
set -euo pipefail
cd wiki
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 wiki changes to commit."
else
git commit -m "docs: sync wiki from help/documentation"
git push
fi