• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1name: Build documentation
2
3on:
4  pull_request:
5  push:
6    branches:
7      - main
8      - release/*
9    tags:
10      - v[0-9]+.[0-9]+.[0-9]+
11      - v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
12  workflow_dispatch:
13  schedule:
14    - cron: '0 0 * * *'
15
16jobs:
17  build:
18    uses: pytorch/test-infra/.github/workflows/linux_job.yml@release/2.5
19    strategy:
20      matrix:
21        include:
22          - build-tool: buck2
23    with:
24      job-name: Build doc
25      runner: linux.2xlarge
26      docker-image: executorch-ubuntu-22.04-clang12
27      submodules: 'true'
28      repository: pytorch/executorch
29      upload-artifact: docs
30      timeout: 90
31      script: |
32        # The generic Linux job chooses to use base env, not the one setup by the image
33        CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
34        conda activate "${CONDA_ENV}"
35
36        BUILD_TOOL=${{ matrix.build-tool }}
37        # Setup dependencies as there is no Docker support
38        PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "${BUILD_TOOL}"
39
40        if [[(${GITHUB_EVENT_NAME} = 'pull_request' && (${GITHUB_BASE_REF} = 'release'*)) || (${GITHUB_REF} = 'refs/heads/release'*) ]]; then
41          export CHANNEL=test
42        else
43          export CHANNEL=nightly
44        fi
45
46        # Get the version of ExecuTorch from REF_NAME and save as ET_VERSION_DOCS
47        # ET_VERSION_DOCS will be pulled during the doc build to add to the version dropdown
48        # on the website. See docs/source/conf.py for details
49
50        GITHUB_REF=${{ github.ref }}
51        echo "$GITHUB_REF"
52        export ET_VERSION_DOCS="${GITHUB_REF}"
53        echo "$ET_VERSION_DOCS"
54
55        set -eux
56
57        # clean up the ${RUNNER_DOCS_DIR} if exists:
58        rm -rf "${RUNNER_DOCS_DIR}"/*
59        # clean up the ${RUNNER_ARTIFACT_DIR} if exists:
60        rm -rf "${RUNNER_ARTIFACT_DIR}"/*
61
62        # Build docset:
63        cd docs
64        doxygen source/Doxyfile
65        make html
66        cd ..
67
68        # If it's main branch, add noindex tag to all .html files to exclude from Google Search indexing.
69        echo "GitHub Ref: ${GITHUB_REF}"
70        if [[ "${{ github.ref }}" == 'refs/heads/main' ]]; then
71          find docs/_build/html/ -name "*.html" -print0 | xargs -0 sed -i '/<head>/a \ \ <meta name="robots" content="noindex">';
72        fi
73
74        cp -rf docs/_build/html/* "${RUNNER_DOCS_DIR}"
75
76        mv docs/_build/html "${RUNNER_ARTIFACT_DIR}"
77
78        ls -R "${RUNNER_ARTIFACT_DIR}"/*/*.html
79
80  upload-gh-pages:
81    needs: build
82    if: github.repository == 'pytorch/executorch' && github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
83    permissions:
84      contents: write
85    uses: pytorch/test-infra/.github/workflows/linux_job.yml@release/2.5
86    with:
87      repository: pytorch/executorch
88      download-artifact: docs
89      ref: gh-pages
90      timeout: 90
91      script: |
92        set -euo pipefail
93
94        # Get github.ref for the output doc folder. By default "main"
95        # If matches a tag like refs/tags/v1.12.0-rc3 or
96        # refs/tags/v1.12.0 convert to 1.12
97        export GITHUB_REF=${{ github.ref }}
98
99        # Convert refs/tags/v1.12.0rc3 into 1.12.
100        # Adopted from https://github.com/pytorch/pytorch/blob/release/2.5/.github/workflows/_docs.yml#L150C11-L155C13
101        if [[ "${GITHUB_REF}" =~ ^refs/tags/v([0-9]+\.[0-9]+) ]]; then
102          TARGET_FOLDER="${BASH_REMATCH[1]}"
103        else
104          TARGET_FOLDER="main"
105        fi
106        echo "Target Folder: ${TARGET_FOLDER}"
107
108        mkdir -p "${TARGET_FOLDER}"
109        # Clean up target folder if exists and copy html output to the
110        # Target folder
111        rm -rf "${TARGET_FOLDER}"/*
112        mv "${RUNNER_ARTIFACT_DIR}"/html/* "${TARGET_FOLDER}"
113        git add "${TARGET_FOLDER}" || true
114
115        git config user.name 'pytorchbot'
116        git config user.email 'soumith+bot@pytorch.org'
117        git commit -m "Auto-generating sphinx docs" || true
118        git push -f
119