1#!/usr/bin/env bash 2 3set -euo pipefail 4 5scriptdir=$(dirname "${BASH_SOURCE[0]}") 6bucket="$AWS_BUCKET" 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 88# redirects[versions/latest/guides/exp-cli.html]=versions/latest/workflow/expo-cli/ 89# redirects[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]=archive/classic-updates/building-standalone-apps/ 98redirects[build-reference/build-webhook]=eas/webhooks/ 99redirects[distribution/webhooks]=eas/webhooks/ 100redirects[distribution/turtle-cli]=archive/classic-updates/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/introduction/ 107redirects[development/compatibility]=development/introduction/ 108redirects[clients/development-workflows]=development/development-workflows/ 109redirects[clients/eas-build]=development/eas-build/ 110redirects[clients/extending-the-dev-menu]=development/extending-the-dev-menu/ 111redirects[clients/getting-started]=development/getting-started/ 112redirects[clients/installation]=development/installation/ 113redirects[clients/introduction]=development/introduction/ 114redirects[clients/troubleshooting]=development/troubleshooting/ 115redirects[clients/upgrading]=development/upgrading/ 116# Expo Modules 117redirects[modules]=modules/overview/ 118redirects[module-api]=modules/module-api/ 119redirects[module-config]=modules/module-config/ 120# EAS Metadata 121redirects[eas-metadata]=eas/metadata/ 122redirects[eas-metadata/introduction]=eas/metadata/ 123redirects[eas-metadata/getting-started]=eas/metadata/getting-started/ 124 125# Development builds 126redirects[development/build]=development/create-development-builds/ 127redirects[development/getting-started]=development/create-development-builds/ 128redirects[development/troubleshooting]=development/introduction/ 129redirects[development/upgrading]=development/introduction/ 130redirects[development/extensions]=development/development-workflows/ 131redirects[development/develop-your-project]=development/use-development-builds/ 132 133# Guides that have been deleted 134redirects[guides/using-gatsby]=/ 135redirects[guides/testing-on-devices]=workflow/run-on-device 136redirects[distribution/uploading-apps]=submit/introduction 137redirects[guides/setup-native-firebase/]=guides/using-firebase 138redirects[guides/using-clojurescript/]=/ 139redirects[distribution/hosting-your-app/]=distribution/publishing-websites/ 140 141# We should change this redirect to a more general EAS guide later 142redirects[guides/setting-up-continuous-integration]=build/building-on-ci 143 144# Moved classic updates 145redirects[distribution/release-channels]=archive/classic-updates/release-channels 146redirects[distribution/advanced-release-channels]=archive/classic-updates/advanced-release-channels 147redirects[distribution/optimizing-updates]=archive/classic-updates/optimizing-updates 148redirects[eas-update/custom-updates-server]=distribution/custom-updates-server 149redirects[guides/offline-support]=archive/classic-updates/offline-support 150redirects[guides/preloading-and-caching-assets]=archive/classic-updates/preloading-and-caching-assets 151redirects[guides/configuring-updates]=archive/classic-updates/configuring-updates 152redirects[eas-update/bare-react-native]=bare/updating-your-app 153redirects[worfkflow/publishing]=archive/classic-updates/publishing 154redirects[classic/building-standalone-apps/]=archive/classic-updates/building-standalone-apps/ 155redirects[classic/turtle-cli/]=archive/classic-updates/turtle-cli/ 156redirects[archive/classic-updates/getting-started/]=eas-update/getting-started/ 157redirects[archived/]=archive/ 158 159# Old tutorial pages 160redirects[introduction/walkthrough]=tutorial/introduction/ 161redirects[tutorial/planning]=tutorial/introduction/ 162redirects[tutorial/sharing]=tutorial/introduction/ 163redirects[tutorial/text]=tutorial/introduction/ 164 165# Push notifications 166redirects[push-notifications/using-fcm/]=push-notifications/push-notifications-setup/ 167 168# EAS Update 169redirects[eas-update/developing-with-eas-update/]=eas-update/develop-faster/ 170redirects[eas-update/eas-update-with-local-build/]=eas-update/build-locally/ 171redirects[eas-update/eas-update-and-eas-cli/]=eas-update/eas-cli/ 172redirects[eas-update/debug-updates/]=eas-update/debug/ 173redirects[eas-update/how-eas-update-works/]=eas-update/how-it-works/ 174redirects[eas-update/migrate-to-eas-update/]=eas-update/migrate-from-classic-updates/ 175 176# Removed API reference docs 177redirects[versions/latest/sdk/facebook]=guides/authentication/ 178redirects[versions/latest/sdk/taskmanager]=versions/latest/sdk/task-manager/ 179redirects[versions/latest/sdk/videothumbnails]=versions/latest/sdk/video-thumbnails/ 180redirects[versions/latest/sdk/appearance]=versions/latest/react-native/appearance/ 181redirects[versions/latest/sdk/app-loading]=versions/latest/sdk/splash-screen/ 182redirects[versions/latest/sdk/app-auth]=guides/authentication/ 183redirects[versions/latest/sdk/firebase-core]=guides/using-firebase/ 184redirects[versions/latest/sdk/firebase-analytics]=guides/using-firebase/ 185redirects[versions/latest/sdk/firebase-recaptcha]=guides/using-firebase/ 186redirects[versions/latest/sdk/google-sign-in]=guides/authentication/ 187redirects[versions/latest/sdk/google]=guides/authentication/ 188redirects[versions/latest/sdk/amplitude/]=guides/using-analytics/ 189redirects[versions/latest/sdk/util/]=versions/latest/ 190 191# Redirects based on Sentry reports 192redirects[push-notifications]=push-notifications/overview/ 193 194echo "::group::[5/6] Add custom redirects" 195for i in "${!redirects[@]}" # iterate over keys 196do 197 aws s3 cp \ 198 --no-progress \ 199 --metadata-directive REPLACE \ 200 --website-redirect "/${redirects[$i]}" \ 201 "$target/404.html" \ 202 "s3://${bucket}/${i}" 203 204 # Also add redirects for paths without `.html` or `/` 205 # S3 translates URLs with trailing slashes to `path/` -> `path/index.html` 206 if [[ $i != *".html" ]] && [[ $i != *"/" ]]; then 207 aws s3 cp \ 208 --no-progress \ 209 --metadata-directive REPLACE \ 210 --website-redirect "/${redirects[$i]}" \ 211 "$target/404.html" \ 212 "s3://${bucket}/${i}/index.html" 213 fi 214done 215echo "::endgroup::" 216 217 218if [ "$bucket" = "docs.expo.dev" ]; then 219 echo "::group::[6/6] Notify Google of sitemap changes" 220 curl -m 15 "https://www.google.com/ping\?sitemap\=https%3A%2F%2F${bucket}%2Fsitemap.xml" 221 echo "\n::endgroup::" 222fi 223