Skip to content

Commit 7542607

Browse files
committed
ci: Add automatic uploading for docs previews
Adds automatic uploading for docs previews by specifying a special directory for users to put there documentation in (RUNNER_DOCS_DIR) and then having the default linux job take those and upload them to S3. Also adds a test to verify that we are doing the upload correctly. Signed-off-by: Eli Uriegas <[email protected]>
1 parent 72c7461 commit 7542607

File tree

3 files changed

+71
-11
lines changed

3 files changed

+71
-11
lines changed

.github/actions/setup-linux/action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,15 @@ runs:
5454
RUNNER_ARTIFACT_DIR="${RUNNER_TEMP}/artifacts"
5555
mkdir -p "${RUNNER_ARTIFACT_DIR}"
5656
echo "RUNNER_ARTIFACT_DIR=${RUNNER_ARTIFACT_DIR}" >> "${GITHUB_ENV}"
57-
57+
5858
RUNNER_TEST_RESULTS_DIR="${RUNNER_TEMP}/test-results"
5959
mkdir -p "${RUNNER_TEST_RESULTS_DIR}"
6060
echo "RUNNER_TEST_RESULTS_DIR=${RUNNER_TEST_RESULTS_DIR}" >> "${GITHUB_ENV}"
6161
62+
RUNNER_DOCS_DIR="${RUNNER_TEMP}/docs"
63+
mkdir -p "${RUNNER_DOCS_DIR}"
64+
echo "RUNNER_DOCS_DIR=${RUNNER_DOCS_DIR}" >> "${GITHUB_ENV}"
65+
6266
- name: Needs nvidia driver?
6367
shell: bash
6468
id: needs-nvidia-driver

.github/workflows/linux_job.yml

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ jobs:
7979
inputs.gpu-arch-version)
8080
|| inputs.docker-image }}
8181
REPOSITORY: ${{ inputs.repository || github.repository }}
82+
# Will be blank outside of this
83+
PR_NUMBER: ${{ github.event.pull_request.number }}
8284
SCRIPT: ${{ inputs.script }}
8385
runs-on: ${{ inputs.runner }}
8486
# TODO: Eventually this should run in a container, we need to make a container that matches up
@@ -155,6 +157,7 @@ jobs:
155157
# shellcheck disable=SC2086,SC2090
156158
container_name=$(docker run \
157159
-e RUNNER_ARTIFACT_DIR=/artifacts \
160+
-e RUNNER_DOCS_DIR=/docs \
158161
-e RUNNER_TEST_RESULTS_DIR=/test-results \
159162
--env-file="${RUNNER_TEMP}/github_env_${GITHUB_RUN_ID}" \
160163
`# It is unknown why the container sees a different value for this.` \
@@ -170,6 +173,7 @@ jobs:
170173
-v "${GITHUB_WORKSPACE}/${REPOSITORY}:/work" \
171174
-v "${GITHUB_WORKSPACE}/test-infra:/test-infra" \
172175
-v "${RUNNER_ARTIFACT_DIR}:/artifacts" \
176+
-v "${RUNNER_DOCS_DIR}:/docs" \
173177
-v "${RUNNER_TEST_RESULTS_DIR}:/test-results" \
174178
-v "${RUNNER_TEMP}/exec_script:/exec" \
175179
-v "${GITHUB_STEP_SUMMARY}":"${GITHUB_STEP_SUMMARY}" \
@@ -191,26 +195,37 @@ jobs:
191195
with:
192196
directory: ${{ github.workspace }}/${{ env.repository }}
193197

194-
- name: Chown artifacts
198+
- name: Chown runner temp
195199
if: ${{ always() }}
196200
uses: ./test-infra/.github/actions/chown-directory
197201
with:
198-
directory: ${{ env.RUNNER_ARTIFACT_DIR }}
202+
directory: ${{ env.RUNNER_TEMP }}
199203

200-
- name: Check if there are potential artifacts and move them to the correct artifact location
204+
- name: Prepare artifacts for upload
201205
working-directory: ${{ inputs.repository }}
202206
id: check-artifacts
203-
if: ${{ inputs.upload-artifact != '' }}
204207
env:
205208
UPLOAD_ARTIFACT_NAME: ${{ inputs.upload-artifact }}
206209
run: |
207-
# If the default execution path is followed then we should get a wheel in the dist/ folder
208-
# attempt to just grab whatever is in there and scoop it all up
209-
if find "dist/" -name "*.whl" >/dev/null 2>/dev/null; then
210-
mv -v dist/*.whl "${RUNNER_ARTIFACT_DIR}/"
210+
# Only do these steps if we actually want to upload an artifact
211+
if [[ -n "${UPLOAD_ARTIFACT_NAME}" ]]; then
212+
# If the default execution path is followed then we should get a wheel in the dist/ folder
213+
# attempt to just grab whatever is in there and scoop it all up
214+
if find "dist/" -name "*.whl" >/dev/null 2>/dev/null; then
215+
mv -v dist/*.whl "${RUNNER_ARTIFACT_DIR}/"
216+
fi
217+
# Set to fail upload step if there are no files for upload and expected files for upload
218+
echo 'if-no-files-found=error' >> "${GITHUB_OUTPUT}"
219+
fi
220+
221+
upload_docs=0
222+
# Check if there are things in the documentation folder to uplaod
223+
if find "${RUNNER_DOCS_DIR}" -mindepth 1 -maxdepth 1 | read; then
224+
# TODO: Add a check here to test if on ec2 because if we're not on ec2 then this
225+
# upload will probably not work correctly
226+
upload_docs=1
211227
fi
212-
# Set to fail upload step if there are no files for upload and expected files for upload
213-
echo 'if-no-files-found=error' >> "${GITHUB_OUTPUT}"
228+
echo "upload-docs=${upload_docs}" >> "${GITHUB_OUTPUT}"
214229
215230
- name: Upload artifacts to GitHub (if any)
216231
uses: actions/upload-artifact@v3
@@ -220,6 +235,27 @@ jobs:
220235
path: ${{ runner.temp }}/artifacts/
221236
if-no-files-found: ${{ steps.check-artifacts.outputs.if-no-files-found }}
222237

238+
# TODO: Remove once we converge on documentation paths
239+
- name: (legacy) Upload documentation to S3 (if any)
240+
uses: seemethere/upload-artifact-s3@v5
241+
if: ${{ steps.check-artifacts.outputs.upload-docs == 1 && github.event.pull_request.number != '' }}
242+
with:
243+
retention-days: 14
244+
s3-bucket: doc-previews
245+
if-no-files-found: error
246+
path: ${{ env.RUNNER_DOCS_DIR }}
247+
s3-prefix: pytorch/${{ env.REPOSITORY }}/${{ github.event.pull_request.number }}
248+
249+
- name: Upload documentation to S3 (if any)
250+
uses: seemethere/upload-artifact-s3@v5
251+
if: ${{ steps.check-artifacts.outputs.upload-docs == 1 && github.event.pull_request.number != '' }}
252+
with:
253+
retention-days: 14
254+
s3-bucket: doc-previews
255+
if-no-files-found: error
256+
path: ${{ env.RUNNER_DOCS_DIR }}
257+
s3-prefix: ${{ env.REPOSITORY }}/${{ github.event.pull_request.number }}
258+
223259
- name: Teardown Linux
224260
if: ${{ always() }}
225261
uses: ./test-infra/.github/actions/teardown-linux

.github/workflows/test_linux_job.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,26 @@ jobs:
7575
download-artifact: my-cool-artifact
7676
script: |
7777
grep "hello" "${RUNNER_ARTIFACT_DIR}/cool_beans"
78+
upload-docs:
79+
uses: ./.github/workflows/linux_job.yml
80+
with:
81+
runner: linux.2xlarge
82+
test-infra-repository: ${{ github.repository }}
83+
test-infra-ref: ${{ github.ref }}
84+
script: |
85+
echo "hello" > "${RUNNER_DOCS_DIR}/index.html"
86+
verify-upload-docs:
87+
needs: upload-docs
88+
uses: ./.github/workflows/linux_job.yml
89+
with:
90+
runner: linux.2xlarge
91+
test-infra-repository: ${{ github.repository }}
92+
test-infra-ref: ${{ github.ref }}
93+
script: |
94+
# Sleep a couple of seconds just in case S3 is being slow (might not be needed?)
95+
sleep 10
96+
REPO_NAME="$(echo "${REPOSITORY}" | cut -d '/' -f2)"
97+
curl -fsSL "https://docs-preview.pytorch.org/${REPO_NAME}/${PR_NUMBER}/index.html" | grep "hello"
7898
test-with-matrix:
7999
uses: ./.github/workflows/linux_job.yml
80100
strategy:

0 commit comments

Comments
 (0)