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]=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/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# EAS Metadata 120redirects[eas-metadata]=eas/metadata/ 121redirects[eas-metadata/introduction]=eas/metadata/ 122redirects[eas-metadata/getting-started]=eas/metadata/getting-started/ 123 124redirects[introduction/walkthrough]=tutorial/planning/ 125 126# Guides that have been deleted 127redirects[guides/using-gatsby]=guides/ 128redirects[guides/testing-on-devices]=workflow/run-on-device 129redirects[distribution/uploading-apps]=submit/introduction 130redirects[distribution/uploading-apps]=submit/introduction 131 132# We should change this redirect to a more general EAS guide later 133redirects[guides/setting-up-continuous-integration]=build/building-on-ci 134 135# Moved classic updates 136redirects[distribution/release-channels]=archive/classic-updates/release-channels 137redirects[distribution/advanced-release-channels]=archive/classic-updates/advanced-release-channels 138redirects[distribution/optimizing-updates]=archive/classic-updates/optimizing-updates 139redirects[eas-update/custom-updates-server]=distribution/custom-updates-server 140redirects[guides/offline-support]=archive/classic-updates/offline-support 141redirects[guides/preloading-and-caching-assets]=archive/classic-updates/preloading-and-caching-assets 142redirects[guides/configuring-updates]=archive/classic-updates/configuring-updates 143redirects[eas-update/bare-react-native]=bare/updating-your-app 144redirects[worfkflow/publishing]=archive/classic-updates/publishing 145redirects[classic/building-standalone-apps/]=archive/classic-updates/building-standalone-apps/ 146redirects[classic/turtle-cli/]=archive/classic-updates/turtle-cli/ 147 148echo "::group::[5/6] Add custom redirects" 149for i in "${!redirects[@]}" # iterate over keys 150do 151 aws s3 cp \ 152 --no-progress \ 153 --metadata-directive REPLACE \ 154 --website-redirect "/${redirects[$i]}" \ 155 "$target/404.html" \ 156 "s3://${bucket}/${i}" 157 158 # Also add redirects for paths without `.html` or `/` 159 # S3 translates URLs with trailing slashes to `path/` -> `path/index.html` 160 if [[ $i != *".html" ]] && [[ $i != *"/" ]]; then 161 aws s3 cp \ 162 --no-progress \ 163 --metadata-directive REPLACE \ 164 --website-redirect "/${redirects[$i]}" \ 165 "$target/404.html" \ 166 "s3://${bucket}/${i}/index.html" 167 fi 168done 169echo "::endgroup::" 170 171 172echo "::group::[6/6] Notify Google of sitemap changes" 173curl -m 15 "https://www.google.com/ping\?sitemap\=https%3A%2F%2F${bucket}%2Fsitemap.xml" 174echo "\n::endgroup::" 175