Skip to content

Update doc build to use tags #163

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 4 commits 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
55 changes: 37 additions & 18 deletions .github/workflows/doc_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ jobs:
# REF_NAME variable. This will be passed in
# conf.py to display the version in the
# site dropdown
REF_NAME=${{ github.ref_name }}
TORCHAO_VERSION_DOCS="${REF_NAME}"
GITHUB_REF=${{ github.ref }}
TORCHAO_VERSION_DOCS="${GITHUB_REF}"
echo "$TORCHAO_VERSION_DOCS"
- name: Build docs
run: |
Expand All @@ -61,13 +61,35 @@ jobs:
name: Doc-Build
path: docs/build/html/

doc-preview:
runs-on: [self-hosted, linux.2xlarge]
needs: build_docs
if: ${{ github.event_name == 'pull_request' }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: Doc-Build
path: docs
- name: Upload docs preview
uses: seemethere/upload-artifact-s3@v5
if: ${{ github.event_name == 'pull_request' }}
with:
retention-days: 14
s3-bucket: doc-previews
if-no-files-found: error
path: docs
s3-prefix: pytorch/ao/${{ github.event.pull_request.number }}

upload:
runs-on: ubuntu-latest
permissions:
# Grant write permission here so that the doc can be pushed to gh-pages branch
contents: write
needs: build_docs
if: github.repository == 'pytorch-labs/ao' && github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') || startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch')
if: github.repository == 'pytorch-labs/ao' && github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch')
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -89,23 +111,20 @@ jobs:
- name: Move and commit changes
run: |
set -euo pipefail
REF_TYPE=${{ github.ref_type }}
REF_NAME=${{ github.ref_name }}
if [[ "${REF_TYPE}" == branch ]]; then
TARGET_FOLDER="${REF_NAME}"
elif [[ "${REF_TYPE}" == tag ]]; then
case "${REF_NAME}" in
*-rc*)
echo "Aborting upload since this is an RC tag: ${REF_NAME}"
exit 0
;;
*)
TARGET_FOLDER=$(echo "${REF_NAME}" | sed 's/v\([0-9]\+\)\.\([0-9]\+\)\.[0-9]\+/\1.\2/')
;;
esac
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 }}

# 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="${BASH_REMATCH[1]}"
else
target="main"
fi
echo "Target Folder: ${TARGET_FOLDER}"

mkdir -p "${TARGET_FOLDER}"
rm -rf "${TARGET_FOLDER}"/*
mv docs/* "${TARGET_FOLDER}"
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ docs/dev
docs/build
docs/source/tutorials/*
docs/source/gen_modules/*
docs/source/sg_execution_times.rst
docs/source/sg_execution_times

# LevelDB files
*.sst
Expand Down
5 changes: 2 additions & 3 deletions docs/source/_templates/layout.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{% extends "!layout.html" %}

{% block sidebartitle %}
<!-- TODO: uncomment below before release to enable the version selector -->
<!-- <div class="version">
<div class="version">
<a href='tba'>{{ version }} &#x25BC</a>
</div> -->
</div>
{% include "searchbox.html" %}
{% endblock %}

Expand Down
35 changes: 9 additions & 26 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,34 +67,17 @@
torchao_version_docs = os.environ.get("TORCHAO_VERSION_DOCS", None)

# 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 "main" is set.
# tags like v0.1.0 or with the -rc suffix like v0.1.0-rc3 = > 0.1
# the version varible is used in layout.html: https://github.com/pytorch/torchao/blob/main/docs/source/_templates/layout.html#L29
version = release = "main"
if torchao_version_docs:
# Check if starts with release/ and set the version to the number after slash
if torchao_version_docs.startswith("release/"):
version = torchao_version_docs.split("/")[-1]
else:
# Remove "v" prefix if present
if torchao_version_docs.startswith("v"):
torchao_version_docs = torchao_version_docs[1:]
# Split to major, minor, and patch
version_components = torchao_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 = torchao_version_docs

html_title = " ".join((project, version, "documentation"))
# IF TORCHAO_VERSION_DOCS not set, set version to main.
else:
version = "main"
release = "main"
if torchao_version_docs.startswith("refs/tags/v"):
version = ".".join(
torchao_version_docs.split("/")[-1].split("-")[0].lstrip("v").split(".")[:2]
)
print(f"Version: {version}")
html_title = " ".join((project, version, "documentation"))

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
Expand Down
37 changes: 0 additions & 37 deletions docs/source/sg_execution_times.rst

This file was deleted.