|
7 | 7 | - nightly |
8 | 8 | - main |
9 | 9 | - release/* |
| 10 | + tags: |
| 11 | + - v[0-9]+.[0-9]+.[0-9] |
| 12 | + - v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+ |
10 | 13 | workflow_dispatch: |
11 | 14 |
|
12 | 15 | jobs: |
13 | 16 | build: |
14 | 17 | uses: pytorch/test-infra/.github/workflows/linux_job.yml@main |
15 | 18 | with: |
16 | 19 | repository: pytorch/vision |
| 20 | + upload-artifact: docs |
17 | 21 | script: | |
18 | 22 | set -euo pipefail |
19 | 23 |
|
|
44 | 48 | sed -i -e 's/-j auto/-j 1/' Makefile |
45 | 49 | make html |
46 | 50 | |
47 | | - mv build/html/* "${RUNNER_DOCS_DIR}" |
| 51 | + cp -r build/html "${RUNNER_ARTIFACT_DIR}" |
| 52 | + |
| 53 | + # On PRs we also want to upload the docs into our S3 bucket for preview. |
| 54 | + if [[ ${{ github.event_name == 'pull_request' }} ]]; then |
| 55 | + cp -r build/html/* "${RUNNER_DOCS_DIR}" |
| 56 | + fi |
| 57 | +
|
| 58 | + upload: |
| 59 | + needs: build |
| 60 | + if: github.repository == 'pytorch/vision' && github.event_name == 'push' && |
| 61 | + ((github.ref_type == 'branch' && github.ref_name == 'main') || github.ref_type == 'tag') |
| 62 | + permissions: |
| 63 | + contents: write |
| 64 | + uses: pytorch/test-infra/.github/workflows/linux_job.yml@main |
| 65 | + with: |
| 66 | + repository: pytorch/vision |
| 67 | + download-artifact: docs |
| 68 | + ref: gh-pages |
| 69 | + script: | |
| 70 | + set -euo pipefail |
| 71 | + |
| 72 | + REF_TYPE=${{ github.ref_type }} |
| 73 | + REF_NAME=${{ github.ref_name }} |
| 74 | +
|
| 75 | + if [[ "${REF_TYPE}" == branch ]]; then |
| 76 | + TARGET_FOLDER="${REF_NAME}" |
| 77 | + elif [[ "${REF_TYPE}" == tag ]]; then |
| 78 | + case "${REF_NAME}" in |
| 79 | + *-rc*) |
| 80 | + echo "Aborting upload since this is an RC tag: ${REF_NAME}" |
| 81 | + exit 0 |
| 82 | + ;; |
| 83 | + *) |
| 84 | + # Strip the leading "v" as well as the trailing patch version. For example: |
| 85 | + # 'v0.15.2' -> '0.15' |
| 86 | + TARGET_FOLDER=$(echo "${REF_NAME}" | sed 's/v\([0-9]\+\)\.\([0-9]\+\)\.[0-9]\+/\1.\2/') |
| 87 | + ;; |
| 88 | + esac |
| 89 | + fi |
| 90 | + echo "Target Folder: ${TARGET_FOLDER}" |
| 91 | +
|
| 92 | + mkdir -p "${TARGET_FOLDER}" |
| 93 | + rm -rf "${TARGET_FOLDER}"/* |
| 94 | + mv "${RUNNER_ARTIFACT_DIR}"/html/* "${TARGET_FOLDER}" |
| 95 | + git add "${TARGET_FOLDER}" || true |
| 96 | + |
| 97 | + if [[ "${TARGET_FOLDER}" == main ]]; then |
| 98 | + mkdir -p _static |
| 99 | + rm -rf _static/* |
| 100 | + cp -r "${TARGET_FOLDER}"/_static/* _static |
| 101 | + git add _static || true |
| 102 | + fi |
| 103 | + |
| 104 | + git config user.name 'pytorchbot' |
| 105 | + git config user.email '[email protected]' |
| 106 | + git commit -m "auto-generating sphinx docs" || true |
| 107 | + git push |
0 commit comments