Skip to content

Commit

Permalink
Enable doc upload for tags, disable for release branches (#3153)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
svekars authored and facebook-github-bot committed Apr 23, 2024
1 parent 6c36f10 commit ee8c3a6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 59 deletions.
46 changes: 15 additions & 31 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@main
Expand All @@ -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}"
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

0 comments on commit ee8c3a6

Please sign in to comment.