Skip to content

Commit 19b2d3c

Browse files
authored
reinstate doc upload (#7580)
1 parent 99ec261 commit 19b2d3c

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

.github/workflows/docs.yml

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ on:
77
- nightly
88
- main
99
- release/*
10+
tags:
11+
- v[0-9]+.[0-9]+.[0-9]
12+
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
1013
workflow_dispatch:
1114

1215
jobs:
1316
build:
1417
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
1518
with:
1619
repository: pytorch/vision
20+
upload-artifact: docs
1721
script: |
1822
set -euo pipefail
1923
@@ -44,4 +48,60 @@ jobs:
4448
sed -i -e 's/-j auto/-j 1/' Makefile
4549
make html
4650
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

Comments
 (0)