Skip to content

Update

Update #14468

Workflow file for this run

name: Build Docs
on:
push:
branches:
- main
- release/*
- 'gh/**'
tags:
- v[0-9]+.[0-9]+.[0-9]
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
pull_request:
paths:
- 'docs/**'
workflow_dispatch:
concurrency:
group: build-docs-${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_number || github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash -l -eo pipefail {0}
jobs:
build_docs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11']
steps:
- name: Check out repo
uses: actions/checkout@v4
- name: Setup conda env
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
miniconda-version: "latest"
activate-environment: test
python-version: ${{ matrix.python-version }}
- name: Update pip
run: python -m pip install --upgrade pip
- name: Install dependencies
run: |
python -m pip install torch
python -m pip install -e . --no-build-isolation
pip install -r dev-requirements.txt
python -m pip install -r docs/requirements.txt
- name: Build docs
env:
TORCHAO_VERSION_DOCS: ${{ github.ref }}
run: |
cd docs
make html
- uses: actions/upload-artifact@v4
with:
name: Doc-Build
path: docs/build/html/
doc-preview:
runs-on: [self-hosted, linux.2xlarge]
needs: build_docs
if: ${{ github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }}
permissions:
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: Doc-Build
path: docs
- name: Upload docs preview
uses: seemethere/upload-artifact-s3@v5
if: ${{ github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }}
with:
retention-days: 14
s3-bucket: doc-previews
if-no-files-found: error
path: docs
s3-prefix: pytorch/ao/${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.run_id }}
- name: Get preview URL
if: ${{ github.event_name == 'workflow_dispatch' }}
id: preview-url
run: |
echo "url=https://docs-preview.pytorch.org/pytorch/ao/${{ github.run_id }}/index.html" >> $GITHUB_OUTPUT
- name: Find associated PR and post comment
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: actions/github-script@v7
with:
script: |
const prs = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: `${context.repo.owner}:${context.ref.replace('refs/heads/', '')}`,
state: 'open'
});
console.log(`Found ${prs.data.length} open PRs for branch ${context.ref}`);
if (prs.data.length > 0) {
const prNumber = prs.data[0].number;
console.log(`Posting comment to PR #${prNumber}`);
const previewUrl = '${{ steps.preview-url.outputs.url }}';
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `## 📄 Doc Preview (workflow_dispatch)\n\nYou triggered a doc build manually via workflow_dispatch.\nThe pytorchbot doc preview link will not work for this build.\n\n**Use this link instead:** ${previewUrl}`
});
} else {
console.log('No open PR found for this branch');
}
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/ao' && github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: gh-pages
persist-credentials: true
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: Doc-Build
path: docs
- name: Add no-index tag
run: |
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
- name: Move and commit changes
run: |
set -euo pipefail
# 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}"
mkdir -p "${TARGET_FOLDER}"
rm -rf "${TARGET_FOLDER}"/*
mv docs/* "${TARGET_FOLDER}"
git config user.name 'pytorchbot'
git config user.email 'soumith+bot@pytorch.org'
git add "${TARGET_FOLDER}" || true
git commit -m "auto-generating sphinx docs" || true
git push -f