Skip to content

Commit 0a47c81

Browse files
authored
Separate docs preview deployment (#773)
1 parent eff137f commit 0a47c81

4 files changed

Lines changed: 64 additions & 16 deletions

File tree

.github/workflows/CI.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,11 @@ jobs:
179179
using Documenter: doctest
180180
using KomaMRI
181181
doctest(KomaMRI)'
182-
- if: ${{ !contains( github.event.pull_request.labels.*.name, 'documentation' ) }}
183-
name: "Building documentation (docs/make.jl)"
182+
- name: "Building documentation (docs/make.jl)"
184183
run: julia --project=docs docs/make.jl
185184
env:
186185
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
187186
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
188-
- if: ${{ contains( github.event.pull_request.labels.*.name, 'documentation' ) }}
189-
name: "Building documentation (docs/make.jl) - [PR] PUSH_PREVIEW"
190-
run: julia --project=docs docs/make.jl push_preview
191-
env:
192-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
193-
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
194187
Skip:
195188
if: contains(github.event.head_commit.message, '[skip ci]')
196189
runs-on: ubuntu-latest

.github/workflows/docs-preview-cleanup.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ jobs:
1212
cleanup:
1313
name: Cleanup documentation preview
1414
runs-on: ubuntu-latest
15+
concurrency:
16+
group: docs-preview-gh-pages
17+
cancel-in-progress: false
1518
steps:
1619
- uses: actions/checkout@v6
1720
with:

.github/workflows/docs-preview.yml

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ on:
1111

1212
permissions:
1313
actions: read
14+
contents: write
1415
issues: write
1516
pull-requests: write
1617

1718
jobs:
1819
comment:
1920
if: github.event.workflow_run.event == 'pull_request'
20-
name: Comment documentation preview URL
21+
name: Deploy documentation preview
2122
runs-on: ubuntu-latest
23+
concurrency:
24+
group: docs-preview-gh-pages
25+
cancel-in-progress: false
2226
steps:
2327
- name: Find pull request
2428
id: pr
@@ -38,6 +42,16 @@ jobs:
3842
pull_number: pr.number,
3943
});
4044
45+
if (data.state !== 'open') {
46+
core.info('Pull request is not open.');
47+
return;
48+
}
49+
50+
if (data.head.repo.full_name !== `${context.repo.owner}/${context.repo.repo}`) {
51+
core.info('Pull request is not from this repository.');
52+
return;
53+
}
54+
4155
if (!data.labels.some(label => label.name === 'documentation')) {
4256
core.info('Pull request does not have the documentation label.');
4357
return;
@@ -63,6 +77,41 @@ jobs:
6377
6478
core.setOutput('number', pr.number);
6579
80+
- uses: actions/checkout@v6
81+
if: steps.pr.outputs.number != ''
82+
with:
83+
ref: refs/pull/${{ steps.pr.outputs.number }}/merge
84+
fetch-depth: 0
85+
86+
- uses: julia-actions/setup-julia@v2
87+
if: steps.pr.outputs.number != ''
88+
with:
89+
version: '1'
90+
91+
- name: "Documentation dev environment setup"
92+
if: steps.pr.outputs.number != ''
93+
run: |
94+
julia --project=docs -e '
95+
using Pkg
96+
Pkg.develop([
97+
PackageSpec(path=pwd(), subdir="."),
98+
PackageSpec(path=pwd(), subdir="KomaMRIBase"),
99+
PackageSpec(path=pwd(), subdir="KomaMRICore"),
100+
PackageSpec(path=pwd(), subdir="KomaMRIFiles"),
101+
PackageSpec(path=pwd(), subdir="KomaMRIPlots")
102+
])
103+
Pkg.instantiate()'
104+
105+
- name: Build and deploy preview
106+
if: steps.pr.outputs.number != ''
107+
run: |
108+
GITHUB_EVENT_NAME=pull_request \
109+
GITHUB_REF=refs/pull/${{ steps.pr.outputs.number }}/merge \
110+
julia --project=docs docs/make.jl push_preview
111+
env:
112+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
113+
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
114+
66115
- name: Comment preview URL
67116
if: steps.pr.outputs.number != ''
68117
uses: actions/github-script@v7

docs/make.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,13 @@ makedocs(;
7878
clean=false,
7979
)
8080

81-
DocumenterVitepress.deploydocs(;
82-
repo = "github.com/JuliaHealth/KomaMRI.jl",
83-
target = joinpath(@__DIR__, "build"),
84-
branch = "gh-pages",
85-
devbranch = "master",
86-
push_preview = true,
87-
)
81+
deploy_preview = "push_preview" in ARGS
82+
if get(ENV, "GITHUB_EVENT_NAME", "") == "push" || deploy_preview
83+
DocumenterVitepress.deploydocs(;
84+
repo = "github.com/JuliaHealth/KomaMRI.jl",
85+
target = joinpath(@__DIR__, "build"),
86+
branch = "gh-pages",
87+
devbranch = "master",
88+
push_preview = deploy_preview,
89+
)
90+
end

0 commit comments

Comments
 (0)