1- name : Build and publish docs
1+ name : Build and Publish Multi-Version Docs
22
33on :
44 push :
55 branches :
6- - dev
7- - multiversion
6+ - dev
7+ - multiversion
8+ release :
9+ types :
10+ - published
811 pull_request :
912 branches :
1013 - dev
@@ -18,16 +21,17 @@ permissions:
1821 contents : write
1922
2023jobs :
21- publish :
22- name : build and publish docs
24+ build-docs :
25+ name : Build Documentation
2326 runs-on : ubuntu-latest
2427 steps :
25- - uses : actions/checkout@v4
28+ - name : Checkout code
29+ uses : actions/checkout@v4
2630 with :
2731 fetch-depth : 0
2832 fetch-tags : true
2933
30- - name : set up python 3.10
34+ - name : Set up Python 3.10
3135 uses : actions/setup-python@v5
3236 with :
3337 python-version : " 3.10"
@@ -40,43 +44,93 @@ jobs:
4044 run : |
4145 sudo apt install pandoc
4246
43- - name : install dependencies
47+ - name : Install dependencies
4448 run : |
4549 poetry install --with docs
4650
47- - name : Test documentation
51+ - name : Test documentation build
52+ if : github.event_name == 'pull_request' && github.base_ref == 'dev'
4853 run : |
49- make test-docs
50-
51- # - name: build documentation
52- # if: ${{ github.ref != 'refs/heads/dev' }}
53- # run: |
54- # make docs
55- #
56- - name : build multiversion documentation
57- # if: ${{ github.ref == 'refs/heads/dev' }}
54+ echo "Testing documentation build for PR..."
55+ sphinx-build docs/source docs/build/html
56+
57+
58+ - name : Generate missing tags list
59+ if : github.event_name == 'push' || github.event_name == 'release'
60+ id : missing_tags
5861 run : |
59- make multi-version-docs
62+ # Fetch existing documentation versions from gh-pages
63+ mkdir -p existing_versions
64+ git fetch origin gh-pages --depth=1
65+ git checkout origin/gh-pages -- docs/versions || true
66+
67+ # List existing tags and built versions
68+ EXISTING_VERSIONS=$(ls docs/versions | tr '\n' ' ')
69+ ALL_TAGS=$(git tag --list "v*" | tr '\n' ' ')
70+
71+ # Find missing tags
72+ MISSING_TAGS=""
73+ for TAG in $ALL_TAGS; do
74+ if [[ ! " $EXISTING_VERSIONS " =~ " $TAG " ]]; then
75+ MISSING_TAGS+="$TAG "
76+ fi
77+ done
78+
79+ echo "Missing tags: $MISSING_TAGS"
80+ echo "missing_tags=${MISSING_TAGS}" >> $GITHUB_ENV
6081
61- - name : save branch name without slashes
62- env :
63- BRANCH_NAME : ${{ github.head_ref || github.ref_name }}
82+ - name : Build documentation for missing tags
83+ if : env.missing_tags != ''
6484 run : |
65- BRANCH_NAME=${{ env.BRANCH_NAME }}
66- BRANCH_NAME=${BRANCH_NAME////_}
67- echo BRANCH_NAME=${BRANCH_NAME} >> $GITHUB_ENV
85+ for TAG in ${{ env.missing_tags }}; do
86+ echo "Building docs for $TAG..."
87+ git checkout $TAG
88+ mkdir -p docs/build/versions/$TAG
89+ sphinx-build docs/source docs/build/versions/$TAG
90+ done
6891
69- - name : Upload artifact
70- uses : actions/upload-artifact@v4
71- with :
72- name : ${{ format('github-pages-for-branch-{0}', env.BRANCH_NAME) }}
73- path : docs/build/
74- retention-days : 3
92+ - name : Build documentation for dev branch
93+ if : github.ref == 'refs/heads/dev'
94+ run : |
95+ echo "Building docs for dev branch..."
96+ sphinx-build docs/source docs/build/versions/dev
7597
7698 - name : Deploy to GitHub Pages
77- uses : JamesIves/ github[email protected] 78- # if: ${{ github.ref == 'refs/heads/dev' }}
99+ if : github.event_name != 'pull_request'
100+ uses : peaceiris/actions-gh-pages@v3
79101 with :
80- branch : gh-pages
81- folder : docs/build/html/
82- single-commit : True
102+ github_token : ${{ github.token }}
103+ publish_dir : docs/build/versions
104+ keep_files : true
105+
106+ update-static :
107+ name : Update Static Files in Old Releases
108+ runs-on : ubuntu-latest
109+ needs : build-docs
110+
111+ steps :
112+ - name : Checkout gh-pages branch
113+ uses : actions/checkout@v4
114+ with :
115+ ref : gh-pages
116+ fetch-depth : 0
117+
118+ - name : Update _static in all versions
119+ run : |
120+ # Define path to the updated _static directory
121+ UPDATED_STATIC_DIR=docs/source/_static
122+ TARGET_STATIC_DIRS=$(find docs/versions/ -type d -name "_static")
123+
124+ # Copy updated _static to all versions
125+ for DIR in $TARGET_STATIC_DIRS; do
126+ echo "Updating $DIR..."
127+ cp -r ${UPDATED_STATIC_DIR}/* ${DIR}/
128+ done
129+
130+ - name : Commit and push changes
131+ run : |
132+ git config user.name "github-actions"
133+ git config user.email "[email protected] " 134+ git add .
135+ git commit -m "Update _static files in all documentation versions" || echo "No changes to commit"
136+ git push
0 commit comments