@@ -318,12 +318,35 @@ struct GitHubActions <: DeployConfig
318
318
github_repository:: String
319
319
github_event_name:: String
320
320
github_ref:: String
321
+ github_host:: String
322
+ github_api:: String
323
+ github_pages_url:: String
321
324
end
325
+
322
326
function GitHubActions ()
323
327
github_repository = get (ENV , " GITHUB_REPOSITORY" , " " ) # "JuliaDocs/Documenter.jl"
324
328
github_event_name = get (ENV , " GITHUB_EVENT_NAME" , " " ) # "push", "pull_request" or "cron" (?)
325
329
github_ref = get (ENV , " GITHUB_REF" , " " ) # "refs/heads/$(branchname)" for branch, "refs/tags/$(tagname)" for tags
326
- return GitHubActions (github_repository, github_event_name, github_ref)
330
+ github_api = get (ENV , " GITHUB_API_URL" , " " ) # https://api.github.com
331
+
332
+ # Compute GitHub Pages URL from repository
333
+ parts = split (github_repository, " /" )
334
+ github_pages_url = if length (parts) == 2
335
+ owner, repo = parts
336
+ " https://$(owner) .github.io/$(repo) /"
337
+ else
338
+ " "
339
+ end
340
+
341
+ return GitHubActions (github_repository, github_event_name, github_ref, " github.com" , github_api, github_pages_url)
342
+ end
343
+
344
+ function GitHubActions (host, pages_url)
345
+ github_repository = get (ENV , " GITHUB_REPOSITORY" , " " ) # "JuliaDocs/Documenter.jl"
346
+ github_event_name = get (ENV , " GITHUB_EVENT_NAME" , " " ) # "push", "pull_request" or "cron" (?)
347
+ github_ref = get (ENV , " GITHUB_REF" , " " ) # "refs/heads/$(branchname)" for branch, "refs/tags/$(tagname)" for tags
348
+ github_api = get (ENV , " GITHUB_API_URL" , " " ) # https://api.github.com
349
+ return GitHubActions (github_repository, github_event_name, github_ref, host, github_api, pages_url)
327
350
end
328
351
329
352
# Check criteria for deployment
@@ -393,7 +416,7 @@ function deploy_folder(
393
416
all_ok &= pr_ok
394
417
println (io, " - $(marker (pr_ok)) ENV[\" GITHUB_REF\" ] corresponds to a PR number" )
395
418
if pr_ok
396
- pr_origin_matches_repo = verify_github_pull_repository (cfg. github_repository , pr_number)
419
+ pr_origin_matches_repo = verify_github_pull_repository (cfg, pr_number)
397
420
all_ok &= pr_origin_matches_repo
398
421
println (io, " - $(marker (pr_origin_matches_repo)) PR originates from the same repository" )
399
422
end
452
475
453
476
authentication_method (:: GitHubActions ) = env_nonempty (" DOCUMENTER_KEY" ) ? SSH : HTTPS
454
477
function authenticated_repo_url (cfg:: GitHubActions )
455
- return " https://$(ENV [" GITHUB_ACTOR" ]) :$(ENV [" GITHUB_TOKEN" ]) @github.com /$(cfg. github_repository) .git"
478
+ return " https://$(ENV [" GITHUB_ACTOR" ]) :$(ENV [" GITHUB_TOKEN" ]) @$(cfg . github_host) /$(cfg. github_repository) .git"
456
479
end
457
480
458
481
function version_tag_strip_build (tag; tag_prefix = " " )
@@ -469,7 +492,7 @@ function version_tag_strip_build(tag; tag_prefix = "")
469
492
return " $s0$s1$s2$s3$s4 "
470
493
end
471
494
472
- function post_status (:: GitHubActions ; type, repo:: String , subfolder = nothing , kwargs... )
495
+ function post_status (cfg :: GitHubActions ; type, repo:: String , subfolder = nothing , kwargs... )
473
496
try # make this non-fatal and silent
474
497
# If we got this far it usually means everything is in
475
498
# order so no need to check everything again.
@@ -489,17 +512,18 @@ function post_status(::GitHubActions; type, repo::String, subfolder = nothing, k
489
512
sha = get (ENV , " GITHUB_SHA" , nothing )
490
513
end
491
514
sha === nothing && return
492
- return post_github_status (type, repo, sha, subfolder)
515
+ return post_github_status (cfg, type, repo, sha, subfolder)
493
516
catch
494
517
@debug " Failed to post status"
495
518
end
496
519
end
497
520
498
- function post_github_status (type:: S , deploydocs_repo:: S , sha:: S , subfolder = nothing ) where {S <: String }
521
+
522
+ function post_github_status (cfg:: GitHubActions , type:: S , deploydocs_repo:: S , sha:: S , subfolder = nothing ) where {S <: String }
499
523
try
500
524
Sys. which (" curl" ) === nothing && return
501
525
# # Extract owner and repository name
502
- m = match (r" ^github.com \ / (.+?)\/ (.+?)(.git)?$ " , deploydocs_repo)
526
+ m = match (Regex ( " ^(?:https?://)? $(cfg . github_host) \\ /(.+?)\\ /(.+?)(.git)?\$ " ) , deploydocs_repo)
503
527
m === nothing && return
504
528
owner = String (m. captures[1 ])
505
529
repo = String (m. captures[2 ])
@@ -517,9 +541,9 @@ function post_github_status(type::S, deploydocs_repo::S, sha::S, subfolder = not
517
541
json[" description" ] = " Documentation build in progress"
518
542
elseif type == " success"
519
543
json[" description" ] = " Documentation build succeeded"
520
- target_url = " https:// $(owner) .github.io/ $(repo) / "
521
- if subfolder != = nothing
522
- target_url *= " $(subfolder) /"
544
+ target_url = cfg . github_pages_url
545
+ if ! isempty (target_url) && subfolder != = nothing
546
+ target_url = rstrip (target_url, ' / ' ) * " / $(subfolder) /"
523
547
end
524
548
json[" target_url" ] = target_url
525
549
elseif type == " error"
@@ -530,7 +554,7 @@ function post_github_status(type::S, deploydocs_repo::S, sha::S, subfolder = not
530
554
error (" unsupported type: $type " )
531
555
end
532
556
push! (cmd. exec, " -d" , JSON. json (json))
533
- push! (cmd. exec, " https://api.github.com /repos/$(owner) /$(repo) /statuses/$(sha) " )
557
+ push! (cmd. exec, " $(cfg . github_api) /repos/$(owner) /$(repo) /statuses/$(sha) " )
534
558
# Run the command (silently)
535
559
io = IOBuffer ()
536
560
res = run (pipeline (cmd; stdout = io, stderr = devnull ))
@@ -541,7 +565,8 @@ function post_github_status(type::S, deploydocs_repo::S, sha::S, subfolder = not
541
565
return nothing
542
566
end
543
567
544
- function verify_github_pull_repository (repo, prnr)
568
+ function verify_github_pull_repository (cfg:: GitHubActions , prnr)
569
+ repo = cfg. github_repository
545
570
github_token = get (ENV , " GITHUB_TOKEN" , nothing )
546
571
if github_token === nothing
547
572
@warn " GITHUB_TOKEN is missing, unable to verify if PR comes from destination repository -- assuming it doesn't."
@@ -552,7 +577,7 @@ function verify_github_pull_repository(repo, prnr)
552
577
push! (cmd. exec, " -H" , " Authorization: token $(github_token) " )
553
578
push! (cmd. exec, " -H" , " User-Agent: Documenter.jl" )
554
579
push! (cmd. exec, " --fail" )
555
- push! (cmd. exec, " https://api.github.com /repos/$(repo) /pulls/$(prnr) " )
580
+ push! (cmd. exec, " $(cfg . github_api) /repos/$(repo) /pulls/$(prnr) " )
556
581
try
557
582
# Run the command (silently)
558
583
response = run_and_capture (cmd)
0 commit comments