From aec3a0c76761dde3f01c7a4c7b53ead7c3d708e4 Mon Sep 17 00:00:00 2001 From: IonutMuthi Date: Fri, 7 Feb 2025 05:27:43 -0500 Subject: [PATCH] doc: update workflow to consider versioning Signed-off-by: IonutMuthi --- .github/workflows/generate_doc.yml | 64 ++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 22 deletions(-) diff --git a/.github/workflows/generate_doc.yml b/.github/workflows/generate_doc.yml index f76cd0a5a..0ba8de0e6 100644 --- a/.github/workflows/generate_doc.yml +++ b/.github/workflows/generate_doc.yml @@ -18,6 +18,15 @@ jobs: with: python-version: "3.x" + + - name: Differentiate main from tag + run: | + if [ "${{ github.ref_name }}" != "main" ] ; then + echo "new_tag=1" >> "$GITHUB_ENV" + else + echo "new_tag=0" >> "$GITHUB_ENV" + fi + - name: Install pip packages working-directory: docs run: | @@ -33,6 +42,7 @@ jobs: working-directory: docs run: | python3 extract_macros.py ../ user_guide/preferences_table.rst + export ADOC_DOC_VERSION=${{ github.ref_name }} make html SPHINXOPTS='-W --keep-going' - name: Store the generated doc @@ -44,48 +54,58 @@ jobs: deploy-doc: runs-on: ubuntu-latest needs: build-doc - if: startsWith(github.ref, 'refs/tags/') + if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' steps: + - uses: actions/checkout@v4 - run: | git config --global user.name "${{ github.event.head_commit.committer.name }}" git config --global user.email "${{ github.event.head_commit.committer.email }}" - - uses: actions/checkout@v4 - name: Create gh-pages branch run: > - git ls-remote --exit-code --heads origin refs/heads/gh-pages || + git reset --hard ; + git clean -fdx ; + git ls-remote --exit-code --heads origin refs/heads/gh-pages && ( - git reset --hard ; - git clean -fdx ; + git fetch origin gh-pages ; + git checkout -b gh-pages origin/gh-pages ; + DOC_BUILDS=$(find . -mindepth 2 -name objects.inv -exec sh -c 'dirname {}' ';') ; + git rm -r . --quiet || true ; + printf "Detected doc builds: $DOC_BUILDS" ; + if ! [ -z "$DOC_BUILDS" ]; then + git checkout @ -- $DOC_BUILDS ; + fi ; + if [[ "$new_tag" == "1" ]]; then + git rm -r ${{ github.ref_name }} --quiet || true ; + fi ; + ) || ( git checkout --orphan gh-pages ; - git reset --hard; - git commit -m "empty" --allow-empty ; - git push origin gh-pages:gh-pages + git reset --hard ; + git commit -m "initial commit" --allow-empty ) - - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + if: ${{ env.new_tag == '0' }} with: - ref: 'gh-pages' - - - name: Empty gh-pages - run: | - git rm -r . --quiet || true + name: html - uses: actions/download-artifact@v4 + if: ${{ env.new_tag == '1' }} with: name: html + path: ${{ github.ref_name }} - - name: Patch doc build + - name: Generate aux files run: | - rm -r _sources - touch .nojekyll + touch .nojekyll ; + find . -name objects.inv -exec sh -c 'dirname {}' ';' | + cut -c 3- | sort -r | + jq --raw-input . | + jq --slurp . > tags.json - - name: Commit gh-pages + - name: Commit and push to gh-pages run: | git add . >> /dev/null git commit -m "deploy: ${GITHUB_SHA}" --allow-empty - - - name: Push to gh-pages - run: | - git push origin gh-pages:gh-pages \ No newline at end of file + git push origin gh-pages:gh-pages