-
Notifications
You must be signed in to change notification settings - Fork 1
95 lines (75 loc) · 2.71 KB
/
update_docs.yml
File metadata and controls
95 lines (75 loc) · 2.71 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
name: Update Docs
on:
push:
pull_request:
workflow_dispatch:
env:
PYTHON_VERSION: '3.8'
GIT_USER_NAME: 'GitHub Actions Bot'
GIT_USER_EMAIL: 'github-actions[bot]@users.noreply.github.com'
jobs:
build-and-deploy:
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v3 # Updated to v3
with:
fetch-depth: 0 # Fetch all history for better versioning
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip' # Enable pip caching
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y pandoc
- name: Setup Python virtual environment
run: |
python -m venv venv
source venv/bin/activate
pip install --upgrade pip
- name: Install Python dependencies
run: |
source venv/bin/activate
pip install -r requirements.txt
pip install sphinx-mathjax-offline
- name: Install d2l-book
run: |
source venv/bin/activate
git clone https://github.com/openmlsys/d2l-book.git
cd d2l-book
pip install .
cd ..
- name: Build documentation
run: |
source venv/bin/activate
sh build_html.sh
- name: Deploy to pages branch
run: |
# Create and switch to a new worktree for the openmlsys-book-en branch
git worktree add --detach openmlsys-book-en
cd openmlsys-book-en
# Delete openmlsys-book-en branch if it exists and create a new orphan branch
git fetch origin openmlsys-book-en || true
git branch -D openmlsys-book-en || true
git checkout --orphan openmlsys-book-en
# Clean everything except .git directory
find . -mindepth 1 -maxdepth 1 -not -name .git -exec rm -rf {} \;
# Copy built documentation
cp -r ../_build/* .
# Configure git
git config user.name "${GIT_USER_NAME}"
git config user.email "${GIT_USER_EMAIL}"
# Add and commit all changes
git add .
git commit -m "docs: update documentation
Automated update by GitHub Actions
Workflow: ${{ github.workflow }}
Run ID: ${{ github.run_id }}
Triggered by: ${{ github.event_name }}"
# Force push to openmlsys-book-en branch
git push -f origin openmlsys-book-en
# Clean up the worktree
cd ..
git worktree remove openmlsys-book-en