-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (85 loc) · 3.56 KB
/
sync-to-site.yml
File metadata and controls
102 lines (85 loc) · 3.56 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
name: Sync Markdown to Site Branch
on:
push:
branches:
- master
workflow_dispatch:
permissions:
contents: write
actions: write
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout master branch
uses: actions/checkout@v4
with:
ref: master
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Sync markdown files to site branch
run: |
# Fetch all branches
git fetch origin
# Check if site branch exists
if git show-ref --verify --quiet refs/remotes/origin/site; then
git checkout site
git pull origin site
else
echo "Error: site branch does not exist. Please create it first."
exit 1
fi
mkdir -p docs/specs
# Get the conversion script from site branch
CONVERT_SCRIPT="scripts/convert_admonitions.py"
# Sync README.md from master root -> docs/index.md
# Convert GitHub markdown to MkDocs format (links + admonitions)
git show master:README.md | sed \
-e 's|\[Mechanical Specs\](mechanical/)|[Mechanical Specs](specs/mechanical.md)|g' \
-e 's|\[Electrical Specs\](electrical/)|[Electrical Specs](specs/electrical.md)|g' \
| python3 "$CONVERT_SCRIPT" > docs/index.md
# Sync LICENSE.md from master root -> docs/LICENSE.md
git show master:LICENSE.md > docs/LICENSE.md 2>/dev/null || true
# Sync mechanical/README.md -> docs/specs/mechanical.md
# Convert GitHub markdown links and admonitions to MkDocs format
git show master:mechanical/README.md 2>/dev/null | sed \
-e 's|\[Electrical\](../electrical/)|[Electrical](electrical.md)|g' \
| python3 "$CONVERT_SCRIPT" > docs/specs/mechanical.md || true
# Sync electrical/README.md -> docs/specs/electrical.md
# Convert GitHub markdown links and admonitions to MkDocs format
git show master:electrical/README.md 2>/dev/null | sed \
-e 's|\[Mechanical\](../mechanical/)|[Mechanical](mechanical.md)|g' \
| python3 "$CONVERT_SCRIPT" > docs/specs/electrical.md || true
# Sync images from mechanical/ and electrical/ -> docs/specs/
for ext in png jpg jpeg gif svg webp; do
for file in $(git ls-tree --name-only master:mechanical/ 2>/dev/null | grep -E "\.$ext$" || true); do
git show "master:mechanical/$file" > "docs/specs/$file"
done
for file in $(git ls-tree --name-only master:electrical/ 2>/dev/null | grep -E "\.$ext$" || true); do
git show "master:electrical/$file" > "docs/specs/$file"
done
done
# Stage all changes
git add -A
# Commit and push if there are changes
if git diff --staged --quiet; then
echo "No changes to commit"
echo "CHANGES_MADE=false" >> $GITHUB_ENV
else
git commit -m "Sync markdown files from master"
git push origin site
echo "CHANGES_MADE=true" >> $GITHUB_ENV
fi
- name: Trigger deploy workflow
if: env.CHANGES_MADE == 'true'
run: |
gh workflow run deploy.yml --ref site
env:
GH_TOKEN: ${{ github.token }}