Skip to content

Commit

Permalink
chore: guard Git commands in docs/make.jl against accidental deploy…
Browse files Browse the repository at this point in the history
…ment (#57)
  • Loading branch information
mortenpi authored Aug 16, 2023
1 parent e02d468 commit 5da2ba5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
run: |
git config user.name github-actions
git config user.email [email protected]
julia --project=. docs/make.jl
julia --project=. docs/make.jl deploy
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/Manifest.toml
/docs/out/
56 changes: 31 additions & 25 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,39 @@ MultiDocumenter.make(
rootpath = "/MultiDocumenter.jl/",
)

gitroot = normpath(joinpath(@__DIR__, ".."))
run(`git pull`)
outbranch = "gh-pages"
has_outbranch = true
if !success(`git checkout $outbranch`)
has_outbranch = false
if !success(`git switch --orphan $outbranch`)
@error "Cannot create new orphaned branch $outbranch."
exit(1)
if "deploy" in ARGS
@warn "Deploying to GitHub" ARGS
gitroot = normpath(joinpath(@__DIR__, ".."))
run(`git pull`)
outbranch = "gh-pages"
has_outbranch = true
if !success(`git checkout $outbranch`)
has_outbranch = false
if !success(`git switch --orphan $outbranch`)
@error "Cannot create new orphaned branch $outbranch."
exit(1)
end
end
end
for file in readdir(gitroot; join = true)
endswith(file, ".git") && continue
rm(file; force = true, recursive = true)
end
for file in readdir(outpath)
cp(joinpath(outpath, file), joinpath(gitroot, file))
end
run(`git add .`)
if success(`git commit -m 'Aggregate documentation'`)
@info "Pushing updated documentation."
if has_outbranch
run(`git push`)
for file in readdir(gitroot; join = true)
endswith(file, ".git") && continue
rm(file; force = true, recursive = true)
end
for file in readdir(outpath)
cp(joinpath(outpath, file), joinpath(gitroot, file))
end
run(`git add .`)
if success(`git commit -m 'Aggregate documentation'`)
@info "Pushing updated documentation."
if has_outbranch
run(`git push`)
else
run(`git push -u origin $outbranch`)
end
run(`git checkout main`)
else
run(`git push -u origin $outbranch`)
@info "No changes to aggregated documentation."
end
run(`git checkout main`)
else
@info "No changes to aggregated documentation."
@info "Skipping deployment, 'deploy' not passed. Generated files in docs/out." ARGS
cp(outpath, joinpath(@__DIR__, "out"), force = true)
end

0 comments on commit 5da2ba5

Please sign in to comment.