Skip to content

Commit 5da2ba5

Browse files
authored
chore: guard Git commands in docs/make.jl against accidental deployment (#57)
1 parent e02d468 commit 5da2ba5

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ jobs:
2727
run: |
2828
git config user.name github-actions
2929
git config user.email [email protected]
30-
julia --project=. docs/make.jl
30+
julia --project=. docs/make.jl deploy

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/Manifest.toml
2+
/docs/out/

docs/make.jl

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,33 +81,39 @@ MultiDocumenter.make(
8181
rootpath = "/MultiDocumenter.jl/",
8282
)
8383

84-
gitroot = normpath(joinpath(@__DIR__, ".."))
85-
run(`git pull`)
86-
outbranch = "gh-pages"
87-
has_outbranch = true
88-
if !success(`git checkout $outbranch`)
89-
has_outbranch = false
90-
if !success(`git switch --orphan $outbranch`)
91-
@error "Cannot create new orphaned branch $outbranch."
92-
exit(1)
84+
if "deploy" in ARGS
85+
@warn "Deploying to GitHub" ARGS
86+
gitroot = normpath(joinpath(@__DIR__, ".."))
87+
run(`git pull`)
88+
outbranch = "gh-pages"
89+
has_outbranch = true
90+
if !success(`git checkout $outbranch`)
91+
has_outbranch = false
92+
if !success(`git switch --orphan $outbranch`)
93+
@error "Cannot create new orphaned branch $outbranch."
94+
exit(1)
95+
end
9396
end
94-
end
95-
for file in readdir(gitroot; join = true)
96-
endswith(file, ".git") && continue
97-
rm(file; force = true, recursive = true)
98-
end
99-
for file in readdir(outpath)
100-
cp(joinpath(outpath, file), joinpath(gitroot, file))
101-
end
102-
run(`git add .`)
103-
if success(`git commit -m 'Aggregate documentation'`)
104-
@info "Pushing updated documentation."
105-
if has_outbranch
106-
run(`git push`)
97+
for file in readdir(gitroot; join = true)
98+
endswith(file, ".git") && continue
99+
rm(file; force = true, recursive = true)
100+
end
101+
for file in readdir(outpath)
102+
cp(joinpath(outpath, file), joinpath(gitroot, file))
103+
end
104+
run(`git add .`)
105+
if success(`git commit -m 'Aggregate documentation'`)
106+
@info "Pushing updated documentation."
107+
if has_outbranch
108+
run(`git push`)
109+
else
110+
run(`git push -u origin $outbranch`)
111+
end
112+
run(`git checkout main`)
107113
else
108-
run(`git push -u origin $outbranch`)
114+
@info "No changes to aggregated documentation."
109115
end
110-
run(`git checkout main`)
111116
else
112-
@info "No changes to aggregated documentation."
117+
@info "Skipping deployment, 'deploy' not passed. Generated files in docs/out." ARGS
118+
cp(outpath, joinpath(@__DIR__, "out"), force = true)
113119
end

0 commit comments

Comments
 (0)