Skip to content

Commit 1d7d824

Browse files
committed
Auto merge of #112407 - tgross35:ci-docs-publish, r=Mark-Simulacrum
Publish docs as github artifacts during CI Discussed here: https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/Building.20docs.20for.20PR.20CI The goal is to make docs available for download after CI runs on PRs, for easy review of API changes. Notes: - Currently this only captures library documentation (`core`, `alloc`, `std`, `test`, `proc_macro`) - You can't see artifacts until the entire workflow run has completed actions/upload-artifact#53 - There is currently a generic file name `ci-artifacts`. No way to customize this based on contained files unfortunately actions/upload-artifact#349 You can find the results at the bottom of the CI "summary" page: <img width="379" alt="image" src="https://github.com/rust-lang/rust/assets/13724985/d3748e59-242c-40f8-9f54-82177b9b481b">
2 parents 0cc541e + 696b0dd commit 1d7d824

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"
@@ -557,6 +570,17 @@ jobs:
557570
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.CACHES_AWS_ACCESS_KEY_ID)] }}"
558571
TOOLSTATE_REPO_ACCESS_TOKEN: "${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}"
559572
if: success() && !env.SKIP_JOB
573+
- name: create github artifacts
574+
run: src/ci/scripts/create-doc-artifacts.sh
575+
if: success() && !env.SKIP_JOB
576+
- name: upload artifacts to github
577+
uses: actions/upload-artifact@v3
578+
with:
579+
name: "${{ env.DOC_ARTIFACT_NAME }}"
580+
path: obj/artifacts/doc
581+
if-no-files-found: ignore
582+
retention-days: 5
583+
if: success() && !env.SKIP_JOB
560584
- name: upload artifacts to S3
561585
run: src/ci/scripts/upload-artifacts.sh
562586
env:
@@ -571,6 +595,7 @@ jobs:
571595
DIST_TRY_BUILD: 1
572596
CI_JOB_NAME: "${{ matrix.name }}"
573597
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
598+
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
574599
SCCACHE_BUCKET: rust-lang-ci-sccache2
575600
DEPLOY_BUCKET: rust-lang-ci2
576601
TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate"
@@ -672,6 +697,17 @@ jobs:
672697
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.CACHES_AWS_ACCESS_KEY_ID)] }}"
673698
TOOLSTATE_REPO_ACCESS_TOKEN: "${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}"
674699
if: success() && !env.SKIP_JOB
700+
- name: create github artifacts
701+
run: src/ci/scripts/create-doc-artifacts.sh
702+
if: success() && !env.SKIP_JOB
703+
- name: upload artifacts to github
704+
uses: actions/upload-artifact@v3
705+
with:
706+
name: "${{ env.DOC_ARTIFACT_NAME }}"
707+
path: obj/artifacts/doc
708+
if-no-files-found: ignore
709+
retention-days: 5
710+
if: success() && !env.SKIP_JOB
675711
- name: upload artifacts to S3
676712
run: src/ci/scripts/upload-artifacts.sh
677713
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)