-
Notifications
You must be signed in to change notification settings - Fork 40
152 lines (133 loc) · 5.13 KB
/
docs-preview.yml
File metadata and controls
152 lines (133 loc) · 5.13 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Docs Preview
on:
workflow_run:
workflows:
- CI
types:
- completed
branches-ignore:
- master
permissions:
actions: read
contents: write
issues: write
pull-requests: write
jobs:
comment:
if: github.event.workflow_run.event == 'pull_request'
name: Deploy documentation preview
runs-on: ubuntu-latest
concurrency:
group: docs-preview-gh-pages
cancel-in-progress: false
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.state !== 'open') {
core.info('Pull request is not open.');
return;
}
if (data.head.repo.full_name !== `${context.repo.owner}/${context.repo.repo}`) {
core.info('Pull request is not from this repository.');
return;
}
if (!data.labels.some(label => label.name === 'documentation')) {
core.info('Pull request does not have the documentation label.');
return;
}
if (data.head.sha !== context.payload.workflow_run.head_sha) {
core.info('Workflow run is not for the current pull request head.');
return;
}
const jobs = await github.paginate(github.rest.actions.listJobsForWorkflowRun, {
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
per_page: 100,
});
const docsJob = jobs.find(job => job.name === 'Documentation');
if (docsJob?.conclusion !== 'success') {
core.info(`Documentation job conclusion: ${docsJob?.conclusion ?? 'missing'}.`);
return;
}
core.setOutput('number', pr.number);
- uses: actions/checkout@v6
if: steps.pr.outputs.number != ''
with:
ref: refs/pull/${{ steps.pr.outputs.number }}/merge
fetch-depth: 0
- uses: julia-actions/setup-julia@v2
if: steps.pr.outputs.number != ''
with:
version: '1'
- name: "Documentation dev environment setup"
if: steps.pr.outputs.number != ''
run: |
julia --project=docs -e '
using Pkg
Pkg.develop([
PackageSpec(path=pwd(), subdir="."),
PackageSpec(path=pwd(), subdir="KomaMRIBase"),
PackageSpec(path=pwd(), subdir="KomaMRICore"),
PackageSpec(path=pwd(), subdir="KomaMRIFiles"),
PackageSpec(path=pwd(), subdir="KomaMRIPlots")
])
Pkg.instantiate()'
- name: Build and deploy preview
if: steps.pr.outputs.number != ''
run: |
GITHUB_EVENT_NAME=pull_request \
GITHUB_REF=refs/pull/${{ steps.pr.outputs.number }}/merge \
julia --project=docs docs/make.jl push_preview
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
- 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 previewSha = context.payload.workflow_run.head_sha.slice(0, 7);
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const body = `${marker}\nPreview available: ${previewUrl}\n\nLast preview build: ${previewSha}, [Docs Preview run ${context.runId}](${runUrl})`;
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,
});
}