11name : Update Docs
2+
23on :
3- - push
4- - pull_request
5- - workflow_dispatch
4+ push :
5+ branches :
6+ - main # specify branches if needed
7+ pull_request :
8+ workflow_dispatch :
9+
10+ env :
11+ PYTHON_VERSION : ' 3.8'
12+ DEST_REPO : ' openmlsys/html-en'
13+ GIT_USER_NAME : ' GitHub Actions Bot'
14+ GIT_USER_EMAIL : ' github-actions[bot]@users.noreply.github.com'
15+
616jobs :
7- build :
17+ build-and-deploy :
818 runs-on : ubuntu-20.04
19+
920 steps :
10- - uses : actions/checkout@v2
11- - uses : actions/setup-python@v4
21+ - name : Checkout repository
22+ uses : actions/checkout@v3 # Updated to v3
1223 with :
13- python-version : ' 3.8'
14- - run : |
24+ fetch-depth : 0 # Fetch all history for better versioning
25+
26+ - name : Setup Python
27+ uses : actions/setup-python@v4
28+ with :
29+ python-version : ${{ env.PYTHON_VERSION }}
30+ cache : ' pip' # Enable pip caching
31+
32+ - name : Install system dependencies
33+ run : |
1534 sudo apt-get update
1635 sudo apt-get install -y pandoc
17- - run : |
36+
37+ - name : Setup Python virtual environment
38+ run : |
1839 python -m venv venv
1940 source venv/bin/activate
2041 pip install --upgrade pip
42+
43+ - name : Install Python dependencies
44+ run : |
45+ source venv/bin/activate
2146 pip install -r requirements.txt
2247 pip install sphinx-mathjax-offline
48+
49+ - name : Install d2l-book
50+ run : |
51+ source venv/bin/activate
2352 git clone https://github.com/openmlsys/d2l-book.git
2453 cd d2l-book
2554 pip install .
2655 cd ..
56+
57+ - name : Build documentation
58+ run : |
59+ source venv/bin/activate
2760 sh build_html.sh
28- - run : cd ..
29- # Modified these steps for proper authentication
30- - name : Clone and push to html-en
61+
62+ - name : Deploy to html-en repository
63+ if : github.event_name != 'pull_request' # Don't deploy on PRs
64+ env :
65+ GH_TOKEN : ${{ secrets.GH_TOKEN }}
3166 run : |
32- git clone https://${{ secrets.GH_TOKEN }}@github.com/openmlsys/html-en.git
67+ # Clone the destination repository
68+ git clone https://${GH_TOKEN}@github.com/${DEST_REPO}.git
69+
70+ # Copy built documentation
3371 cp -r _build/html/* html-en/
72+
73+ # Configure git
3474 cd html-en
35- git config user.name 'GitHub Actions Bot'
36- git config user.email 'github-actions[bot]@users.noreply.github.com'
37- git add .
38- git commit -m 'update docs'
39- git push https://${{ secrets.GH_TOKEN }}@github.com/openmlsys/html-en.git main
75+ git config user.name "${GIT_USER_NAME}"
76+ git config user.email "${GIT_USER_EMAIL}"
77+
78+ # Check if there are changes to commit
79+ if [[ -n $(git status -s) ]]; then
80+ git add .
81+ git commit -m "docs: update documentation
82+
83+ Automated update by GitHub Actions
84+ Workflow: ${{ github.workflow }}
85+ Run ID: ${{ github.run_id }}
86+ Triggered by: ${{ github.event_name }}"
87+
88+ # Push changes
89+ git push origin main
90+ else
91+ echo "No changes to commit"
92+ fi
93+
94+ - name : Clean up
95+ if : always()
96+ run : |
97+ rm -rf venv
98+ rm -rf html-en
99+ rm -rf d2l-book
0 commit comments