1
+ # Copyright 2024 The Fuchsia Authors
2
+ #
3
+ # Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
4
+ # <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
5
+ # license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
6
+ # This file may not be copied, modified, or distributed except according to
7
+ # those terms.
8
+
9
+ name : Publish Rustdoc on GitHub Pages
10
+ on :
11
+ push :
12
+ branches : [main]
13
+ pull_request :
14
+
15
+ permissions :
16
+ contents : read
17
+ pages : write
18
+ id-token : write
19
+ concurrency :
20
+ group : deploy
21
+ cancel-in-progress : false
22
+
23
+ jobs :
24
+ build :
25
+ name : Build
26
+ runs-on : ubuntu-latest
27
+ steps :
28
+ - uses : actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
29
+ - name : Configure environment variables
30
+ run : |
31
+ set -eo pipefail
32
+
33
+ # We use toolchain descriptors ("msrv", "stable", "nightly", and
34
+ # values from the "metadata.build-rs" key in Cargo.toml) in the
35
+ # matrix. This step converts the current descriptor to a particular
36
+ # toolchain version by looking up the corresponding key in
37
+ # `Cargo.toml`. It sets the `ZC_NIGHTLY_TOOLCHAIN` environment
38
+ # variable for use in the next step (toolchain installation) because
39
+ # GitHub variable interpolation doesn't support running arbitrary
40
+ # commands. In other words, we can't rewrite:
41
+ #
42
+ # toolchain: $ {{ env.ZC_NIGHTLY_TOOLCHAIN }}
43
+ #
44
+ # ...to:
45
+ #
46
+ # toolchain: $ {{ ./cargo.sh --version matrix.toolchain }} # hypothetical syntax
47
+ ZC_NIGHTLY_TOOLCHAIN="$(./cargo.sh --version nightly)"
48
+ echo "Found that the 'nightly' toolchain is $ZC_NIGHTLY_TOOLCHAIN" | tee -a $GITHUB_STEP_SUMMARY
49
+ echo "ZC_NIGHTLY_TOOLCHAIN=$ZC_NIGHTLY_TOOLCHAIN" >> $GITHUB_ENV
50
+
51
+ # On our MSRV, `cargo` does not know about the `rust-version` field. As a
52
+ # result, in `cargo.sh`, if we use our MSRV toolchain in order to run `cargo
53
+ # metadata`, we will not be able to extract the `rust-version` field. Thus,
54
+ # in `cargo.sh`, we explicitly do `cargo +stable metadata`. This requires a
55
+ # (more recent) stable toolchain to be installed. As of this writing, this
56
+ # toolchain is not used for anything else.
57
+ - name : Install stable Rust for use in 'cargo.sh'
58
+ uses : dtolnay/rust-toolchain@00b49be78f40fba4e87296b2ead62868750bdd83 # stable
59
+ with :
60
+ toolchain : stable
61
+ # This isn't actually required to build docs, but `cargo.sh` checks
62
+ # for it in order to help avoid the subtle UI test bugs that happen
63
+ # when UI tests are run without it installed.
64
+ components : rust-src
65
+
66
+ - name : Install Rust with nightly toolchain (${{ env.ZC_NIGHTLY_TOOLCHAIN }})
67
+ uses : dtolnay/rust-toolchain@00b49be78f40fba4e87296b2ead62868750bdd83 # stable
68
+ with :
69
+ toolchain : ${{ env.ZC_NIGHTLY_TOOLCHAIN }}
70
+ targets : " x86_64-unknown-linux-gnu"
71
+
72
+ - name : Configure GitHub pages
73
+ id : pages
74
+ uses : actions/configure-pages@v4
75
+
76
+ - name : Cargo doc
77
+ # We pass --document-private-items and --document-hidden items to ensure
78
+ # that documentation always builds even for these items. This makes
79
+ # future changes to make those items public/non-hidden more painless.
80
+ # Note that --document-hidden-items is unstable; if a future release
81
+ # breaks or removes it, we can just update CI to no longer pass that
82
+ # flag.
83
+ run : |
84
+ # Include arguments passed during docs.rs deployments to make sure those
85
+ # work properly.
86
+ #
87
+ # TODO(#1228): Use `jq` to parse these from `Cargo.toml` instead of
88
+ # hard-coding them once we've gotten it working again.
89
+ METADATA_DOCS_RS_RUSTDOC_ARGS='--cfg doc_cfg --generate-link-to-definition'
90
+ export RUSTDOCFLAGS="-Z unstable-options --document-hidden-items $METADATA_DOCS_RS_RUSTDOC_ARGS"
91
+
92
+ # TODO: Use `./cargo.sh` instead once we've debugged why it won't work.
93
+ cargo +${{ env.ZC_NIGHTLY_TOOLCHAIN }} doc --document-private-items --package zerocopy --all-features
94
+
95
+ - name : Add HTML redirect to doc root
96
+ # By default, Rustdoc doesn't redirect to the documentation root, so we
97
+ # manually generate a redirect.
98
+ run : echo '<meta http-equiv="refresh" content="0;url=aoc/index.html">' > target/doc/index.html
99
+
100
+ - name : Upload Cargo doc output to GitHub Pages
101
+ uses : actions/upload-pages-artifact@v3
102
+ with :
103
+ path : target/doc
104
+ deploy :
105
+ name : Deploy to GitHub Pages
106
+ environment :
107
+ name : github-pages
108
+ url : ${{ steps.deployment.outputs.page_url }}
109
+ runs-on : ubuntu-latest
110
+ needs : build
111
+ steps :
112
+ - name : Deploy to GitHub Pages
113
+ id : deployment
114
+ uses : actions/deploy-pages@v4
0 commit comments