From f7308f2d3c9104691ed730d6eefeffb9bf2ad795 Mon Sep 17 00:00:00 2001 From: niksirbi Date: Fri, 22 Nov 2024 14:31:08 +0000 Subject: [PATCH 01/18] add github hash to artifact uploaded by docs build --- .github/workflows/docs_build_and_deploy.yml | 51 ++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docs_build_and_deploy.yml b/.github/workflows/docs_build_and_deploy.yml index 31390e4..56681d8 100644 --- a/.github/workflows/docs_build_and_deploy.yml +++ b/.github/workflows/docs_build_and_deploy.yml @@ -26,7 +26,56 @@ jobs: needs: linting runs-on: ubuntu-latest steps: - - uses: neuroinformatics-unit/actions/build_sphinx_docs@v2 + - uses: actions/checkout@v4 + + # Need the tags so that setuptools-scm can form a valid version number + - name: Fetch git tags + run: git fetch origin 'refs/tags/*:refs/tags/*' + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python-version }} + + - name: Upgrade pip + shell: bash + run: | + # install pip=>20.1 to use "pip cache dir" + python3 -m pip install --upgrade pip + + - name: Get pip cache dir + shell: bash + id: pip-cache + run: echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT + + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ${{ steps.pip-cache.outputs.dir }} + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install dependencies + shell: bash + run: python3 -m pip install -r ./docs/requirements.txt + + - name: Check links + shell: bash + run: | + sphinx-build docs/source docs/build -b linkcheck + + # needs to have sphinx.ext.githubpages in conf.py extensions list + - name: Building documentation + shell: bash + run: | + sphinx-build docs/source docs/build -b html -W --keep-going + + - name: Upload the content for deployment + uses: actions/upload-artifact@v4 + with: + name: docs-${{ github.sha }} + path: ./docs/build/ deploy_sphinx_docs: name: Deploy Sphinx Docs From c2600aa6f0f439c6afdbeac892fe45d1ffe11ddd Mon Sep 17 00:00:00 2001 From: niksirbi Date: Fri, 22 Nov 2024 14:37:27 +0000 Subject: [PATCH 02/18] linkcheck ignore incf website --- docs/source/conf.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 3a208f7..0f823e9 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -143,4 +143,8 @@ } # link-check cannot check anchors -linkcheck_ignore = ['https://bids-specification.readthedocs.io', 'https://neuroinformatics.zulipchat.com', 'https://www.incf.org'] +linkcheck_ignore = [ + 'https://bids-specification.readthedocs.io', + 'https://neuroinformatics.zulipchat.com', + 'https://www.incf.org/', # due to SSLCertVerificationError +] From 430a2def039c4a4b2c06340f7bb36cdb9884ab38 Mon Sep 17 00:00:00 2001 From: niksirbi Date: Fri, 22 Nov 2024 14:55:50 +0000 Subject: [PATCH 03/18] try pooch-inspired docs deploy workflow --- .github/workflows/docs_build_and_deploy.yml | 69 ++++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docs_build_and_deploy.yml b/.github/workflows/docs_build_and_deploy.yml index 56681d8..d248109 100644 --- a/.github/workflows/docs_build_and_deploy.yml +++ b/.github/workflows/docs_build_and_deploy.yml @@ -85,6 +85,71 @@ jobs: if: github.event_name == 'push' runs-on: ubuntu-latest steps: - - uses: neuroinformatics-unit/actions/deploy_sphinx_docs@v2 + - name: Checkout + uses: actions/checkout@v4 + + # Fetch the built docs from the "build" job + - name: Download HTML documentation artifact + uses: actions/download-artifact@v4 + with: + name: docs-${{ github.sha }} + path: docs/build + + - name: Checkout the gh-pages branch in a separate folder + uses: actions/checkout@v4 with: - secret_input: ${{ secrets.GITHUB_TOKEN }} + ref: gh-pages-test + # Checkout to this folder instead of the current one + path: deploy + # Download the entire history + fetch-depth: 0 + + - name: Push the built HTML to gh-pages + run: | + # Detect if this is a release or from the main branch + if [[ "${{ github.event_name }}" == "release" ]]; then + # Get the tag name without the "refs/tags/" part + version="${GITHUB_REF#refs/*/}" + else + version=dev + fi + echo "Deploying version: $version" + # Make the new commit message. Needs to happen before cd into deploy + # to get the right commit hash. + message="Deploy $version from $(git rev-parse --short HEAD)" + cd deploy + # Need to have this file so that Github doesn't try to run Jekyll + touch .nojekyll + # Delete all the files and replace with our new set + echo -e "\nRemoving old files from previous builds of ${version}:" + rm -rvf ${version} + echo -e "\nCopying HTML files to ${version}:" + cp -Rvf ../docs/build ${version}/ + # If this is a new release, update the link from /latest to it + if [[ "${version}" != "dev" ]]; then + echo -e "\nSetup link from ${version} to 'latest'." + rm -f latest + ln -sf ${version} latest + fi + # Stage the commit + git add -A . + echo -e "\nChanges to be applied:" + git status + # Configure git to be the GitHub Actions account + git config user.email "github-actions[bot]@users.noreply.github.com" + git config user.name "github-actions[bot]" + # If this is a dev build and the last commit was from a dev build + # (detect if "dev" was in the previous commit message), reuse the + # same commit + if [[ "${version}" == "dev" && `git log -1 --format='%s'` == *"dev"* ]]; then + echo -e "\nAmending last commit:" + git commit --amend --reset-author -m "$message" + else + echo -e "\nMaking a new commit:" + git commit -m "$message" + fi + # Make the push quiet just in case there is anything that could leak + # sensitive information. + echo -e "\nPushing changes to gh-pages." + git push -fq origin gh-pages 2>&1 >/dev/null + echo -e "\nFinished uploading generated files." From 1a287e05f9073d5f09eaf7a67b316091b60464ba Mon Sep 17 00:00:00 2001 From: niksirbi Date: Fri, 22 Nov 2024 15:01:19 +0000 Subject: [PATCH 04/18] fix indentation error in yaml --- .github/workflows/docs_build_and_deploy.yml | 96 ++++++++++----------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/.github/workflows/docs_build_and_deploy.yml b/.github/workflows/docs_build_and_deploy.yml index d248109..ed692e8 100644 --- a/.github/workflows/docs_build_and_deploy.yml +++ b/.github/workflows/docs_build_and_deploy.yml @@ -105,51 +105,51 @@ jobs: fetch-depth: 0 - name: Push the built HTML to gh-pages - run: | - # Detect if this is a release or from the main branch - if [[ "${{ github.event_name }}" == "release" ]]; then - # Get the tag name without the "refs/tags/" part - version="${GITHUB_REF#refs/*/}" - else - version=dev - fi - echo "Deploying version: $version" - # Make the new commit message. Needs to happen before cd into deploy - # to get the right commit hash. - message="Deploy $version from $(git rev-parse --short HEAD)" - cd deploy - # Need to have this file so that Github doesn't try to run Jekyll - touch .nojekyll - # Delete all the files and replace with our new set - echo -e "\nRemoving old files from previous builds of ${version}:" - rm -rvf ${version} - echo -e "\nCopying HTML files to ${version}:" - cp -Rvf ../docs/build ${version}/ - # If this is a new release, update the link from /latest to it - if [[ "${version}" != "dev" ]]; then - echo -e "\nSetup link from ${version} to 'latest'." - rm -f latest - ln -sf ${version} latest - fi - # Stage the commit - git add -A . - echo -e "\nChanges to be applied:" - git status - # Configure git to be the GitHub Actions account - git config user.email "github-actions[bot]@users.noreply.github.com" - git config user.name "github-actions[bot]" - # If this is a dev build and the last commit was from a dev build - # (detect if "dev" was in the previous commit message), reuse the - # same commit - if [[ "${version}" == "dev" && `git log -1 --format='%s'` == *"dev"* ]]; then - echo -e "\nAmending last commit:" - git commit --amend --reset-author -m "$message" - else - echo -e "\nMaking a new commit:" - git commit -m "$message" - fi - # Make the push quiet just in case there is anything that could leak - # sensitive information. - echo -e "\nPushing changes to gh-pages." - git push -fq origin gh-pages 2>&1 >/dev/null - echo -e "\nFinished uploading generated files." + run: | + # Detect if this is a release or from the main branch + if [[ "${{ github.event_name }}" == "release" ]]; then + # Get the tag name without the "refs/tags/" part + version="${GITHUB_REF#refs/*/}" + else + version=dev + fi + echo "Deploying version: $version" + # Make the new commit message. Needs to happen before cd into deploy + # to get the right commit hash. + message="Deploy $version from $(git rev-parse --short HEAD)" + cd deploy + # Need to have this file so that Github doesn't try to run Jekyll + touch .nojekyll + # Delete all the files and replace with our new set + echo -e "\nRemoving old files from previous builds of ${version}:" + rm -rvf ${version} + echo -e "\nCopying HTML files to ${version}:" + cp -Rvf ../docs/build ${version}/ + # If this is a new release, update the link from /latest to it + if [[ "${version}" != "dev" ]]; then + echo -e "\nSetup link from ${version} to 'latest'." + rm -f latest + ln -sf ${version} latest + fi + # Stage the commit + git add -A . + echo -e "\nChanges to be applied:" + git status + # Configure git to be the GitHub Actions account + git config user.email "github-actions[bot]@users.noreply.github.com" + git config user.name "github-actions[bot]" + # If this is a dev build and the last commit was from a dev build + # (detect if "dev" was in the previous commit message), reuse the + # same commit + if [[ "${version}" == "dev" && `git log -1 --format='%s'` == *"dev"* ]]; then + echo -e "\nAmending last commit:" + git commit --amend --reset-author -m "$message" + else + echo -e "\nMaking a new commit:" + git commit -m "$message" + fi + # Make the push quiet just in case there is anything that could leak + # sensitive information. + echo -e "\nPushing changes to gh-pages." + git push -fq origin gh-pages 2>&1 >/dev/null + echo -e "\nFinished uploading generated files." From 5637d673196d2d26f5f087574799eeae8e538ad5 Mon Sep 17 00:00:00 2001 From: niksirbi Date: Fri, 22 Nov 2024 15:33:39 +0000 Subject: [PATCH 05/18] editted comment --- .github/workflows/docs_build_and_deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docs_build_and_deploy.yml b/.github/workflows/docs_build_and_deploy.yml index ed692e8..42813ab 100644 --- a/.github/workflows/docs_build_and_deploy.yml +++ b/.github/workflows/docs_build_and_deploy.yml @@ -88,7 +88,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - # Fetch the built docs from the "build" job + # Fetch the built docs from the "build_sphinx_docs" job - name: Download HTML documentation artifact uses: actions/download-artifact@v4 with: From 4329690b44bedd395ace0eade854ed1937ce52f1 Mon Sep 17 00:00:00 2001 From: niksirbi Date: Fri, 22 Nov 2024 15:44:10 +0000 Subject: [PATCH 06/18] do not checkout at start of build job --- .github/workflows/docs_build_and_deploy.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/docs_build_and_deploy.yml b/.github/workflows/docs_build_and_deploy.yml index 42813ab..a09f133 100644 --- a/.github/workflows/docs_build_and_deploy.yml +++ b/.github/workflows/docs_build_and_deploy.yml @@ -26,8 +26,6 @@ jobs: needs: linting runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - # Need the tags so that setuptools-scm can form a valid version number - name: Fetch git tags run: git fetch origin 'refs/tags/*:refs/tags/*' From a4674bc0de1857eb92bcda47d39a5b5eb08b2333 Mon Sep 17 00:00:00 2001 From: niksirbi Date: Fri, 22 Nov 2024 15:47:26 +0000 Subject: [PATCH 07/18] add back the checkout --- .github/workflows/docs_build_and_deploy.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/docs_build_and_deploy.yml b/.github/workflows/docs_build_and_deploy.yml index a09f133..1a1064b 100644 --- a/.github/workflows/docs_build_and_deploy.yml +++ b/.github/workflows/docs_build_and_deploy.yml @@ -26,6 +26,9 @@ jobs: needs: linting runs-on: ubuntu-latest steps: + - name: Checkout + uses: actions/checkout@v4 + # Need the tags so that setuptools-scm can form a valid version number - name: Fetch git tags run: git fetch origin 'refs/tags/*:refs/tags/*' From 23b788336886c9c4ec2a966b8f4d317430ac5432 Mon Sep 17 00:00:00 2001 From: niksirbi Date: Fri, 22 Nov 2024 16:00:54 +0000 Subject: [PATCH 08/18] switch everything to gh-pages test --- .github/workflows/docs_build_and_deploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docs_build_and_deploy.yml b/.github/workflows/docs_build_and_deploy.yml index 1a1064b..deaf3e4 100644 --- a/.github/workflows/docs_build_and_deploy.yml +++ b/.github/workflows/docs_build_and_deploy.yml @@ -96,7 +96,7 @@ jobs: name: docs-${{ github.sha }} path: docs/build - - name: Checkout the gh-pages branch in a separate folder + - name: Checkout the gh-pages-test branch in a separate folder uses: actions/checkout@v4 with: ref: gh-pages-test @@ -105,7 +105,7 @@ jobs: # Download the entire history fetch-depth: 0 - - name: Push the built HTML to gh-pages + - name: Push the built HTML to gh-pages-test run: | # Detect if this is a release or from the main branch if [[ "${{ github.event_name }}" == "release" ]]; then @@ -151,6 +151,6 @@ jobs: fi # Make the push quiet just in case there is anything that could leak # sensitive information. - echo -e "\nPushing changes to gh-pages." - git push -fq origin gh-pages 2>&1 >/dev/null + echo -e "\nPushing changes to gh-pages-test." + git push -fq origin gh-pages-test 2>&1 >/dev/null echo -e "\nFinished uploading generated files." From 44051382ad0da3e6d1c1277e5f12f34e9cd0b493 Mon Sep 17 00:00:00 2001 From: niksirbi Date: Fri, 22 Nov 2024 16:08:18 +0000 Subject: [PATCH 09/18] investigate event_name trigger --- .github/workflows/docs_build_and_deploy.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/docs_build_and_deploy.yml b/.github/workflows/docs_build_and_deploy.yml index deaf3e4..a14ab5c 100644 --- a/.github/workflows/docs_build_and_deploy.yml +++ b/.github/workflows/docs_build_and_deploy.yml @@ -12,6 +12,9 @@ on: - '*' pull_request: workflow_dispatch: + release: + types: + - published jobs: linting: @@ -108,6 +111,7 @@ jobs: - name: Push the built HTML to gh-pages-test run: | # Detect if this is a release or from the main branch + echo "Event name: ${{ github.event_name }}" if [[ "${{ github.event_name }}" == "release" ]]; then # Get the tag name without the "refs/tags/" part version="${GITHUB_REF#refs/*/}" From d322091ea6f7debe2454621088aa1b954f82bccb Mon Sep 17 00:00:00 2001 From: niksirbi Date: Fri, 22 Nov 2024 16:19:24 +0000 Subject: [PATCH 10/18] change if guard for releases --- .github/workflows/docs_build_and_deploy.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docs_build_and_deploy.yml b/.github/workflows/docs_build_and_deploy.yml index a14ab5c..b226403 100644 --- a/.github/workflows/docs_build_and_deploy.yml +++ b/.github/workflows/docs_build_and_deploy.yml @@ -112,7 +112,8 @@ jobs: run: | # Detect if this is a release or from the main branch echo "Event name: ${{ github.event_name }}" - if [[ "${{ github.event_name }}" == "release" ]]; then + echo "Ref type: ${{ github.ref_type }}" + if [[ "${{ github.event_name }}" == "push"]] && [[ "${{ github.ref_type }}" == "tag"]]; then # Get the tag name without the "refs/tags/" part version="${GITHUB_REF#refs/*/}" else From f43b2b14f47afbf68a1cf6a9511cbab4ca321627 Mon Sep 17 00:00:00 2001 From: niksirbi Date: Fri, 22 Nov 2024 16:23:06 +0000 Subject: [PATCH 11/18] detect releases by tag presence --- .github/workflows/docs_build_and_deploy.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/docs_build_and_deploy.yml b/.github/workflows/docs_build_and_deploy.yml index b226403..103980b 100644 --- a/.github/workflows/docs_build_and_deploy.yml +++ b/.github/workflows/docs_build_and_deploy.yml @@ -12,9 +12,6 @@ on: - '*' pull_request: workflow_dispatch: - release: - types: - - published jobs: linting: @@ -113,7 +110,7 @@ jobs: # Detect if this is a release or from the main branch echo "Event name: ${{ github.event_name }}" echo "Ref type: ${{ github.ref_type }}" - if [[ "${{ github.event_name }}" == "push"]] && [[ "${{ github.ref_type }}" == "tag"]]; then + if [ "${{ github.event_name }}" = "push" ] && [ "${{ github.ref_type }}" = "tag" ]; then # Get the tag name without the "refs/tags/" part version="${GITHUB_REF#refs/*/}" else From a27113dc6e935ad00b9ed216c88cc16a4c8383f8 Mon Sep 17 00:00:00 2001 From: IgorTatarnikov Date: Fri, 22 Nov 2024 17:29:43 +0000 Subject: [PATCH 12/18] V1 of dynamic switcher.json --- .github/workflows/docs_build_and_deploy.yml | 28 +++++++++++++++++++++ docs/source/_static/switcher.json | 8 ++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docs_build_and_deploy.yml b/.github/workflows/docs_build_and_deploy.yml index 103980b..d440fc9 100644 --- a/.github/workflows/docs_build_and_deploy.yml +++ b/.github/workflows/docs_build_and_deploy.yml @@ -128,6 +128,34 @@ jobs: rm -rvf ${version} echo -e "\nCopying HTML files to ${version}:" cp -Rvf ../docs/build ${version}/ + + if [[ "${version}" != "dev" ]]; then + # Updated switcher.json file + SWITCHER_FILE="${version}/_static/switcher.json" + SWITCHER_CONTENT=$(cat "${SWITCHER_FILE}") + BASE_URL="$(jq -r '.[1].url|split("/")[0:-2]|join("/")' $SWITCHER_FILE)" + NEW_URL="${BASE_URL}/${version}/" + + # Extract the current latest version entry + CURRENT_LATEST_ENTRY=$(jq '.[1]' <<< "${SWITCHER_CONTENT}") + + # Remove the "name" field from the current latest entry + UPDATED_CURRENT_LATEST_ENTRY=$(jq '.[1] | del(.name)' <<< "$SWITCHER_CONTENT") + + # Create the new version entry with the "latest" tag + NEW_ENTRY=$(jq -n --arg version "${version}" --arg url "$NEW_URL" \ + '{version: $version, url: $url, name: "v\($version) (latest)"}') + + UPDATED_SWITCHER_CONTENT=$(jq --argjson new_entry "$NEW_ENTRY" \ + --argjson updated_current_latest_entry "$UPDATED_CURRENT_LATEST_ENTRY" \ + '.[1] = $updated_current_latest_entry | . += [$new_entry]' <<< "$SWITCHER_CONTENT") + + # Write the updated content back to switcher.json + echo "$UPDATED_SWITCHER_CONTENT" > "$SWITCHER_FILE" + + echo "switcher.json has been updated successfully." + fi + # If this is a new release, update the link from /latest to it if [[ "${version}" != "dev" ]]; then echo -e "\nSetup link from ${version} to 'latest'." diff --git a/docs/source/_static/switcher.json b/docs/source/_static/switcher.json index cad800f..2f9d2ea 100644 --- a/docs/source/_static/switcher.json +++ b/docs/source/_static/switcher.json @@ -1,7 +1,11 @@ [ { - "name": "v0.3.1 (stable)", - "version": "0.3.1", + "version": "dev", + "url": "https://neuroblueprint.neuroinformatics.dev/latest/" + }, + { + "name": "v0.3.0 (stable)", + "version": "0.3.0", "url": "https://neuroblueprint.neuroinformatics.dev/" } ] From fc95fabd95b969d7826cc14945822e985830e875 Mon Sep 17 00:00:00 2001 From: IgorTatarnikov Date: Fri, 22 Nov 2024 17:56:09 +0000 Subject: [PATCH 13/18] Update the switcher json to order correctly --- .github/workflows/docs_build_and_deploy.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docs_build_and_deploy.yml b/.github/workflows/docs_build_and_deploy.yml index d440fc9..e8333d6 100644 --- a/.github/workflows/docs_build_and_deploy.yml +++ b/.github/workflows/docs_build_and_deploy.yml @@ -137,6 +137,7 @@ jobs: NEW_URL="${BASE_URL}/${version}/" # Extract the current latest version entry + FIRST_ENTRY=$(jq '.[0]' <<< "${SWITCHER_CONTENT}") CURRENT_LATEST_ENTRY=$(jq '.[1]' <<< "${SWITCHER_CONTENT}") # Remove the "name" field from the current latest entry @@ -144,11 +145,13 @@ jobs: # Create the new version entry with the "latest" tag NEW_ENTRY=$(jq -n --arg version "${version}" --arg url "$NEW_URL" \ - '{version: $version, url: $url, name: "v\($version) (latest)"}') + '{version: $version, url: $url, name: "($version) (latest)"}') - UPDATED_SWITCHER_CONTENT=$(jq --argjson new_entry "$NEW_ENTRY" \ - --argjson updated_current_latest_entry "$UPDATED_CURRENT_LATEST_ENTRY" \ - '.[1] = $updated_current_latest_entry | . += [$new_entry]' <<< "$SWITCHER_CONTENT") + # Combine the entries in the desired order + UPDATED_SWITCHER_CONTENT=$(jq --argjson first_entry "$FIRST_ENTRY" \ + --argjson new_entry "$NEW_ENTRY" \ + --argjson updated_current_stable_entry "$UPDATED_CURRENT_STABLE_ENTRY" \ + '[$first_entry, $new_entry, $updated_current_stable_entry] + .[2:]' <<< "$SWITCHER_CONTENT") # Write the updated content back to switcher.json echo "$UPDATED_SWITCHER_CONTENT" > "$SWITCHER_FILE" From 95a73808bca35219d592a64174cde6593b5a5e4b Mon Sep 17 00:00:00 2001 From: IgorTatarnikov Date: Fri, 29 Nov 2024 15:44:40 +0000 Subject: [PATCH 14/18] V2 dynamic switcher.json --- .github/workflows/docs_build_and_deploy.yml | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/.github/workflows/docs_build_and_deploy.yml b/.github/workflows/docs_build_and_deploy.yml index e8333d6..1353e6d 100644 --- a/.github/workflows/docs_build_and_deploy.yml +++ b/.github/workflows/docs_build_and_deploy.yml @@ -133,25 +133,22 @@ jobs: # Updated switcher.json file SWITCHER_FILE="${version}/_static/switcher.json" SWITCHER_CONTENT=$(cat "${SWITCHER_FILE}") - BASE_URL="$(jq -r '.[1].url|split("/")[0:-2]|join("/")' $SWITCHER_FILE)" - NEW_URL="${BASE_URL}/${version}/" - + BASE_URL="$(jq -r '.[1].url|split("/")[0:3]|join("/")' $SWITCHER_FILE)" + NEW_URL="${BASE_URL}/stable/" # Extract the current latest version entry FIRST_ENTRY=$(jq '.[0]' <<< "${SWITCHER_CONTENT}") - CURRENT_LATEST_ENTRY=$(jq '.[1]' <<< "${SWITCHER_CONTENT}") + CURRENT_LATEST_VERSION=${$(jq '.[1].version' <<< "${SWITCHER_CONTENT}")//\"/} # Remove the "name" field from the current latest entry - UPDATED_CURRENT_LATEST_ENTRY=$(jq '.[1] | del(.name)' <<< "$SWITCHER_CONTENT") + UPDATED_CURRENT_LATEST_ENTRY=$(jq --arg url "${BASE_URL}/${CURRENT_LATEST_VERSION}" '.[1] | .url = $url | del(.name)' <<< "$SWITCHER_CONTENT") + + # Create the new version entry with the "stable" tag + NEW_ENTRY=$(jq -n --arg version "${version}" --arg url "$NEW_URL" --arg name "$version (stable)" \ + '{name: $name, version: $version, url: $url}') - # Create the new version entry with the "latest" tag - NEW_ENTRY=$(jq -n --arg version "${version}" --arg url "$NEW_URL" \ - '{version: $version, url: $url, name: "($version) (latest)"}') # Combine the entries in the desired order - UPDATED_SWITCHER_CONTENT=$(jq --argjson first_entry "$FIRST_ENTRY" \ - --argjson new_entry "$NEW_ENTRY" \ - --argjson updated_current_stable_entry "$UPDATED_CURRENT_STABLE_ENTRY" \ - '[$first_entry, $new_entry, $updated_current_stable_entry] + .[2:]' <<< "$SWITCHER_CONTENT") + UPDATED_SWITCHER_CONTENT=$(jq --argjson first_entry "$FIRST_ENTRY" --argjson new_entry "$NEW_ENTRY" --argjson updated_current_stable "$UPDATED_CURRENT_LATEST_ENTRY" '[$first_entry, $new_entry, $updated_current_stable] + .[2:]' <<< "$SWITCHER_CONTENT") # Write the updated content back to switcher.json echo "$UPDATED_SWITCHER_CONTENT" > "$SWITCHER_FILE" From 53a14c593bb3da943f9e862a724fef0601aeb5c1 Mon Sep 17 00:00:00 2001 From: IgorTatarnikov Date: Fri, 29 Nov 2024 15:55:13 +0000 Subject: [PATCH 15/18] Fixed double quote truncation --- .github/workflows/docs_build_and_deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docs_build_and_deploy.yml b/.github/workflows/docs_build_and_deploy.yml index 1353e6d..1da81da 100644 --- a/.github/workflows/docs_build_and_deploy.yml +++ b/.github/workflows/docs_build_and_deploy.yml @@ -137,7 +137,7 @@ jobs: NEW_URL="${BASE_URL}/stable/" # Extract the current latest version entry FIRST_ENTRY=$(jq '.[0]' <<< "${SWITCHER_CONTENT}") - CURRENT_LATEST_VERSION=${$(jq '.[1].version' <<< "${SWITCHER_CONTENT}")//\"/} + CURRENT_LATEST_VERSION=$(echo $(jq '.[1].version' <<< "${SWITCHER_CONTENT}") | tr -d '"') # Remove the "name" field from the current latest entry UPDATED_CURRENT_LATEST_ENTRY=$(jq --arg url "${BASE_URL}/${CURRENT_LATEST_VERSION}" '.[1] | .url = $url | del(.name)' <<< "$SWITCHER_CONTENT") From 7f494021f615b60462c64a87bef67138204cc536 Mon Sep 17 00:00:00 2001 From: IgorTatarnikov Date: Fri, 29 Nov 2024 16:13:13 +0000 Subject: [PATCH 16/18] Switch stable to latest --- .github/workflows/docs_build_and_deploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docs_build_and_deploy.yml b/.github/workflows/docs_build_and_deploy.yml index 1da81da..30aded6 100644 --- a/.github/workflows/docs_build_and_deploy.yml +++ b/.github/workflows/docs_build_and_deploy.yml @@ -134,7 +134,7 @@ jobs: SWITCHER_FILE="${version}/_static/switcher.json" SWITCHER_CONTENT=$(cat "${SWITCHER_FILE}") BASE_URL="$(jq -r '.[1].url|split("/")[0:3]|join("/")' $SWITCHER_FILE)" - NEW_URL="${BASE_URL}/stable/" + NEW_URL="${BASE_URL}/latest/" # Extract the current latest version entry FIRST_ENTRY=$(jq '.[0]' <<< "${SWITCHER_CONTENT}") CURRENT_LATEST_VERSION=$(echo $(jq '.[1].version' <<< "${SWITCHER_CONTENT}") | tr -d '"') @@ -142,13 +142,13 @@ jobs: # Remove the "name" field from the current latest entry UPDATED_CURRENT_LATEST_ENTRY=$(jq --arg url "${BASE_URL}/${CURRENT_LATEST_VERSION}" '.[1] | .url = $url | del(.name)' <<< "$SWITCHER_CONTENT") - # Create the new version entry with the "stable" tag - NEW_ENTRY=$(jq -n --arg version "${version}" --arg url "$NEW_URL" --arg name "$version (stable)" \ + # Create the new version entry with the "latest" tag + NEW_ENTRY=$(jq -n --arg version "${version}" --arg url "$NEW_URL" --arg name "$version (latest)" \ '{name: $name, version: $version, url: $url}') # Combine the entries in the desired order - UPDATED_SWITCHER_CONTENT=$(jq --argjson first_entry "$FIRST_ENTRY" --argjson new_entry "$NEW_ENTRY" --argjson updated_current_stable "$UPDATED_CURRENT_LATEST_ENTRY" '[$first_entry, $new_entry, $updated_current_stable] + .[2:]' <<< "$SWITCHER_CONTENT") + UPDATED_SWITCHER_CONTENT=$(jq --argjson first_entry "$FIRST_ENTRY" --argjson new_entry "$NEW_ENTRY" --argjson updated_current_latest "$UPDATED_CURRENT_LATEST_ENTRY" '[$first_entry, $new_entry, $updated_current_latest] + .[2:]' <<< "$SWITCHER_CONTENT") # Write the updated content back to switcher.json echo "$UPDATED_SWITCHER_CONTENT" > "$SWITCHER_FILE" From da55421a9902aacde078a61ce49fd3bf654b06db Mon Sep 17 00:00:00 2001 From: IgorTatarnikov Date: Fri, 29 Nov 2024 16:14:12 +0000 Subject: [PATCH 17/18] Update switcher.json --- docs/source/_static/switcher.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/source/_static/switcher.json b/docs/source/_static/switcher.json index 2f9d2ea..3c405a0 100644 --- a/docs/source/_static/switcher.json +++ b/docs/source/_static/switcher.json @@ -1,11 +1,11 @@ [ - { - "version": "dev", - "url": "https://neuroblueprint.neuroinformatics.dev/latest/" - }, - { - "name": "v0.3.0 (stable)", - "version": "0.3.0", - "url": "https://neuroblueprint.neuroinformatics.dev/" - } + { + "version": "dev", + "url": "https://neuroblueprint.neuroinformatics.dev/dev/" + }, + { + "name": "0.3.0 (latest)", + "version": "0.3.0", + "url": "https://neuroblueprint.neuroinformatics.dev/latest/" + } ] From a35f68c69ef2468ed923eb54c24e3023292ad8d7 Mon Sep 17 00:00:00 2001 From: IgorTatarnikov Date: Fri, 29 Nov 2024 17:00:21 +0000 Subject: [PATCH 18/18] Final version of multi-version switcher --- .github/workflows/docs_build_and_deploy.yml | 14 ++++++-------- docs/source/conf.py | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docs_build_and_deploy.yml b/.github/workflows/docs_build_and_deploy.yml index 30aded6..68f6095 100644 --- a/.github/workflows/docs_build_and_deploy.yml +++ b/.github/workflows/docs_build_and_deploy.yml @@ -96,16 +96,16 @@ jobs: name: docs-${{ github.sha }} path: docs/build - - name: Checkout the gh-pages-test branch in a separate folder + - name: Checkout the gh-pages branch in a separate folder uses: actions/checkout@v4 with: - ref: gh-pages-test + ref: gh-pages # Checkout to this folder instead of the current one path: deploy # Download the entire history fetch-depth: 0 - - name: Push the built HTML to gh-pages-test + - name: Push the built HTML to gh-pages run: | # Detect if this is a release or from the main branch echo "Event name: ${{ github.event_name }}" @@ -131,8 +131,7 @@ jobs: if [[ "${version}" != "dev" ]]; then # Updated switcher.json file - SWITCHER_FILE="${version}/_static/switcher.json" - SWITCHER_CONTENT=$(cat "${SWITCHER_FILE}") + SWITCHER_CONTENT=$(curl https://neuroblueprint.neuroinformatics.dev/latest/_static/switcher.json) BASE_URL="$(jq -r '.[1].url|split("/")[0:3]|join("/")' $SWITCHER_FILE)" NEW_URL="${BASE_URL}/latest/" # Extract the current latest version entry @@ -146,7 +145,6 @@ jobs: NEW_ENTRY=$(jq -n --arg version "${version}" --arg url "$NEW_URL" --arg name "$version (latest)" \ '{name: $name, version: $version, url: $url}') - # Combine the entries in the desired order UPDATED_SWITCHER_CONTENT=$(jq --argjson first_entry "$FIRST_ENTRY" --argjson new_entry "$NEW_ENTRY" --argjson updated_current_latest "$UPDATED_CURRENT_LATEST_ENTRY" '[$first_entry, $new_entry, $updated_current_latest] + .[2:]' <<< "$SWITCHER_CONTENT") @@ -181,6 +179,6 @@ jobs: fi # Make the push quiet just in case there is anything that could leak # sensitive information. - echo -e "\nPushing changes to gh-pages-test." - git push -fq origin gh-pages-test 2>&1 >/dev/null + echo -e "\nPushing changes to gh-pages." + git push -fq origin gh-pages 2>&1 >/dev/null echo -e "\nFinished uploading generated files." diff --git a/docs/source/conf.py b/docs/source/conf.py index 0f823e9..96288d0 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -129,7 +129,7 @@ }, ], "switcher": { - "json_url": "https://neuroblueprint.neuroinformatics.dev/_static/switcher.json", + "json_url": "https://neuroblueprint.neuroinformatics.dev/latest/_static/switcher.json", "version_match": release, }, "logo": {