xref: /expo/docs/deploy.sh (revision eeffdb10)
1#!/usr/bin/env bash
2
3set -euo pipefail
4
5scriptdir=$(dirname "${BASH_SOURCE[0]}")
6bucket="docs.expo.io"
7target="${1-$scriptdir/out}"
8
9if [ ! -d "$target" ]; then
10  echo "target $target not found"
11  exit 1
12fi
13
14# To keep the previous website up and running, we deploy it using these steps.
15#   1.  Sync JS/assets dependencies in \`_next/**\` and \`static/**\` folder
16#      > Uploads the new generated JS and asset files (stored in hashed folders to avoid collision with older deployments)
17#   2. Overwrite HTML dependents, not located in \`_next/**\` or \`static/**\` folder
18#      > Force overwrite of all HTML files to make sure we use the latest one
19#   3. Sync assets and clean up outdated files from previous deployments
20#   4. Add custom redirects
21
22echo "::group::[1/4] Sync JS/assets dependencies in \`_next/**\` and \`static/**\` folder"
23aws s3 sync \
24  --no-progress \
25  --exclude "*" \
26  --include "_next/**" \
27  --include "static/**" \
28  "$target" \
29  "s3://${bucket}"
30echo "::endgroup::"
31
32# Due to a bug with `aws s3 sync` we need to copy everything first instead of syncing
33# see: https://github.com/aws/aws-cli/issues/3273#issuecomment-643436849
34echo "::group::[2/4] Overwrite HTML dependents, not located in \`_next/**\` or \`static/**\` folder"
35aws s3 cp \
36  --no-progress \
37  --recursive \
38  --exclude "_next/**" \
39  --exclude "static/**" \
40  "$target" \
41  "s3://${bucket}"
42echo "::endgroup::"
43
44echo "::group::[3/4] Sync assets and clean up outdated files from previous deployments"
45aws s3 sync \
46  --no-progress \
47  --delete \
48  "$target" \
49  "s3://${bucket}"
50echo "::endgroup::"
51
52declare -A redirects # associative array variable
53
54# usage:
55# redicts[requests/for/this/path]=are/redirected/to/this/one
56
57# Temporarily create a redirect for a page that Home links to
58redirects[versions/latest/introduction/installation.html]=versions/latest/introduction/installation/
59# useful link on twitter
60redirects[versions/latest/guides/app-stores.html]=versions/latest/distribution/app-stores/
61# Xdl caches
62redirects[versions/latest/guides/offline-support.html]=versions/latest/guides/offline-support/
63# xdl convert comment
64redirects[versions/latest/sdk/index.html]=versions/latest/sdk/overview/
65# upgrading expo -> upgrading sdk walkthrough
66redirects[versions/latest/workflow/upgrading-expo]=versions/latest/workflow/upgrading-expo-sdk-walkthrough/
67# rename
68redirects[versions/latest/sdk/haptic/index.html]=versions/latest/sdk/haptics/
69# duplicate docs file, consolidate into one page
70redirects[versions/latest/sdk/introduction/index.html]=versions/latest/sdk/overview/
71# project-lifecycle is now covered by managed-vs-bare
72redirects[versions/latest/introduction/project-lifecycle/]=versions/latest/introduction/managed-vs-bare/
73# exp-cli is now expo-cli
74redirects[versions/latest/guides/exp-cli.html]=versions/latest/workflow/expo-cli/
75redirects[versions/latest/guides/exp-cli]=versions/latest/workflow/expo-cli/
76
77echo "::group::[4/4] Add custom redirects"
78for i in "${!redirects[@]}" # iterate over keys
79do
80  aws s3 cp \
81    --no-progress \
82    --metadata-directive REPLACE \
83    --website-redirect "/${redirects[$i]}" \
84    "$target/404.html" \
85    "s3://${bucket}/${i}"
86done
87echo "::endgroup::"
88