Skip to content

Commit 696b0dd

Browse files
committed
Publish docs as github artifacts during CI
This PR saves library docs as github artifacts so they can be easily viewed for review. Discussed in <https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/Building.20docs.20for.20PR.20CI>
1 parent df77afb commit 696b0dd

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

.github/workflows/ci.yml

+36
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
env:
3939
CI_JOB_NAME: "${{ matrix.name }}"
4040
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
41+
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
4142
SCCACHE_BUCKET: rust-lang-ci-sccache2
4243
TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate"
4344
CACHE_DOMAIN: ci-caches.rust-lang.org
@@ -143,6 +144,17 @@ jobs:
143144
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.CACHES_AWS_ACCESS_KEY_ID)] }}"
144145
TOOLSTATE_REPO_ACCESS_TOKEN: "${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}"
145146
if: success() && !env.SKIP_JOB
147+
- name: create github artifacts
148+
run: src/ci/scripts/create-doc-artifacts.sh
149+
if: success() && !env.SKIP_JOB
150+
- name: upload artifacts to github
151+
uses: actions/upload-artifact@v3
152+
with:
153+
name: "${{ env.DOC_ARTIFACT_NAME }}"
154+
path: obj/artifacts/doc
155+
if-no-files-found: ignore
156+
retention-days: 5
157+
if: success() && !env.SKIP_JOB
146158
- name: upload artifacts to S3
147159
run: src/ci/scripts/upload-artifacts.sh
148160
env:
@@ -156,6 +168,7 @@ jobs:
156168
env:
157169
CI_JOB_NAME: "${{ matrix.name }}"
158170
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
171+
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
159172
SCCACHE_BUCKET: rust-lang-ci-sccache2
160173
DEPLOY_BUCKET: rust-lang-ci2
161174
TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate"
@@ -567,6 +580,17 @@ jobs:
567580
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.CACHES_AWS_ACCESS_KEY_ID)] }}"
568581
TOOLSTATE_REPO_ACCESS_TOKEN: "${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}"
569582
if: success() && !env.SKIP_JOB
583+
- name: create github artifacts
584+
run: src/ci/scripts/create-doc-artifacts.sh
585+
if: success() && !env.SKIP_JOB
586+
- name: upload artifacts to github
587+
uses: actions/upload-artifact@v3
588+
with:
589+
name: "${{ env.DOC_ARTIFACT_NAME }}"
590+
path: obj/artifacts/doc
591+
if-no-files-found: ignore
592+
retention-days: 5
593+
if: success() && !env.SKIP_JOB
570594
- name: upload artifacts to S3
571595
run: src/ci/scripts/upload-artifacts.sh
572596
env:
@@ -581,6 +605,7 @@ jobs:
581605
DIST_TRY_BUILD: 1
582606
CI_JOB_NAME: "${{ matrix.name }}"
583607
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
608+
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
584609
SCCACHE_BUCKET: rust-lang-ci-sccache2
585610
DEPLOY_BUCKET: rust-lang-ci2
586611
TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate"
@@ -682,6 +707,17 @@ jobs:
682707
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.CACHES_AWS_ACCESS_KEY_ID)] }}"
683708
TOOLSTATE_REPO_ACCESS_TOKEN: "${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}"
684709
if: success() && !env.SKIP_JOB
710+
- name: create github artifacts
711+
run: src/ci/scripts/create-doc-artifacts.sh
712+
if: success() && !env.SKIP_JOB
713+
- name: upload artifacts to github
714+
uses: actions/upload-artifact@v3
715+
with:
716+
name: "${{ env.DOC_ARTIFACT_NAME }}"
717+
path: obj/artifacts/doc
718+
if-no-files-found: ignore
719+
retention-days: 5
720+
if: success() && !env.SKIP_JOB
685721
- name: upload artifacts to S3
686722
run: src/ci/scripts/upload-artifacts.sh
687723
env:

src/ci/docker/host-x86_64/mingw-check/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ ENV SCRIPT python3 ../x.py --stage 2 test src/tools/expand-yaml-anchors && \
4545
python3 ../x.py test --stage 0 src/tools/compiletest && \
4646
python3 ../x.py test --stage 0 core alloc std test proc_macro && \
4747
# Build both public and internal documentation.
48+
RUSTDOCFLAGS=\"--document-private-items --document-hidden-items\" python3 ../x.py doc --stage 0 library && \
49+
mkdir -p /checkout/obj/staging/doc && \
50+
cp -r build/x86_64-unknown-linux-gnu/doc /checkout/obj/staging && \
4851
RUSTDOCFLAGS=\"--document-private-items --document-hidden-items\" python3 ../x.py doc --stage 0 compiler && \
4952
RUSTDOCFLAGS=\"--document-private-items --document-hidden-items\" python3 ../x.py doc --stage 0 library/test && \
5053
/scripts/validate-toolstate.sh && \

src/ci/github-actions/ci.yml

+16
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ x--expand-yaml-anchors--remove:
3434
- &shared-ci-variables
3535
CI_JOB_NAME: ${{ matrix.name }}
3636
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
37+
# commit of PR sha or commit sha. `GITHUB_SHA` is not accurate for PRs.
38+
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
3739

3840
- &public-variables
3941
SCCACHE_BUCKET: rust-lang-ci-sccache2
@@ -229,6 +231,20 @@ x--expand-yaml-anchors--remove:
229231
TOOLSTATE_REPO_ACCESS_TOKEN: ${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}
230232
<<: *step
231233

234+
- name: create github artifacts
235+
run: src/ci/scripts/create-doc-artifacts.sh
236+
<<: *step
237+
238+
- name: upload artifacts to github
239+
uses: actions/upload-artifact@v3
240+
with:
241+
# name is set in previous step
242+
name: ${{ env.DOC_ARTIFACT_NAME }}
243+
path: obj/artifacts/doc
244+
if-no-files-found: ignore
245+
retention-days: 5
246+
<<: *step
247+
232248
- name: upload artifacts to S3
233249
run: src/ci/scripts/upload-artifacts.sh
234250
env:
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
# Compress doc artifacts and name them based on the commit, or the date if
3+
# commit is not available.
4+
5+
set -euox pipefail
6+
7+
# Try to get short commit hash, fallback to date
8+
if [ -n "$HEAD_SHA" ]; then
9+
short_rev=$(echo "${HEAD_SHA}" | cut -c1-8)
10+
else
11+
short_rev=$(git rev-parse --short HEAD || date -u +'%Y-%m-%dT%H%M%SZ')
12+
fi
13+
14+
# Try to get branch, fallback to none
15+
branch=$(git branch --show-current || echo)
16+
17+
if [ -n "$branch" ]; then
18+
branch="${branch}-"
19+
fi
20+
21+
if [ "${GITHUB_EVENT_NAME:=none}" = "pull_request" ]; then
22+
pr_num=$(echo "$GITHUB_REF_NAME" | cut -d'/' -f1)
23+
name="doc-${pr_num}-${short_rev}"
24+
else
25+
name="doc-${branch}${short_rev}"
26+
fi
27+
28+
29+
if [ -d "obj/staging/doc" ]; then
30+
mkdir -p obj/artifacts/doc
31+
32+
# Level 12 seems to give a good tradeoff of time vs. space savings
33+
ZSTD_CLEVEL=12 ZSTD_NBTHREADS=4 \
34+
tar --zstd -cf "obj/artifacts/doc/${name}.tar.zst" -C obj/staging/doc .
35+
36+
ls -lh obj/artifacts/doc
37+
fi
38+
39+
# Set this environment variable for future use if running in CI
40+
if [ -n "$GITHUB_ENV" ]; then
41+
echo "DOC_ARTIFACT_NAME=${name}" >> "$GITHUB_ENV"
42+
fi

0 commit comments

Comments
 (0)