Skip to content

Enable doc upload for tags, disable for release branches #3243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 14 additions & 37 deletions .github/workflows/doc-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 '/<head>/a \ \ <meta name="robots" content="noindex">';
Expand All @@ -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
Expand All @@ -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 '/<head>/a \ \ <meta name="robots" content="noindex">';
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}"

Expand Down
39 changes: 11 additions & 28 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading