From 1ba292ae4071c4eede8ea14e8f10ffd973a085b4 Mon Sep 17 00:00:00 2001 From: pytorchbot Date: Tue, 23 Apr 2024 11:06:01 -0700 Subject: [PATCH] Enable doc upload for tags, disable for release branches (#3153) (#3243) Summary: - Disabled doc upload for branches like release/x.x - Enabled publishing for tags. Tested locally: ``` export GITHUB_REF=refs/tags/v3.1.4-rc5 bash test-version.py ``` ``` # test-version.py 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}" ``` Output: ``` Target folder: 3.1 ``` One more: ``` export GITHUB_REF=refs/tags/v1.15.4 bash test-version.sh ``` Output: ``` Target folder: 1.15 ``` Pull Request resolved: https://github.com/pytorch/executorch/pull/3153 Reviewed By: dbort Differential Revision: D56445037 Pulled By: svekars fbshipit-source-id: e7328523dfe308e8921c1e4f365d9a757d053191 (cherry picked from commit ee8c3a62ff0de91906931a8bbc0e017a1d5d574f) Co-authored-by: Svetlana Karslioglu --- .github/workflows/doc-build.yml | 51 +++++++++------------------------ docs/source/conf.py | 39 +++++++------------------ 2 files changed, 25 insertions(+), 65 deletions(-) diff --git a/.github/workflows/doc-build.yml b/.github/workflows/doc-build.yml index 238345489f..b243d4ffa0 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@release/2.3 @@ -95,35 +90,17 @@ jobs: script: | set -euo pipefail - REF_TYPE=${{ github.ref_type }} - REF_NAME=${{ github.ref_name }} - - # If it's main branch, add noindex tag to all .html files to exclude from Google Search indexing. - REF_NAME=$(echo "${{ github.ref }}") - echo "Ref name: ${REF_NAME}" - if [[ "${{ github.ref }}" == 'refs/heads/main' ]]; then - find docs -name "*.html" -print0 | xargs -0 sed -i '//a \ \ '; - fi + # 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 }} - # 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 + # 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 239319f7c2..2f72a01d22 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"