-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (110 loc) · 4.29 KB
/
md-to-html.yml
File metadata and controls
132 lines (110 loc) · 4.29 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
name: Build and Deploy Jupyter Book
on:
push:
paths:
- 'Markdowns/**.md'
- 'Markdowns/**.ipynb'
- 'FrontPage/*.md'
- '!JupyterBook/**'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
persist-credentials: false
fetch-depth: 0
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install Jupyter Book and dependencies
run: |
python -m pip install --upgrade pip
# Check if jupyter-book is installed
if ! command -v jupyter-book &> /dev/null; then
pip install jupyter-book
fi
- name: Install Dependencies from requirements.txt
run: |
pip install -r .github/workflows/requirements.txt
- name: Prepare files for Jupyter Book, Clean old build
run: |
rm -rf JupyterBook/_build
rm -f JupyterBook/*.md
rm -f JupyterBook/*.ipynb
rm -f JupyterBook/_toc.yml
cp FrontPage/intro.md JupyterBook/
rsync -av --include='*.md' --include='*.ipynb' --include='*/' --exclude='*' Markdowns/ JupyterBook/
- name: Generate TOC
run: |
echo "format: jb-book" > JupyterBook/_toc.yml
echo "root: intro" >> JupyterBook/_toc.yml
echo "parts:" >> JupyterBook/_toc.yml
# Loop through each folder in /Markdowns
for dir in Markdowns/*; do
if [ -d "$dir" ]; then
heading=$(basename -- "$dir")
echo " - caption: $heading" >> JupyterBook/_toc.yml
echo " chapters:" >> JupyterBook/_toc.yml
# Check for nested directories with overview.md
for sub_dir in "$dir"/*; do
if [ -d "$sub_dir" ] && [ -f "$sub_dir/overview.md" ]; then
sub_heading=$(basename -- "$sub_dir")
echo " - file: $heading/$sub_heading/overview" >> JupyterBook/_toc.yml
echo " sections:" >> JupyterBook/_toc.yml
# Loop through other markdown files in the sub-directory excluding overview.md
for file in "$sub_dir"/*.{md,ipynb}; do
if [[ "$file" != "$sub_dir/overview.md" ]]; then
baseName=$(basename -- "$file")
noExtName="${baseName%.*}"
echo " - file: $heading/$sub_heading/$noExtName" >> JupyterBook/_toc.yml
fi
done
fi
done
# Add markdown files from the first directory layer
for file in "$dir"/*.{md,ipynb}; do
baseName=$(basename -- "$file")
noExtName="${baseName%.*}"
echo " - file: $heading/$noExtName" >> JupyterBook/_toc.yml
done
fi
done
- name: Check JupyterBook file structure
run: |
echo "Checking the file structure in JupyterBook:"
if command -v tree &> /dev/null; then
tree JupyterBook
else
echo "The 'tree' command isn't available. Using 'find' instead."
find JupyterBook -print
fi
- name: Print TOC for Debugging
run: |
echo "Content of _toc.yml:"
cat JupyterBook/_toc.yml
# Build the Jupyter Book
- name: Build Jupyter Book
run: |
jupyter-book build JupyterBook
# Commit and push changes if any exist
- name: Commit and push changes
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
git add .
git commit -m "Automated updates from GitHub Actions"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.MY_GITHUB_TOKEN }}
branch: ${{ github.main }}
# Deploy to GitHub Pages (push to the gh-pages branch)
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3.8.0
with:
github_token: ${{ secrets.MY_GITHUB_TOKEN }}
publish_dir: ./JupyterBook/_build/html
publish_branch: gh-pages