Skip to content

Commit c125181

Browse files
authored
ci: Generate docs for each PR (#2547)
## Description <!-- A summary of what this pull request achieves and a rough list of changes. --> Added a `docs.yaml` workflow that makes the github action bot reply to PRs with a link to built docs to your PRs. It only does so once, and then just updates the comment (although actually it doesn't necessarily need to, the link is always the same, but it's still nice in case someone changes the workflow). This is using the nightly toolchain, because we're using [`#[feature(doc_cfg)]`](https://doc.rust-lang.org/unstable-book/language-features/doc-cfg.html). ## Motivation I personally wanted this. Every now and then we get a PR with the description saying "the best way to review this is to start by looking at the generated docs". But then I need to checkout the PR, build the docs and open them. Having a link directly to the docs would be *amazing* IMO. I *also* think that having easy access to docs on every PR will make people check out the rendered docs on PRs more often. My hope here is that doc quality will thus improve. ## Breaking Changes <!-- Optional, if there are any breaking changes document them, including how to migrate older code. --> None of course. This is only CI. ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR. --> Wdyt? ## Change checklist - [x] Self-review. - ~~[ ] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant.~~ - ~~[ ] Tests if relevant.~~ - ~~[ ] All breaking changes documented.~~
1 parent accce8a commit c125181

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

.github/workflows/docs.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Docs Preview
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
preview_docs:
8+
timeout-minutes: 30
9+
name: Docs preview
10+
if: "github.event_name == 'pull_request'"
11+
runs-on: ubuntu-latest
12+
env:
13+
RUSTC_WRAPPER: "sccache"
14+
SCCACHE_GHA_ENABLED: "on"
15+
SCCACHE_CACHE_SIZE: "50G"
16+
PREVIEW_PATH: pr/${{ github.event.pull_request.number }}/docs
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: dtolnay/rust-toolchain@master
21+
with:
22+
toolchain: nightly-2024-05-02
23+
- name: Install sccache
24+
uses: mozilla-actions/[email protected]
25+
26+
- name: Generate Docs
27+
run: cargo doc --workspace --all-features --no-deps
28+
env:
29+
RUSTDOCFLAGS: --cfg docsrs
30+
31+
- name: Deploy Docs to Preview Branch
32+
uses: peaceiris/actions-gh-pages@v4
33+
with:
34+
github_token: ${{ secrets.GITHUB_TOKEN }}
35+
publish_dir: ./target/doc/
36+
destination_dir: ${{ env.PREVIEW_PATH }}
37+
publish_branch: generated-docs-preview
38+
39+
- name: Find Docs Comment
40+
uses: peter-evans/find-comment@v3
41+
id: fc
42+
with:
43+
issue-number: ${{ github.event.pull_request.number }}
44+
comment-author: 'github-actions[bot]'
45+
body-includes: Documentation for this PR has been generated
46+
47+
- name: Create or Update Docs Comment
48+
uses: peter-evans/create-or-update-comment@v4
49+
with:
50+
issue-number: ${{ github.event.pull_request.number }}
51+
comment-id: ${{ steps.fc.outputs.comment-id }}
52+
body: |
53+
Documentation for this PR has been generated and is available at: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ env.PREVIEW_PATH }}/iroh/
54+
55+
Last updated: ${{ github.event.pull_request.updated_at }}
56+
edit-mode: replace

0 commit comments

Comments
 (0)