xref: /expo/docs/deploy.sh (revision 104f0ac7)
1#!/usr/bin/env bash
2
3set -euo pipefail
4
5scriptdir=$(dirname "${BASH_SOURCE[0]}")
6bucket="docs.expo.dev"
7target="${1-$scriptdir/out}"
8
9if [ ! -d "$target" ]; then
10  echo "target $target not found"
11  exit 1
12fi
13
14
15# To keep the previous website up and running, we deploy it using these steps.
16#   1.  Sync Next.js static assets in \`_next/**\` folder
17#      > Uploads the new generated JS and asset files (stored in hashed folders to avoid collision with older deployments)
18#   2.  Sync assets in \`static/**\` folder
19#   3. Overwrite HTML dependents, not located in \`_next/**\` or \`static/**\` folder
20#      > Force overwrite of all HTML files to make sure we use the latest one
21#   4. Sync assets and clean up outdated files from previous deployments
22#   5. Add custom redirects
23#   6. Notify Google of sitemap changes for SEO
24
25echo "::group::[1/6] Sync Next.js static assets in \`_next/**\` folder"
26aws s3 sync \
27  --no-progress \
28  --exclude "*" \
29  --include "_next/**" \
30  --cache-control "public, max-age=31536000, immutable" \
31  "$target" \
32  "s3://${bucket}"
33echo "::endgroup::"
34
35echo "::group::[2/6] Sync assets in \`static/**\` folder"
36aws s3 sync \
37  --no-progress \
38  --exclude "*" \
39  --include "static/**" \
40  --cache-control "public, max-age=3600" \
41  "$target" \
42  "s3://${bucket}"
43echo "::endgroup::"
44
45# Due to a bug with `aws s3 sync` we need to copy everything first instead of syncing
46# see: https://github.com/aws/aws-cli/issues/3273#issuecomment-643436849
47echo "::group::[3/6] Overwrite HTML dependents, not located in \`_next/**\` or \`static/**\` folder"
48aws s3 cp \
49  --no-progress \
50  --recursive \
51  --exclude "_next/**" \
52  --exclude "static/**" \
53  "$target" \
54  "s3://${bucket}"
55echo "::endgroup::"
56
57echo "::group::[4/6] Sync assets and clean up outdated files from previous deployments"
58aws s3 sync \
59  --no-progress \
60  --delete \
61  "$target" \
62  "s3://${bucket}"
63echo "::endgroup::"
64
65declare -A redirects # associative array variable
66
67# usage:
68# redicts[requests/for/this/path]=are/redirected/to/this/one
69
70# Temporarily create a redirect for a page that Home links to
71redirects[versions/latest/introduction/installation.html]=versions/latest/introduction/installation/
72# useful link on twitter
73redirects[versions/latest/guides/app-stores.html]=versions/latest/distribution/app-stores/
74# Xdl caches
75redirects[versions/latest/guides/offline-support.html]=versions/latest/guides/offline-support/
76# xdl convert comment
77redirects[versions/latest/sdk/index.html]=versions/latest/sdk/overview/
78# upgrading expo -> upgrading sdk walkthrough
79redirects[versions/latest/workflow/upgrading-expo]=versions/latest/workflow/upgrading-expo-sdk-walkthrough/
80# rename
81redirects[versions/latest/sdk/haptic/index.html]=versions/latest/sdk/haptics/
82redirects[development/eas-build]=development/build
83# duplicate docs file, consolidate into one page
84redirects[versions/latest/sdk/introduction/index.html]=versions/latest/sdk/overview/
85# project-lifecycle is now covered by managed-vs-bare
86redirects[versions/latest/introduction/project-lifecycle/]=versions/latest/introduction/managed-vs-bare/
87# exp-cli is now expo-cli
88redirects[versions/latest/guides/exp-cli.html]=versions/latest/workflow/expo-cli/
89redirects[versions/latest/guides/exp-cli]=versions/latest/workflow/expo-cli/
90# Migrated FAQ pages
91redirects[faq/image-background]=ui-programming/image-background/
92redirects[faq/react-native-styling-buttons]=ui-programming/react-native-styling-buttons/
93redirects[faq/react-native-version-mismatch]=troubleshooting/react-native-version-mismatch/
94redirects[faq/clear-cache-windows]=troubleshooting/clear-cache-windows/
95redirects[faq/clear-cache-macos-linux]=troubleshooting/clear-cache-macos-linux/
96redirects[faq/application-has-not-been-registered]=troubleshooting/application-has-not-been-registered/
97redirects[distribution/building-standalone-apps]=classic/building-standalone-apps/
98redirects[build-reference/build-webhook]=eas/webhooks/
99redirects[distribution/webhooks]=eas/webhooks/
100redirects[distribution/turtle-cli]=classic/turtle-cli/
101redirects[distribution/app-signing]=app-signing/app-credentials/
102redirects[guides/adhoc-builds]=archived/adhoc-builds/
103# clients is now development
104redirects[clients/distribution-for-ios]=development/build/
105redirects[clients/distribution-for-android]=development/build/
106redirects[clients/compatibility]=development/compatibility/
107redirects[clients/development-workflows]=development/development-workflows/
108redirects[clients/eas-build]=development/eas-build/
109redirects[clients/extending-the-dev-menu]=development/extending-the-dev-menu/
110redirects[clients/getting-started]=development/getting-started/
111redirects[clients/installation]=development/installation/
112redirects[clients/introduction]=development/introduction/
113redirects[clients/troubleshooting]=development/troubleshooting/
114redirects[clients/upgrading]=development/upgrading/
115# Expo Modules
116redirects[modules]=modules/overview/
117redirects[module-api]=modules/module-api/
118redirects[module-config]=modules/module-config/
119
120echo "::group::[5/6] Add custom redirects"
121for i in "${!redirects[@]}" # iterate over keys
122do
123  aws s3 cp \
124    --no-progress \
125    --metadata-directive REPLACE \
126    --website-redirect "/${redirects[$i]}" \
127    "$target/404.html" \
128    "s3://${bucket}/${i}"
129
130  # Also add redirects for paths without `.html` or `/`
131  # S3 translates URLs with trailing slashes to `path/` -> `path/index.html`
132  if [[ $i != *".html" ]] && [[ $i != *"/" ]]; then
133    aws s3 cp \
134      --no-progress \
135      --metadata-directive REPLACE \
136      --website-redirect "/${redirects[$i]}" \
137      "$target/404.html" \
138      "s3://${bucket}/${i}/index.html"
139  fi
140done
141echo "::endgroup::"
142
143
144echo "::group::[6/6] Notify Google of sitemap changes"
145curl -m 15 "https://www.google.com/ping\?sitemap\=https%3A%2F%2F${bucket}%2Fsitemap.xml"
146echo "\n::endgroup::"
147