xref: /expo/docs/deploy.sh (revision 02fdff46)
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 Next.js static assets in \`_next/**\` folder
16#      > Uploads the new generated JS and asset files (stored in hashed folders to avoid collision with older deployments)
17#   2.  Sync assets in \`static/**\` folder
18#   3. Overwrite HTML dependents, not located in \`_next/**\` or \`static/**\` folder
19#      > Force overwrite of all HTML files to make sure we use the latest one
20#   4. Sync assets and clean up outdated files from previous deployments
21#   5. Add custom redirects
22
23echo "::group::[1/5] Sync Next.js static assets in \`_next/**\` folder"
24aws s3 sync \
25  --no-progress \
26  --exclude "*" \
27  --include "_next/**" \
28  --cache-control "public, max-age=31536000, immutable" \
29  "$target" \
30  "s3://${bucket}"
31echo "::endgroup::"
32
33echo "::group::[2/5] Sync assets in \`static/**\` folder"
34aws s3 sync \
35  --no-progress \
36  --exclude "*" \
37  --include "static/**" \
38  --cache-control "public, max-age=3600" \
39  "$target" \
40  "s3://${bucket}"
41echo "::endgroup::"
42
43# Due to a bug with `aws s3 sync` we need to copy everything first instead of syncing
44# see: https://github.com/aws/aws-cli/issues/3273#issuecomment-643436849
45echo "::group::[3/5] Overwrite HTML dependents, not located in \`_next/**\` or \`static/**\` folder"
46aws s3 cp \
47  --no-progress \
48  --recursive \
49  --exclude "_next/**" \
50  --exclude "static/**" \
51  "$target" \
52  "s3://${bucket}"
53echo "::endgroup::"
54
55echo "::group::[4/5] Sync assets and clean up outdated files from previous deployments"
56aws s3 sync \
57  --no-progress \
58  --delete \
59  "$target" \
60  "s3://${bucket}"
61echo "::endgroup::"
62
63declare -A redirects # associative array variable
64
65# usage:
66# redicts[requests/for/this/path]=are/redirected/to/this/one
67
68# Temporarily create a redirect for a page that Home links to
69redirects[versions/latest/introduction/installation.html]=versions/latest/introduction/installation/
70# useful link on twitter
71redirects[versions/latest/guides/app-stores.html]=versions/latest/distribution/app-stores/
72# Xdl caches
73redirects[versions/latest/guides/offline-support.html]=versions/latest/guides/offline-support/
74# xdl convert comment
75redirects[versions/latest/sdk/index.html]=versions/latest/sdk/overview/
76# upgrading expo -> upgrading sdk walkthrough
77redirects[versions/latest/workflow/upgrading-expo]=versions/latest/workflow/upgrading-expo-sdk-walkthrough/
78# rename
79redirects[versions/latest/sdk/haptic/index.html]=versions/latest/sdk/haptics/
80# duplicate docs file, consolidate into one page
81redirects[versions/latest/sdk/introduction/index.html]=versions/latest/sdk/overview/
82# project-lifecycle is now covered by managed-vs-bare
83redirects[versions/latest/introduction/project-lifecycle/]=versions/latest/introduction/managed-vs-bare/
84# exp-cli is now expo-cli
85redirects[versions/latest/guides/exp-cli.html]=versions/latest/workflow/expo-cli/
86redirects[versions/latest/guides/exp-cli]=versions/latest/workflow/expo-cli/
87
88echo "::group::[5/5] Add custom redirects"
89for i in "${!redirects[@]}" # iterate over keys
90do
91  aws s3 cp \
92    --no-progress \
93    --metadata-directive REPLACE \
94    --website-redirect "/${redirects[$i]}" \
95    "$target/404.html" \
96    "s3://${bucket}/${i}"
97done
98echo "::endgroup::"
99