-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version selection: add AWS redirect configs for latest docs version
- Loading branch information
Showing
3 changed files
with
78 additions
and
19 deletions.
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,27 @@ | ||
name: Deploy config | ||
on: | ||
push: | ||
branches: | ||
- '[0-9]+.[0-9]+' | ||
|
||
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 # 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 files | ||
if: github.repository == 'crystal-lang/crystal-book' | ||
run: aws s3 sync . s3://crystal-book/reference --exclude '*' --include 'versions.json' --include '.aws-config' |
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,50 @@ | ||
#!/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_branch="${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 | ||
|
||
cat <<EOF > .aws-config | ||
{ | ||
"IndexDocument": { | ||
"Suffix": "index.html" | ||
}, | ||
"RoutingRules": [ | ||
{ | ||
"Condition": { | ||
"KeyPrefixEquals": "reference/latest/" | ||
}, | ||
"Redirect": { | ||
"HttpRedirectCode": "302", | ||
"ReplaceKeyPrefixWith": "reference/${latest_branch}/", | ||
"Protocol": "https", | ||
"HostName": "crystal-lang.org" | ||
} | ||
}, | ||
{ | ||
"Condition": { | ||
"KeyPrefixEquals": "reference/", | ||
"HttpErrorCodeReturnedEquals": "404" | ||
}, | ||
"Redirect": { | ||
"HttpRedirectCode": "301", | ||
"ReplaceKeyPrefixWith": "reference/latest/", | ||
"Protocol": "https", | ||
"HostName": "crystal-lang.org" | ||
} | ||
} | ||
] | ||
} | ||
EOF |