-
Notifications
You must be signed in to change notification settings - Fork 3
76 lines (64 loc) · 2.51 KB
/
wiki-sync.yml
File metadata and controls
76 lines (64 loc) · 2.51 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
name: Sync Wiki
on:
push:
branches:
- main
paths:
- 'wiki/**'
permissions:
contents: write
jobs:
sync-wiki:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Generate Sidebar
run: |
cd wiki
{
echo '<!-- This file is auto-generated from the wiki/ folder structure. Do not edit manually. -->'
echo ''
echo '**[Home](Home)**'
# Root-level pages (except Home, _Sidebar, _Footer)
for f in $(find . -maxdepth 1 -name '*.md' ! -name 'Home.md' ! -name '_Sidebar.md' ! -name '_Footer.md' -exec basename {} .md \; | sort -f); do
display=$(echo "$f" | sed 's/-/ /g')
echo "- [$display]($f)"
done
# Grouped pages from subdirectories
find . -mindepth 1 -maxdepth 1 -type d | sed 's|^\./||' | sort -f | while IFS= read -r dir; do
echo ''
echo "**$dir**"
echo ''
for f in $(find "$dir" -maxdepth 1 -name '*.md' -exec basename {} .md \; | sort -f); do
display=$(echo "$f" | sed 's/-/ /g')
echo "- [$display]($f)"
done
done
} > _Sidebar.md
- name: Sync to Wiki
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Configure git
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Clone the wiki repository
wiki_url="https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.wiki.git"
git clone "$wiki_url" /tmp/wiki-repo
# Remove all existing wiki content (except .git)
find /tmp/wiki-repo -maxdepth 1 -not -name '.git' -not -name '.' -delete 2>/dev/null || true
# Copy the generated sidebar
cp wiki/_Sidebar.md /tmp/wiki-repo/
# Flatten all .md files from wiki/ (including subdirectories) to wiki repo root
find wiki -name '*.md' ! -name '_Sidebar.md' -exec cp {} /tmp/wiki-repo/ \;
# Push changes if there are any
cd /tmp/wiki-repo
git add -A
if git diff --cached --quiet; then
echo "No changes to sync."
else
git commit -m "Sync wiki from main repository ($(date -u '+%Y-%m-%d %H:%M:%S UTC'))"
git push
echo "Wiki synced successfully."
fi