-
Notifications
You must be signed in to change notification settings - Fork 40
84 lines (74 loc) · 2.56 KB
/
docs-preview.yml
File metadata and controls
84 lines (74 loc) · 2.56 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
name: Docs Preview
on:
workflow_run:
workflows:
- CI
types:
- completed
branches-ignore:
- master
permissions:
issues: write
pull-requests: read
jobs:
comment:
if: >-
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
name: Comment documentation preview URL
runs-on: ubuntu-latest
steps:
- name: Find pull request
id: pr
uses: actions/github-script@v7
with:
script: |
const pullRequests = context.payload.workflow_run.pull_requests;
if (!pullRequests || pullRequests.length !== 1) {
core.info(`Expected one pull request, found ${pullRequests?.length ?? 0}.`);
return;
}
const pr = pullRequests[0];
const { data } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
});
if (!data.labels.some(label => label.name === 'documentation')) {
core.info('Pull request does not have the documentation label.');
return;
}
core.setOutput('number', pr.number);
- name: Comment preview URL
if: steps.pr.outputs.number != ''
uses: actions/github-script@v7
with:
script: |
const prNumber = Number('${{ steps.pr.outputs.number }}');
const previewUrl = `https://juliahealth.github.io/KomaMRI.jl/previews/PR${prNumber}/`;
const marker = '<!-- komamri-docs-preview-link -->';
const body = `${marker}\nPreview available: ${previewUrl}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
per_page: 100,
});
const existing = comments.find(comment =>
comment.user?.type === 'Bot' && comment.body?.includes(marker)
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body,
});
}