-
Notifications
You must be signed in to change notification settings - Fork 501
Support self-hosted github installations #2755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
ef38eb7
407d4b9
de1721f
438901a
be69eef
bc84016
5fb85ef
285c286
a1fa597
c992c64
ed5eeba
77ab55a
dc9337f
0e268b4
47fecbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -318,12 +318,35 @@ struct GitHubActions <: DeployConfig | |||||||||||||||||||||||||||||||||||||||||||||
| github_repository::String | ||||||||||||||||||||||||||||||||||||||||||||||
| github_event_name::String | ||||||||||||||||||||||||||||||||||||||||||||||
| github_ref::String | ||||||||||||||||||||||||||||||||||||||||||||||
| github_host::String | ||||||||||||||||||||||||||||||||||||||||||||||
| github_api::String | ||||||||||||||||||||||||||||||||||||||||||||||
| github_pages_url::String | ||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| function GitHubActions() | ||||||||||||||||||||||||||||||||||||||||||||||
| github_repository = get(ENV, "GITHUB_REPOSITORY", "") # "JuliaDocs/Documenter.jl" | ||||||||||||||||||||||||||||||||||||||||||||||
| github_event_name = get(ENV, "GITHUB_EVENT_NAME", "") # "push", "pull_request" or "cron" (?) | ||||||||||||||||||||||||||||||||||||||||||||||
| github_ref = get(ENV, "GITHUB_REF", "") # "refs/heads/$(branchname)" for branch, "refs/tags/$(tagname)" for tags | ||||||||||||||||||||||||||||||||||||||||||||||
| return GitHubActions(github_repository, github_event_name, github_ref) | ||||||||||||||||||||||||||||||||||||||||||||||
| github_api = get(ENV, "GITHUB_API_URL", "") # https://api.github.com | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| # Compute GitHub Pages URL from repository | ||||||||||||||||||||||||||||||||||||||||||||||
| parts = split(github_repository, "/") | ||||||||||||||||||||||||||||||||||||||||||||||
| github_pages_url = if length(parts) == 2 | ||||||||||||||||||||||||||||||||||||||||||||||
| owner, repo = parts | ||||||||||||||||||||||||||||||||||||||||||||||
| "https://$(owner).github.io/$(repo)/" | ||||||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course you are just moving this around, and that's already a good step; so what I say below is not a change request, but a general thought (perhaps we should record it it into an issue) Instead of hardcoding the pages URL like that (which won't if e.g. a custom domain name is used, as e.g. $ gh api repos/JuliaDocs/Documenter.jl --jq '.homepage'
https://documenter.juliadocs.orgBut of course one also do that without, using just the Obviously in Julia we'd use the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be great, however I can't find any public API that will tell me where github pages are located. |
||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||
| "" | ||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| return GitHubActions(github_repository, github_event_name, github_ref, "github.com", github_api, github_pages_url) | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
| github_api = get(ENV, "GITHUB_API_URL", "") # https://api.github.com | |
| # Compute GitHub Pages URL from repository | |
| parts = split(github_repository, "/") | |
| github_pages_url = if length(parts) == 2 | |
| owner, repo = parts | |
| "https://$(owner).github.io/$(repo)/" | |
| else | |
| "" | |
| end | |
| return GitHubActions(github_repository, github_event_name, github_ref, "github.com", github_api, github_pages_url) | |
| # Compute GitHub Pages URL from repository | |
| parts = split(github_repository, "/") | |
| github_pages_url = if length(parts) == 2 | |
| owner, repo = parts | |
| "https://$(owner).github.io/$(repo)/" | |
| else | |
| "" | |
| end | |
| return GitHubActions(github_repository, github_event_name, github_ref, "github.com", "https://api.github.com", github_pages_url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is GITHUB_API_URL something that is configurable for a self-hosted instance, or can we assume it's api.$(host)?
There's also GITHUB_SERVER_URL, which could potentially be used for determining host automatically? Or would that not be reliable and/or two automagical?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can assume anything about it, I don't know exactly if it is configurable but I would expect that it is as some orgs have strict rules about domain names
I need to check GITHUB_SERVER_URL , for some reason I haven't used that, don't know if it is because we don't have it or because I've missed it
if something like that exists I would prefer to used it indeed instead of specifying it manually
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that GITHUB_API_URL is mentioned in the GitHub manual as a variable they set in GitHub Action workflows.
And in the corresponding enterprise docs at https://docs.github.com/en/[email protected]/actions/reference/workflows-and-actions/variables the example value given is http(s)://HOSTNAME/api/v3 -- so no, we can't just assume it is api.$(host) (I assume that's the URL one gest if one enables "subdomain isolation")
mortenpi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,6 +102,9 @@ function repofile(remote::Remote, ref, filename, linerange = nothing) | |
| return fileurl(remote, ref, filename, isnothing(linerange) ? nothing : Int(first(linerange)):Int(last(linerange))) | ||
| end | ||
|
|
||
|
|
||
| const GITHUB_HOST = "github.com" | ||
|
|
||
| """ | ||
| GitHub(user :: AbstractString, repo :: AbstractString) | ||
| GitHub(remote :: AbstractString) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took the liberty of removing |
||
|
|
@@ -121,12 +124,15 @@ a slash (e.g. `JuliaDocs/Documenter.jl`). | |
| struct GitHub <: Remote | ||
| user::String | ||
| repo::String | ||
| host::String | ||
|
|
||
| GitHub(user::AbstractString, repo::AbstractString, host::AbstractString = GITHUB_HOST) = new(user, repo, host) | ||
| end | ||
| function GitHub(remote::AbstractString) | ||
| function GitHub(remote::AbstractString; host::AbstractString = GITHUB_HOST) | ||
| user, repo = split(remote, '/') | ||
| return GitHub(user, repo) | ||
| return GitHub(user, repo, host) | ||
| end | ||
| repourl(remote::GitHub) = "https://github.com/$(remote.user)/$(remote.repo)" | ||
| repourl(remote::GitHub) = "https://$(remote.host)/$(remote.user)/$(remote.repo)" | ||
| function fileurl(remote::GitHub, ref::AbstractString, filename::AbstractString, linerange) | ||
| url = "$(repourl(remote))/blob/$(ref)/$(filename)" | ||
| isnothing(linerange) && return url | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -493,6 +493,28 @@ end | |
| ) | ||
| @test !d.all_ok | ||
| end | ||
| # Self-hosted GitHub installation | ||
| # Regular tag build with GITHUB_TOKEN | ||
| withenv( | ||
| "GITHUB_EVENT_NAME" => "push", | ||
| "GITHUB_REPOSITORY" => "JuliaDocs/Documenter.jl", | ||
| "GITHUB_REF" => "refs/tags/v1.2.3", | ||
| "GITHUB_ACTOR" => "github-actions", | ||
| "GITHUB_TOKEN" => "SGVsbG8sIHdvcmxkLg==", | ||
| "DOCUMENTER_KEY" => nothing, | ||
| ) do | ||
| cfg = Documenter.GitHubActions("github.selfhosted", "pages.selfhosted/something/JuliaDocs/Documenter.jl") | ||
| d = Documenter.deploy_folder( | ||
| cfg; repo = "github.selfhosted/JuliaDocs/Documenter.jl.git", | ||
| devbranch = "master", devurl = "dev", push_preview = true | ||
| ) | ||
| @test d.all_ok | ||
| @test d.subfolder == "v1.2.3" | ||
| @test d.repo == "github.selfhosted/JuliaDocs/Documenter.jl.git" | ||
| @test d.branch == "gh-pages" | ||
| @test Documenter.authentication_method(cfg) === Documenter.HTTPS | ||
| @test Documenter.authenticated_repo_url(cfg) === "https://github-actions:[email protected]/JuliaDocs/Documenter.jl.git" | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
@@ -1396,7 +1418,7 @@ end | |
| "CI" => "woodpecker", | ||
| "GITHUB_REPOSITORY" => nothing | ||
| ) do | ||
| @test_throws KeyError cfg = Documenter.auto_detect_deploy_system() | ||
| @test_throws KeyError cfg = Documenter.auto_detect_deploy_system() | ||
| end | ||
| # Drone compatibility ends post-1.0.0 | ||
| withenv( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.