diff --git a/.github/workflows/doc-build.yml b/.github/workflows/doc-build.yml index 5a895c04a00..17fdf6a99c3 100644 --- a/.github/workflows/doc-build.yml +++ b/.github/workflows/doc-build.yml @@ -46,13 +46,9 @@ jobs: # ET_VERSION_DOCS will be pulled during the doc build to add to the version dropdown # on the website. See docs/source/conf.py for details - REF_TYPE=${{ github.ref_type }} - REF_NAME=${{ github.ref_name }} - - echo "$REF_TYPE" - echo "$REF_NAME" - - ET_VERSION_DOCS="${REF_NAME}" + GITHUB_REF=${{ github.ref }} + echo "$GITHUB_REF" + ET_VERSION_DOCS="${GITHUB_REF}" echo "$ET_VERSION_DOCS" set -eux @@ -69,7 +65,6 @@ jobs: cd .. # If it's main branch, add noindex tag to all .html files to exclude from Google Search indexing. - GITHUB_REF=${{ github.ref }} echo "GitHub Ref: ${GITHUB_REF}" if [[ "${{ github.ref }}" == 'refs/heads/main' ]]; then find docs/_build/html/ -name "*.html" -print0 | xargs -0 sed -i '/
/a \ \ '; @@ -83,7 +78,7 @@ jobs: upload-gh-pages: needs: build - if: github.repository == 'pytorch/executorch' && github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') || startsWith(github.ref, 'refs/tags/v')) + if: github.repository == 'pytorch/executorch' && github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) permissions: contents: write uses: pytorch/test-infra/.github/workflows/linux_job.yml@main @@ -95,28 +90,17 @@ jobs: script: | set -euo pipefail - REF_TYPE=${{ github.ref_type }} - REF_NAME=${{ github.ref_name }} - - # If building for a release tag, branch, set the branch/tag name - # as the target folder in the gh-pages branch. The artifacts created - # during the build will be copied over to the target dir in the - # gh-pages branch. - if [[ "${REF_TYPE}" == branch ]]; then - TARGET_FOLDER="${REF_NAME}" - elif [[ "${REF_TYPE}" == tag ]]; then - # Strip the leading "v" as well as the trailing patch version and "-rc" suffix. - # For example: 'v0.1.2' -> '0.1' and 'v0.1.2-rc1' -> 0.1. - case "${REF_NAME}" in - *-rc*) - echo "Aborting upload since this is an RC tag: ${REF_NAME}" - # We don't generate -rc* documentation but for actual tag only. - exit 0 - ;; - *) - TARGET_FOLDER=$(echo "${REF_NAME}" | sed 's/v\([0-9]\+\)\.\([0-9]\+\)\.[0-9]\+/\1.\2/') - ;; - esac + # Get github.ref for the output doc folder. By default "main" + # If matches a tag like refs/tags/v1.12.0-rc3 or + # refs/tags/v1.12.0 convert to 1.12 + GITHUB_REF=${{ github.ref }} + + # Convert refs/tags/v1.12.0rc3 into 1.12. + # Adopted from https://github.com/pytorch/pytorch/blob/main/.github/workflows/_docs.yml#L150C11-L155C13 + if [[ "${GITHUB_REF}" =~ ^refs/tags/v([0-9]+\\.[0-9]+)\\. ]]; then + TARGET_FOLDER="${BASH_REMATCH[1]}" + else + TARGET_FOLDER="main" fi echo "Target Folder: ${TARGET_FOLDER}" diff --git a/docs/source/conf.py b/docs/source/conf.py index 239319f7c2f..2f72a01d22d 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -73,38 +73,21 @@ # Get ET_VERSION_DOCS during the build. et_version_docs = os.environ.get("ET_VERSION_DOCS", None) - +print(f"et_version_docs: {et_version_docs}") # The code below will cut version displayed in the dropdown like this: -# tags like v0.1.0 = > 0.1 -# branch like release/0.1 => 0.1 -# main will remain main -# if not set will fail back to main +# By default, set to "main". +# If it's a tag like refs/tags/v1.2.3-rc4 or refs/tags/v1.2.3, then +# cut to 1.2 # the version varible is used in layout.html: https://github.com/pytorch/executorch/blob/main/docs/source/_templates/layout.html#L29 +version = release = "main" if et_version_docs: - # Check if starts with release/ and set the version to the number after slash - if et_version_docs.startswith("release/"): - version = et_version_docs.split("/")[-1] - else: - # Remove "v" prefix if present - if et_version_docs.startswith("v"): - et_version_docs = et_version_docs[1:] - # Split to major, minor, and patch - version_components = et_version_docs.split(".") - - # Combine the major and minor version components: - if len(version_components) >= 2: - version = release = ".".join(version_components[:2]) - else: - # If there are not enough components, use the full version - version = release = et_version_docs - - html_title = " ".join((project, version, "documentation")) -# IF ET_VERSION_DOCS not set, set version to main. -# This can be updated to nightly and so on. -else: - version = "main" - release = "main" + if et_version_docs.startswith("refs/tags/v"): + version = ".".join( + et_version_docs.split("/")[-1].split("-")[0].lstrip("v").split(".")[:2] + ) +print(f"Version: {version}") +html_title = " ".join((project, version, "documentation")) breathe_projects = {"ExecuTorch": "../build/xml/"} breathe_default_project = "ExecuTorch"