-
Notifications
You must be signed in to change notification settings - Fork 541
Add GitHub action that deploys GitHub Pages with redirects to package repositories #120760
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
da9ec91
Add workflow to generate redirects page
jkrumbiegel f5bb033
use version '1'
jkrumbiegel bf5d9b3
add permissions
jkrumbiegel 6bf36e1
Merge branch 'JuliaRegistries:master' into master
jkrumbiegel ec1cbf5
implement known host mechanism
jkrumbiegel 888a77d
bit nicer to look at
jkrumbiegel 2d10b2a
end with newline
jkrumbiegel 296cd65
clean up yml comments
jkrumbiegel c0311fd
apply persist-credentials review comment
jkrumbiegel 78da909
import instead of using
jkrumbiegel 33644e8
add timeout to job
jkrumbiegel 0e76232
add rel nofollow to links
jkrumbiegel 7de5886
add full commit shas for actions used
jkrumbiegel b10bf7d
change url to be more clear about redirection
jkrumbiegel ac29c04
Merge branch 'master' of github.com:jkrumbiegel/General
jkrumbiegel d7151fb
schedule workflow every six hours
jkrumbiegel fea8907
explanatory comments
jkrumbiegel 43601e6
more Julian purple color
jkrumbiegel 64da39e
make title conditional on redirect
jkrumbiegel cde5390
replace cron with trigger on push to master with Package.toml changes
jkrumbiegel fe25388
Merge branch 'JuliaRegistries:master' into master
jkrumbiegel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| name: Generate and Deploy Redirects | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: | ||
| - master | ||
| paths: | ||
| - '**/Package.toml' # avoids redeploys on version or compat changes | ||
|
|
||
| jobs: | ||
| build-and-deploy: | ||
jkrumbiegel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Grant GITHUB_TOKEN the permissions required to make a Pages deployment | ||
| permissions: | ||
| pages: write # to deploy to Pages | ||
| id-token: write # to verify the deployment originates from an appropriate source | ||
|
|
||
| runs-on: ubuntu-latest | ||
|
|
||
| timeout-minutes: 15 | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Install Julia | ||
| uses: julia-actions/setup-julia@5c9647d97b78a5debe5164e9eec09d653d29bd71 # v2.6.1 | ||
| with: | ||
| version: '1' | ||
|
|
||
| - name: Run the "generate_redirects.jl" Julia script | ||
| run: julia generate_redirects.jl | ||
|
|
||
| - name: Upload static files as artifact | ||
| uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1 | ||
| with: | ||
| path: webroot/ | ||
|
|
||
| - name: Deploy to GitHub Pages | ||
| uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5 | ||
DilumAluthge marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import TOML | ||
|
|
||
| function get_repo(path::String) | ||
| return TOML.parsefile(joinpath(path, "Package.toml"))["repo"] | ||
| end | ||
|
|
||
| function get_packages_info() | ||
| reg = TOML.parsefile("Registry.toml") | ||
| return [(; name = dict["name"], path = dict["path"]) for (uuid, dict) in reg["packages"]] | ||
| end | ||
|
|
||
| function get_host(repo) | ||
| m = match(r"^https://([a-z\.]+)", repo) | ||
| if m === nothing | ||
| error("Repo url $(repr(repo)) did not match expected format") | ||
| end | ||
| return m[1] | ||
| end | ||
|
|
||
| # only for these hosts will we redirect automatically, for all others the user needs to click the link | ||
| function known_host(host) | ||
| host in ("github.com", "gitlab.com", "codeberg.org") | ||
jkrumbiegel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| function package_path(args...) | ||
| # results in URLs like juliaregistries.github.io/General/packages/redirect_to_repo/SomePackage | ||
| joinpath("webroot", "packages", "redirect_to_repo", args...) | ||
jkrumbiegel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
|
|
||
| function create_redirect_page(; name, path) | ||
| repo = get_repo(path) | ||
| host = get_host(repo) | ||
| should_redirect = known_host(host) | ||
| meta_redirection = should_redirect ? """<meta http-equiv="refresh" content="0; url=$repo">""" : "" | ||
| message = if should_redirect | ||
| """Redirecting to $name...<br><br>Click the link below if you are not redirected automatically to the registered repository for the Julia package $name<br><br><a href="$repo" rel="nofollow">$repo</a>""" | ||
| else | ||
| """Click the link below to go to the registered repository for the Julia package $name<br><br><a href="$repo" rel="nofollow">$repo</a>""" | ||
| end | ||
| title = if should_redirect | ||
| "Redirecting to $name..." | ||
| else | ||
| "Confirm redirect to $name" | ||
| end | ||
|
|
||
| open(package_path(name * ".html"), "w") do io | ||
| write(io, """ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>$title</title> | ||
| $meta_redirection | ||
| <style> | ||
| body { | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| min-height: 100vh; | ||
| margin: 0; | ||
| font-family: Arial, sans-serif; | ||
| background-color: #f9f9f9; | ||
| } | ||
| .centered-div { | ||
| border: 3px solid #9558B2; | ||
| background-color: #f8e9ff; | ||
| border-radius: 10px; | ||
| padding: 20px; | ||
| margin: 20px; | ||
| text-align: center; | ||
| color: #333; | ||
| max-width: 30em; | ||
| word-wrap: break-word; | ||
| } | ||
| .centered-div a { | ||
| color: #9558B2; | ||
| font-weight: bold; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <div class="centered-div"> | ||
| <p>$message</p> | ||
| </div> | ||
| </body> | ||
| </html> | ||
| """) | ||
| end | ||
| end | ||
|
|
||
| function main() | ||
| mkpath(package_path()) | ||
| packages_info = get_packages_info() | ||
| for (; name, path) in packages_info | ||
| create_redirect_page(; name, path) | ||
| end | ||
| end | ||
|
|
||
| main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.