xref: /expo/docs/deploy.sh (revision e7a5287c)
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/6] 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/6] 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/6] 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/6] 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# Migrated FAQ pages
88redirects[faq/image-background]=ui-programming/image-background/
89redirects[faq/react-native-styling-buttons]=ui-programming/react-native-styling-buttons/
90redirects[faq/react-native-version-mismatch]=troubleshooting/react-native-version-mismatch/
91redirects[faq/clear-cache-windows]=troubleshooting/clear-cache-windows/
92redirects[faq/clear-cache-macos-linux]=troubleshooting/clear-cache-macos-linux/
93redirects[faq/application-has-not-been-registered]=troubleshooting/application-has-not-been-registered/
94
95echo "::group::[5/6] Add custom redirects"
96for i in "${!redirects[@]}" # iterate over keys
97do
98  aws s3 cp \
99    --no-progress \
100    --metadata-directive REPLACE \
101    --website-redirect "/${redirects[$i]}" \
102    "$target/404.html" \
103    "s3://${bucket}/${i}"
104
105  # Also add redirects for paths without `.html` or `/`
106  # S3 translates URLs with trailing slashes to `path/` -> `path/index.html`
107  if [[ $i != *".html" ]] && [[ $i != *"/" ]]; then
108    aws s3 cp \
109      --no-progress \
110      --metadata-directive REPLACE \
111      --website-redirect "/${redirects[$i]}" \
112      "$target/404.html" \
113      "s3://${bucket}/${i}/index.html"
114  fi
115done
116echo "::endgroup::"
117
118echo "::group::[6/6] Notify Google of sitemap changes"
119curl -m 15 http://www.google.com/ping\?sitemap\=https%3A%2F%2Fdocs.expo.io%2Fsitemap.xml
120echo "\n::endgroup::"
121