-
-
Notifications
You must be signed in to change notification settings - Fork 250
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
Version selection: add AWS redirect configs for latest docs version #561
Merged
+101
−19
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c52480b
Version selection: add AWS redirect configs for latest docs version
oprypin bed4540
Use create and delete triggers
straight-shoota ae44785
Untangle versions.json and website configuration
straight-shoota 946d495
Revert unnecessary changes
straight-shoota 552ff45
Reintroduce some refactors
oprypin 20114eb
Change to a better-targeted 404 redirect
oprypin b353013
Make the config similar to api/ config, drop obsolete redirects
oprypin 12dd02b
Add ability to run workflow manually
oprypin 09589e8
Merge branch 'master' into aws
straight-shoota 9dd1cd3
Remove delete trigger
straight-shoota 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 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
This file contains 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,29 @@ | ||
name: Deploy config | ||
on: | ||
- create | ||
- delete | ||
|
||
jobs: | ||
build: | ||
name: Deploy config | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Download source | ||
uses: actions/checkout@v2 | ||
- name: Build versions files | ||
run: | | ||
scripts/docs-versions.sh origin | ||
grep '' versions.json aws-config.json # Display the files | ||
- name: Configure AWS Credentials | ||
if: github.repository == 'crystal-lang/crystal-book' | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: us-east-1 | ||
- name: Deploy versions.json | ||
if: github.repository == 'crystal-lang/crystal-book' | ||
run: aws s3 cp versions.json 's3://crystal-book/reference/versions.json' | ||
- name: Deploy website configuration | ||
if: github.repository == 'crystal-lang/crystal-book' | ||
run: aws s3api put-bucket-website --bucket 'crystal-book' --website-configuration 'file://aws-config.json' |
This file contains 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,77 @@ | ||
{ | ||
"IndexDocument": { | ||
"Suffix": "index.html" | ||
}, | ||
"ErrorDocument": { | ||
"Key": "reference/404.html" | ||
}, | ||
"RoutingRules": [ | ||
{ | ||
"Condition": { | ||
"KeyPrefixEquals": "reference/installation" | ||
}, | ||
"Redirect": { | ||
"HostName": "crystal-lang.org", | ||
"HttpRedirectCode": "301", | ||
"Protocol": "https", | ||
"ReplaceKeyPrefixWith": "install" | ||
} | ||
}, | ||
{ | ||
"Condition": { | ||
"KeyPrefixEquals": "reference/overview/hello_world.html" | ||
oprypin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
"Redirect": { | ||
"HostName": "crystal-lang.org", | ||
"HttpRedirectCode": "301", | ||
"Protocol": "https", | ||
"ReplaceKeyPrefixWith": "reference/getting_started" | ||
} | ||
}, | ||
{ | ||
"Condition": { | ||
"KeyPrefixEquals": "reference/overview" | ||
}, | ||
"Redirect": { | ||
"HostName": "crystal-lang.org", | ||
"HttpRedirectCode": "301", | ||
"Protocol": "https", | ||
"ReplaceKeyPrefixWith": "reference/getting_started" | ||
} | ||
}, | ||
{ | ||
"Condition": { | ||
"KeyPrefixEquals": "reference/${LATEST_VERSION}/${LATEST_VERSION}/" | ||
}, | ||
"Redirect": { | ||
"HostName": "crystal-lang.org", | ||
"HttpRedirectCode": "301", | ||
"Protocol": "https", | ||
"ReplaceKeyWith": "404" | ||
} | ||
}, | ||
oprypin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
"Condition": { | ||
"KeyPrefixEquals": "reference/latest" | ||
}, | ||
"Redirect": { | ||
"HostName": "crystal-lang.org", | ||
"HttpRedirectCode": "302", | ||
"Protocol": "https", | ||
"ReplaceKeyPrefixWith": "reference/${LATEST_VERSION}/" | ||
} | ||
}, | ||
{ | ||
"Condition": { | ||
"HttpErrorCodeReturnedEquals": "404", | ||
"KeyPrefixEquals": "reference/" | ||
}, | ||
"Redirect": { | ||
"HostName": "crystal-lang.org", | ||
"HttpRedirectCode": "301", | ||
"Protocol": "https", | ||
"ReplaceKeyPrefixWith": "reference/${LATEST_VERSION}/" | ||
} | ||
} | ||
] | ||
} |
This file contains 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 |
---|---|---|
@@ -1,12 +1,19 @@ | ||
#!/usr/bin/env sh | ||
set -e | ||
#!/bin/bash | ||
set -eu | ||
|
||
printf '[' | ||
latest='"latest"' | ||
for ver in $(git ls-remote --heads "${1:-.}" | grep -P -o '(?<=refs/heads/)[0-9][0-9.]+' | sort -V -r); do | ||
printf '{"version": "%s", "title": "%s", "aliases": [%s]}, ' "$ver" "$ver" "$latest" | ||
latest='' | ||
done | ||
printf '{"version": "master", "title": "nightly", "aliases": []}' | ||
printf ']' | ||
test -z "$latest" # Check that we wrote at least one version | ||
branches=( $(git ls-remote --heads "${1:-.}" | grep -P -o '(?<=refs/heads/)[0-9][0-9.]+' | sort -V -r) ) | ||
latest_version="${branches[0]}" | ||
|
||
{ | ||
printf '[\n' | ||
latest='"latest"' | ||
for ver in "${branches[@]}"; do | ||
printf '{"version": "%s", "title": "%s", "aliases": [%s]},\n' "$ver" "$ver" "$latest" | ||
latest='' | ||
done | ||
printf '{"version": "master", "title": "nightly", "aliases": []}\n' | ||
printf ']\n' | ||
test -z "$latest" # Check that we wrote at least one version | ||
} > versions.json | ||
|
||
sed 's/\${LATEST_VERSION}/'"${latest_version}"'/g' "$(dirname "$0")/aws-config.json" > aws-config.json |
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.
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.
Hm is it possible to limit the range of branches that trigger this?
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.
Unfortunately, no. These events are global and unfiltered.
I suppose we could filter for version branches in the steps. I think
${ github.event.ref }
should hold the name of the branch (or tag) that was created or deleted.Per https://docs.github.com/en/actions/learn-github-actions/contexts and https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#create
Maybe it would also be a viable alternative to not automate this in this repo, but integrate the steps with the release workflow over in https://github.com/crystal-lang/distribution-scripts (see https://github.com/crystal-lang/distribution-scripts/blob/master/processes/crystal-release.md)
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.
The addition of a new branch (like when we release 1.3) needs to be triggered somehow. At that point we can also update the versions and website configuration.
Deletion is probably not even worth automating. That should never happen and if it does, it's because of manual interference.
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.
Thinking about this again, I think we should have all the configuration-level changes manually triggered (maybe it can be automatically triggered as part of the release process at some point, but that's not super important).
The workflow could go like this:
versions.json
https://github.com/crystal-lang/distribution-scripts/ seems like a good place for that because we have everything else already collected there.
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 see much advantage to making it manually triggered (The creation of a branch in this repo is already a manual action BTW), but doesn't matter much to me. I agree with your idea.
This part is not critical for the moment, but clearly the way to proceed is to make a PR on distribution-scripts with these same scripts but slightly adapted. I am personally not interested in contributing to distribution-scripts but let me know if you think it's best that I do that.
And out of this PR only the change to .github/workflows/deploy-book.yml needs to be kept. But that should be applied after the other side (distribution-scripts) is finalized.