Repository navigation
93 lines (82 loc) · 2.89 KB
/
Copy pathsync-docs.yml
File metadata and controls
93 lines (82 loc) · 2.89 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
name: Sync Docs to Mintlify
on:
push:
branches: [main]
paths:
- "docs/**"
workflow_dispatch:
env:
REPO_SLUG: web-visuals
REPO_TAB_LABEL: Web Visuals
jobs:
sync-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout source repo
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Get changed/added/deleted files in docs/
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
find docs/ -type f > changed_docs.txt
touch deleted_docs.txt
else
git diff --name-only --diff-filter=ACM HEAD~1 HEAD -- docs/ > changed_docs.txt
git diff --name-only --diff-filter=D HEAD~1 HEAD -- docs/ > deleted_docs.txt
fi
echo "Changed/added docs:"; cat changed_docs.txt
echo "Deleted docs:"; cat deleted_docs.txt
- name: Checkout Mintlify docs repo
uses: actions/checkout@v4
with:
repository: Idopt-Lab/idopt-docs
token: ${{ secrets.DOCS_PUSH_TOKEN }}
path: mintlify-docs
- name: Clean up misplaced root-level synced files (all docs, not just changed)
run: |
find docs/ -type f | while IFS= read -r file; do
rel_path="${file#docs/}"
misplaced="mintlify-docs/$rel_path"
if [ -f "$misplaced" ]; then
rm "$misplaced"
echo "Removed misplaced: $misplaced"
fi
done
- name: Copy new/changed docs to Mintlify repo (under repo subfolder)
run: |
while IFS= read -r file; do
if [ -f "$file" ]; then
rel_path="${file#docs/}"
dest_dir="mintlify-docs/$REPO_SLUG/$(dirname "$rel_path")"
mkdir -p "$dest_dir"
cp "$file" "mintlify-docs/$REPO_SLUG/$rel_path"
echo "Synced: $file -> mintlify-docs/$REPO_SLUG/$rel_path"
fi
done < changed_docs.txt
- name: Delete removed docs from Mintlify repo
run: |
while IFS= read -r file; do
rel_path="${file#docs/}"
target="mintlify-docs/$REPO_SLUG/$rel_path"
if [ -f "$target" ]; then
rm "$target"
echo "Deleted: $target"
fi
done < deleted_docs.txt
- name: Update docs.json navigation and branding
run: |
cd mintlify-docs
python3 $GITHUB_WORKSPACE/.github/scripts/update_docs_nav.py
- name: Commit and push to Mintlify docs repo
run: |
cd mintlify-docs
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
if git diff --staged --quiet; then
echo "No changes to push."
else
git commit -m "chore: sync docs from $REPO_SLUG"
git push
fi