@@ -18,47 +18,107 @@ jobs:
1818 fetch-depth : 0
1919
2020 - name : Set up Python
21- uses : actions/setup-python@v4
21+ uses : actions/setup-python@v5
2222 with :
2323 python-version : ' 3.11'
2424
2525 - name : Setup Graphviz
2626 uses : ts-graphviz/setup-graphviz@v2
2727
28+ - name : Cache Poetry packages
29+ uses : actions/cache@v3
30+ with :
31+ path : ~/.cache/pypoetry
32+ key : ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
33+
34+ - name : Cache pip packages
35+ uses : actions/cache@v3
36+ with :
37+ path : ~/.cache/pip
38+ key : ${{ runner.os }}-pip-${{ hashFiles('**/poetry.lock') }}
39+
2840 - name : Install Dependencies
2941 run : |
42+ set -e
3043 pip install poetry
3144 poetry install --with dev,docs
3245
33- - name : Build Docs with sphinx-multiversion
46+ - name : Build Docs
3447 run : |
35- # Create a temporary directory
36- TEMP_DIR=$(mktemp -d)
37- chmod 777 $TEMP_DIR
38- echo "TEMP_DIR=$TEMP_DIR" >> $GITHUB_ENV
39- echo "Temporary directory is $TEMP_DIR"
40- poetry run sphinx-multiversion docs $TEMP_DIR
41- touch $TEMP_DIR/.nojekyll
42- echo '<meta http-equiv="refresh" content="0; URL='https://saezlab.github.io/corneto/main'" />' > $TEMP_DIR/index.html
43-
44- - name : Deploy to GitHub Pages
48+ set -e
49+ poetry run sphinx-build -b html docs docs/_build/html
50+
51+ - name : Determine doc version
52+ id : set_version
53+ run : |
54+ set -e
55+ case "${GITHUB_REF}" in
56+ refs/tags/*)
57+ version="${GITHUB_REF#refs/tags/}"
58+ ;;
59+ refs/heads/main)
60+ version="main"
61+ ;;
62+ refs/heads/dev)
63+ version="dev"
64+ ;;
65+ *)
66+ echo "Unexpected branch/ref: ${GITHUB_REF}"
67+ version="dev"
68+ ;;
69+ esac
70+ echo "doc_version=${version}" >> $GITHUB_OUTPUT
71+
72+ - name : Generate switcher.json
4573 run : |
46- git config --local user.email "action@github.com"
47- git config --local user.name "GitHub Action"
48-
49- # Now checkout to gh-pages
50- git fetch origin gh-pages
51- git checkout gh-pages || git checkout --orphan gh-pages
52-
53- # Clean existing files for the branch and copy new ones
54- echo "Removing current folder content : $BRANCH_NAME"
55- rm -rf "./$BRANCH_NAME"
56- cp -r "$TEMP_DIR/$BRANCH_NAME" "$BRANCH_NAME"
57-
58- # Adding changes to git
59- git add .
60- git commit -m "Update docs for branch $BRANCH_NAME" --allow-empty
61- git push -u origin gh-pages
62- env :
63- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
64- BRANCH_NAME : ${{ github.head_ref || github.ref_name }}
74+ set -e
75+ poetry run python docs/generate_switcher.py
76+
77+ - name : Create root redirect to latest
78+ run : |
79+ set -e
80+ mkdir -p temp_root
81+ cp docs/switcher.json temp_root/switcher.json
82+ touch temp_root/.nojekyll
83+ cat > temp_root/index.html << EOF
84+ <!DOCTYPE html>
85+ <html>
86+ <head>
87+ <meta charset="utf-8">
88+ <title>Redirecting to main documentation</title>
89+ <meta http-equiv="refresh" content="0; URL=./main/">
90+ <link rel="canonical" href="./main/">
91+ </head>
92+ <body>
93+ <p>Redirecting to <a href="./main/">main documentation</a>...</p>
94+ </body>
95+ </html>
96+ EOF
97+
98+ - name : Deploy content to root
99+ uses : peaceiris/actions-gh-pages@v4
100+ with :
101+ github_token : ${{ secrets.GITHUB_TOKEN }}
102+ publish_dir : ./temp_root
103+ destination_dir : ./
104+ keep_files : true
105+
106+ - name : Deploy versioned docs
107+ uses : peaceiris/actions-gh-pages@v4
108+ with :
109+ github_token : ${{ secrets.GITHUB_TOKEN }}
110+ publish_dir : ./docs/_build/html
111+ destination_dir : ${{ steps.set_version.outputs.doc_version }}
112+ keep_files : true
113+
114+ - name : Deploy latest docs to root
115+ if : ${{ steps.set_version.outputs.doc_version == 'latest' }}
116+ uses : peaceiris/actions-gh-pages@v4
117+ with :
118+ github_token : ${{ secrets.GITHUB_TOKEN }}
119+ publish_dir : ./docs/_build/html
120+ destination_dir : ./
121+ keep_files : true
122+
123+ - name : Clean up temporary files
124+ run : rm -rf temp_root
0 commit comments