Skip to content

Commit e37f0fd

Browse files
svekarspytorchbot
authored andcommitted
Enable doc upload for tags, disable for release branches (#3153)
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: #3153 Reviewed By: dbort Differential Revision: D56445037 Pulled By: svekars fbshipit-source-id: e7328523dfe308e8921c1e4f365d9a757d053191 (cherry picked from commit ee8c3a6)
1 parent 24ecd04 commit e37f0fd

File tree

2 files changed

+25
-65
lines changed

2 files changed

+25
-65
lines changed

.github/workflows/doc-build.yml

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,9 @@ jobs:
4646
# ET_VERSION_DOCS will be pulled during the doc build to add to the version dropdown
4747
# on the website. See docs/source/conf.py for details
4848
49-
REF_TYPE=${{ github.ref_type }}
50-
REF_NAME=${{ github.ref_name }}
51-
52-
echo "$REF_TYPE"
53-
echo "$REF_NAME"
54-
55-
ET_VERSION_DOCS="${REF_NAME}"
49+
GITHUB_REF=${{ github.ref }}
50+
echo "$GITHUB_REF"
51+
ET_VERSION_DOCS="${GITHUB_REF}"
5652
echo "$ET_VERSION_DOCS"
5753
5854
set -eux
@@ -69,7 +65,6 @@ jobs:
6965
cd ..
7066
7167
# If it's main branch, add noindex tag to all .html files to exclude from Google Search indexing.
72-
GITHUB_REF=${{ github.ref }}
7368
echo "GitHub Ref: ${GITHUB_REF}"
7469
if [[ "${{ github.ref }}" == 'refs/heads/main' ]]; then
7570
find docs/_build/html/ -name "*.html" -print0 | xargs -0 sed -i '/<head>/a \ \ <meta name="robots" content="noindex">';
@@ -83,7 +78,7 @@ jobs:
8378
8479
upload-gh-pages:
8580
needs: build
86-
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'))
81+
if: github.repository == 'pytorch/executorch' && github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
8782
permissions:
8883
contents: write
8984
uses: pytorch/test-infra/.github/workflows/linux_job.yml@release/2.3
@@ -95,35 +90,17 @@ jobs:
9590
script: |
9691
set -euo pipefail
9792
98-
REF_TYPE=${{ github.ref_type }}
99-
REF_NAME=${{ github.ref_name }}
100-
101-
# If it's main branch, add noindex tag to all .html files to exclude from Google Search indexing.
102-
REF_NAME=$(echo "${{ github.ref }}")
103-
echo "Ref name: ${REF_NAME}"
104-
if [[ "${{ github.ref }}" == 'refs/heads/main' ]]; then
105-
find docs -name "*.html" -print0 | xargs -0 sed -i '/<head>/a \ \ <meta name="robots" content="noindex">';
106-
fi
93+
# Get github.ref for the output doc folder. By default "main"
94+
# If matches a tag like refs/tags/v1.12.0-rc3 or
95+
# refs/tags/v1.12.0 convert to 1.12
96+
GITHUB_REF=${{ github.ref }}
10797
108-
# If building for a release tag, branch, set the branch/tag name
109-
# as the target folder in the gh-pages branch. The artifacts created
110-
# during the build will be copied over to the target dir in the
111-
# gh-pages branch.
112-
if [[ "${REF_TYPE}" == branch ]]; then
113-
TARGET_FOLDER="${REF_NAME}"
114-
elif [[ "${REF_TYPE}" == tag ]]; then
115-
# Strip the leading "v" as well as the trailing patch version and "-rc" suffix.
116-
# For example: 'v0.1.2' -> '0.1' and 'v0.1.2-rc1' -> 0.1.
117-
case "${REF_NAME}" in
118-
*-rc*)
119-
echo "Aborting upload since this is an RC tag: ${REF_NAME}"
120-
# We don't generate -rc* documentation but for actual tag only.
121-
exit 0
122-
;;
123-
*)
124-
TARGET_FOLDER=$(echo "${REF_NAME}" | sed 's/v\([0-9]\+\)\.\([0-9]\+\)\.[0-9]\+/\1.\2/')
125-
;;
126-
esac
98+
# Convert refs/tags/v1.12.0rc3 into 1.12.
99+
# Adopted from https://github.com/pytorch/pytorch/blob/main/.github/workflows/_docs.yml#L150C11-L155C13
100+
if [[ "${GITHUB_REF}" =~ ^refs/tags/v([0-9]+\\.[0-9]+)\\. ]]; then
101+
TARGET_FOLDER="${BASH_REMATCH[1]}"
102+
else
103+
TARGET_FOLDER="main"
127104
fi
128105
echo "Target Folder: ${TARGET_FOLDER}"
129106

docs/source/conf.py

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -73,38 +73,21 @@
7373

7474
# Get ET_VERSION_DOCS during the build.
7575
et_version_docs = os.environ.get("ET_VERSION_DOCS", None)
76-
76+
print(f"et_version_docs: {et_version_docs}")
7777

7878
# The code below will cut version displayed in the dropdown like this:
79-
# tags like v0.1.0 = > 0.1
80-
# branch like release/0.1 => 0.1
81-
# main will remain main
82-
# if not set will fail back to main
79+
# By default, set to "main".
80+
# If it's a tag like refs/tags/v1.2.3-rc4 or refs/tags/v1.2.3, then
81+
# cut to 1.2
8382
# the version varible is used in layout.html: https://github.com/pytorch/executorch/blob/main/docs/source/_templates/layout.html#L29
83+
version = release = "main"
8484
if et_version_docs:
85-
# Check if starts with release/ and set the version to the number after slash
86-
if et_version_docs.startswith("release/"):
87-
version = et_version_docs.split("/")[-1]
88-
else:
89-
# Remove "v" prefix if present
90-
if et_version_docs.startswith("v"):
91-
et_version_docs = et_version_docs[1:]
92-
# Split to major, minor, and patch
93-
version_components = et_version_docs.split(".")
94-
95-
# Combine the major and minor version components:
96-
if len(version_components) >= 2:
97-
version = release = ".".join(version_components[:2])
98-
else:
99-
# If there are not enough components, use the full version
100-
version = release = et_version_docs
101-
102-
html_title = " ".join((project, version, "documentation"))
103-
# IF ET_VERSION_DOCS not set, set version to main.
104-
# This can be updated to nightly and so on.
105-
else:
106-
version = "main"
107-
release = "main"
85+
if et_version_docs.startswith("refs/tags/v"):
86+
version = ".".join(
87+
et_version_docs.split("/")[-1].split("-")[0].lstrip("v").split(".")[:2]
88+
)
89+
print(f"Version: {version}")
90+
html_title = " ".join((project, version, "documentation"))
10891

10992
breathe_projects = {"ExecuTorch": "../build/xml/"}
11093
breathe_default_project = "ExecuTorch"

0 commit comments

Comments
 (0)