-
Notifications
You must be signed in to change notification settings - Fork 0
91 lines (81 loc) · 3.61 KB
/
Copy pathrustdoc.yml
File metadata and controls
91 lines (81 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: "rustdoc"
on:
push:
branches:
- main
pull_request:
merge_group:
jobs:
rustdoc:
runs-on: ubuntu-latest
env:
RUSTDOCFLAGS: "-D warnings"
steps:
- name: Checkout
uses: actions/checkout@v5
with:
# Make sure the actual branch is checked out when running on pull requests
ref: ${{ github.head_ref }}
repository: ${{github.event.pull_request.head.repo.full_name || github.repository }}
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Install Rust problem matchers
uses: r7kamura/rust-problem-matchers@v1
- name: Use dependency cache
uses: Swatinem/rust-cache@v2
- name: cargo doc
uses: actions-rs/cargo@v1
with:
command: doc
args: --no-deps --all-features
- name: Upload documentation artifact
uses: actions/upload-artifact@v5
with:
name: rustdoc
path: target/doc/
retention-days: 7
- name: Comment on PR with artifact link
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
uses: actions/github-script@v8
with:
script: |
const runId = context.runId;
const repoOwner = context.repo.owner;
const repoName = context.repo.repo;
const artifactUrl = `https://github.com/${repoOwner}/${repoName}/actions/runs/${runId}`;
const message = `📚 **Documentation Preview**
The rustdoc documentation has been generated for this PR.
You can download the \`rustdoc\` artifact from the [workflow run](${artifactUrl}) to preview the documentation locally.
To view the documentation:
1. Download and extract the artifact
2. Open \`index.html\` in your browser`;
// Find existing comment
const comments = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('📚 **Documentation Preview**')
);
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
comment_id: botComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});
} else {
// Create new comment
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});
}