1fa846d1fSNick Novitski#!/usr/bin/env bash 2fa846d1fSNick Novitski 3fa846d1fSNick Novitskiset -euo pipefail 4fa846d1fSNick Novitski 5d913a939SNick Novitskiscriptdir=$(dirname "${BASH_SOURCE[0]}") 6fe1ef024SJon Sampbucket="$AWS_BUCKET" 755028d60SNick Novitskitarget="${1-$scriptdir/out}" 8fa846d1fSNick Novitski 9ff1a0d36SNick Novitskiif [ ! -d "$target" ]; then 10ff1a0d36SNick Novitski echo "target $target not found" 11ff1a0d36SNick Novitski exit 1 12ff1a0d36SNick Novitskifi 13462d8ca6SNick Novitski 141625158dSJuwan Wheatley 152673e6cbSCedric van Putten# To keep the previous website up and running, we deploy it using these steps. 167c86b3fcSAxel Delafosse# 1. Sync Next.js static assets in \`_next/**\` folder 172673e6cbSCedric van Putten# > Uploads the new generated JS and asset files (stored in hashed folders to avoid collision with older deployments) 187c86b3fcSAxel Delafosse# 2. Sync assets in \`static/**\` folder 197c86b3fcSAxel Delafosse# 3. Overwrite HTML dependents, not located in \`_next/**\` or \`static/**\` folder 202673e6cbSCedric van Putten# > Force overwrite of all HTML files to make sure we use the latest one 217c86b3fcSAxel Delafosse# 4. Sync assets and clean up outdated files from previous deployments 227c86b3fcSAxel Delafosse# 5. Add custom redirects 234aa053a7SJuwan Wheatley# 6. Notify Google of sitemap changes for SEO 24fa846d1fSNick Novitski 254aa053a7SJuwan Wheatleyecho "::group::[1/6] Sync Next.js static assets in \`_next/**\` folder" 262673e6cbSCedric van Puttenaws s3 sync \ 272673e6cbSCedric van Putten --no-progress \ 282673e6cbSCedric van Putten --exclude "*" \ 292673e6cbSCedric van Putten --include "_next/**" \ 307c86b3fcSAxel Delafosse --cache-control "public, max-age=31536000, immutable" \ 317c86b3fcSAxel Delafosse "$target" \ 327c86b3fcSAxel Delafosse "s3://${bucket}" 337c86b3fcSAxel Delafosseecho "::endgroup::" 347c86b3fcSAxel Delafosse 354aa053a7SJuwan Wheatleyecho "::group::[2/6] Sync assets in \`static/**\` folder" 367c86b3fcSAxel Delafosseaws s3 sync \ 377c86b3fcSAxel Delafosse --no-progress \ 387c86b3fcSAxel Delafosse --exclude "*" \ 392673e6cbSCedric van Putten --include "static/**" \ 407c86b3fcSAxel Delafosse --cache-control "public, max-age=3600" \ 412673e6cbSCedric van Putten "$target" \ 422673e6cbSCedric van Putten "s3://${bucket}" 432673e6cbSCedric van Puttenecho "::endgroup::" 442673e6cbSCedric van Putten 452673e6cbSCedric van Putten# Due to a bug with `aws s3 sync` we need to copy everything first instead of syncing 462673e6cbSCedric van Putten# see: https://github.com/aws/aws-cli/issues/3273#issuecomment-643436849 474aa053a7SJuwan Wheatleyecho "::group::[3/6] Overwrite HTML dependents, not located in \`_next/**\` or \`static/**\` folder" 48fa846d1fSNick Novitskiaws s3 cp \ 492673e6cbSCedric van Putten --no-progress \ 50fa846d1fSNick Novitski --recursive \ 512673e6cbSCedric van Putten --exclude "_next/**" \ 522673e6cbSCedric van Putten --exclude "static/**" \ 532673e6cbSCedric van Putten "$target" \ 542673e6cbSCedric van Putten "s3://${bucket}" 552673e6cbSCedric van Puttenecho "::endgroup::" 562673e6cbSCedric van Putten 574aa053a7SJuwan Wheatleyecho "::group::[4/6] Sync assets and clean up outdated files from previous deployments" 582673e6cbSCedric van Puttenaws s3 sync \ 592673e6cbSCedric van Putten --no-progress \ 602673e6cbSCedric van Putten --delete \ 612673e6cbSCedric van Putten "$target" \ 622673e6cbSCedric van Putten "s3://${bucket}" 632673e6cbSCedric van Puttenecho "::endgroup::" 64d913a939SNick Novitski 65d913a939SNick Novitskideclare -A redirects # associative array variable 66fa846d1fSNick Novitski 67569595feSNick Novitski# usage: 68ab795694SJames Ide# redirects[requests/for/this/path]=are/redirected/to/this/one 69569595feSNick Novitski 70fa846d1fSNick Novitski# Temporarily create a redirect for a page that Home links to 71d913a939SNick Novitskiredirects[versions/latest/introduction/installation.html]=versions/latest/introduction/installation/ 7260c16a13SNick Novitski# useful link on twitter 7360c16a13SNick Novitskiredirects[versions/latest/guides/app-stores.html]=versions/latest/distribution/app-stores/ 749492327fSNick Novitski# Xdl caches 759492327fSNick Novitskiredirects[versions/latest/guides/offline-support.html]=versions/latest/guides/offline-support/ 769492327fSNick Novitski# xdl convert comment 77af28e265SNick Novitskiredirects[versions/latest/sdk/index.html]=versions/latest/sdk/overview/ 782d5b1bc3SAdam Navarro# upgrading expo -> upgrading sdk walkthrough 792d5b1bc3SAdam Navarroredirects[versions/latest/workflow/upgrading-expo]=versions/latest/workflow/upgrading-expo-sdk-walkthrough/ 80b777a1e0SNick Novitski# rename 81af28e265SNick Novitskiredirects[versions/latest/sdk/haptic/index.html]=versions/latest/sdk/haptics/ 820a5b256dSTC Davisredirects[development/eas-build]=development/build 83ef0dec16SCharlie Cruzan# duplicate docs file, consolidate into one page 84ef0dec16SCharlie Cruzanredirects[versions/latest/sdk/introduction/index.html]=versions/latest/sdk/overview/ 85f543d3a4SBrent Vatne# project-lifecycle is now covered by managed-vs-bare 86f543d3a4SBrent Vatneredirects[versions/latest/introduction/project-lifecycle/]=versions/latest/introduction/managed-vs-bare/ 87ba396c75SBrent Vatne# exp-cli is now expo-cli 889de0c686SAman Mittal# redirects[versions/latest/guides/exp-cli.html]=versions/latest/workflow/expo-cli/ 899de0c686SAman Mittal# redirects[versions/latest/guides/exp-cli]=versions/latest/workflow/expo-cli/ 90943d9310Stcdavis# Migrated FAQ pages 91943d9310Stcdavisredirects[faq/image-background]=ui-programming/image-background/ 92943d9310Stcdavisredirects[faq/react-native-styling-buttons]=ui-programming/react-native-styling-buttons/ 93943d9310Stcdavisredirects[faq/react-native-version-mismatch]=troubleshooting/react-native-version-mismatch/ 94943d9310Stcdavisredirects[faq/clear-cache-windows]=troubleshooting/clear-cache-windows/ 95943d9310Stcdavisredirects[faq/clear-cache-macos-linux]=troubleshooting/clear-cache-macos-linux/ 96943d9310Stcdavisredirects[faq/application-has-not-been-registered]=troubleshooting/application-has-not-been-registered/ 973a4dc2d7SJon Sampredirects[distribution/building-standalone-apps]=archive/classic-updates/building-standalone-apps/ 985337f6f0SDominik Sokalredirects[build-reference/build-webhook]=eas/webhooks/ 995337f6f0SDominik Sokalredirects[distribution/webhooks]=eas/webhooks/ 1003a4dc2d7SJon Sampredirects[distribution/turtle-cli]=archive/classic-updates/turtle-cli/ 1017f40d711SCharlie Cruzanredirects[distribution/app-signing]=app-signing/app-credentials/ 1027f40d711SCharlie Cruzanredirects[guides/adhoc-builds]=archived/adhoc-builds/ 103818c5d24SJon Samp# clients is now development 10451723c53STC Davisredirects[clients/distribution-for-ios]=development/build/ 10551723c53STC Davisredirects[clients/distribution-for-android]=development/build/ 106571d295fSBrent Vatneredirects[clients/compatibility]=development/introduction/ 107571d295fSBrent Vatneredirects[development/compatibility]=development/introduction/ 108818c5d24SJon Sampredirects[clients/development-workflows]=development/development-workflows/ 109818c5d24SJon Sampredirects[clients/eas-build]=development/eas-build/ 110818c5d24SJon Sampredirects[clients/extending-the-dev-menu]=development/extending-the-dev-menu/ 111818c5d24SJon Sampredirects[clients/getting-started]=development/getting-started/ 112818c5d24SJon Sampredirects[clients/installation]=development/installation/ 113818c5d24SJon Sampredirects[clients/introduction]=development/introduction/ 114818c5d24SJon Sampredirects[clients/troubleshooting]=development/troubleshooting/ 115818c5d24SJon Sampredirects[clients/upgrading]=development/upgrading/ 11637bec8acSTomasz Sapeta# Expo Modules 11737bec8acSTomasz Sapetaredirects[modules]=modules/overview/ 11837bec8acSTomasz Sapetaredirects[module-api]=modules/module-api/ 11937bec8acSTomasz Sapetaredirects[module-config]=modules/module-config/ 120e6808ea5SCedric van Putten# EAS Metadata 1219f8df43aSCedric van Puttenredirects[eas-metadata]=eas/metadata/ 1229f8df43aSCedric van Puttenredirects[eas-metadata/introduction]=eas/metadata/ 1239f8df43aSCedric van Puttenredirects[eas-metadata/getting-started]=eas/metadata/getting-started/ 124*f7a14300SAman Mittal# EAS Build 125*f7a14300SAman Mittalredirects[build-reference/eas-json]=eas/json/#eas-build 126943d9310Stcdavis 1275f82a70cSAman Mittal# Development builds 1285f82a70cSAman Mittalredirects[development/build]=development/create-development-builds/ 1295f82a70cSAman Mittalredirects[development/getting-started]=development/create-development-builds/ 1305f82a70cSAman Mittalredirects[development/troubleshooting]=development/introduction/ 1315f82a70cSAman Mittalredirects[development/upgrading]=development/introduction/ 1325f82a70cSAman Mittalredirects[development/extensions]=development/development-workflows/ 1334fcc8372SDominik Sokalredirects[development/develop-your-project]=development/use-development-builds/ 1345f82a70cSAman Mittal 13500afe142SAman Mittal# Guides that have been deleted 136b2d111e6SAman Mittalredirects[guides/using-gatsby]=/ 13723ab6e3dSBrent Vatneredirects[guides/testing-on-devices]=workflow/run-on-device 138dc0355b4SEvan Baconredirects[distribution/uploading-apps]=submit/introduction 13922fce504SAman Mittalredirects[guides/setup-native-firebase/]=guides/using-firebase 140b2d111e6SAman Mittalredirects[guides/using-clojurescript/]=/ 1415a2d7d97SAman Mittalredirects[distribution/hosting-your-app/]=distribution/publishing-websites/ 14202155a46SBrent Vatne 14302155a46SBrent Vatne# We should change this redirect to a more general EAS guide later 14402155a46SBrent Vatneredirects[guides/setting-up-continuous-integration]=build/building-on-ci 14500afe142SAman Mittal 1463a4dc2d7SJon Samp# Moved classic updates 1473a4dc2d7SJon Sampredirects[distribution/release-channels]=archive/classic-updates/release-channels 1483a4dc2d7SJon Sampredirects[distribution/advanced-release-channels]=archive/classic-updates/advanced-release-channels 1493a4dc2d7SJon Sampredirects[distribution/optimizing-updates]=archive/classic-updates/optimizing-updates 1503a4dc2d7SJon Sampredirects[eas-update/custom-updates-server]=distribution/custom-updates-server 1513a4dc2d7SJon Sampredirects[guides/offline-support]=archive/classic-updates/offline-support 1523a4dc2d7SJon Sampredirects[guides/preloading-and-caching-assets]=archive/classic-updates/preloading-and-caching-assets 1533a4dc2d7SJon Sampredirects[guides/configuring-updates]=archive/classic-updates/configuring-updates 1543a4dc2d7SJon Sampredirects[eas-update/bare-react-native]=bare/updating-your-app 1553a4dc2d7SJon Sampredirects[worfkflow/publishing]=archive/classic-updates/publishing 1563a4dc2d7SJon Sampredirects[classic/building-standalone-apps/]=archive/classic-updates/building-standalone-apps/ 1573a4dc2d7SJon Sampredirects[classic/turtle-cli/]=archive/classic-updates/turtle-cli/ 158a06a9af8SAman Mittalredirects[archive/classic-updates/getting-started/]=eas-update/getting-started/ 159a06a9af8SAman Mittalredirects[archived/]=archive/ 1603a4dc2d7SJon Samp 16159f5e389SAman Mittal# Old tutorial pages 16259f5e389SAman Mittalredirects[introduction/walkthrough]=tutorial/introduction/ 16359f5e389SAman Mittalredirects[tutorial/planning]=tutorial/introduction/ 16459f5e389SAman Mittalredirects[tutorial/sharing]=tutorial/introduction/ 16559f5e389SAman Mittalredirects[tutorial/text]=tutorial/introduction/ 16659f5e389SAman Mittal 167d7273661SQuinlan Jung# EAS Update 168ab795694SJames Ideredirects[technical-specs/expo-updates-0/]=archive/technical-specs/expo-updates-0/ 169d7273661SQuinlan Jungredirects[eas-update/developing-with-eas-update/]=eas-update/develop-faster/ 170d7273661SQuinlan Jungredirects[eas-update/eas-update-with-local-build/]=eas-update/build-locally/ 171d7273661SQuinlan Jungredirects[eas-update/eas-update-and-eas-cli/]=eas-update/eas-cli/ 172d7273661SQuinlan Jungredirects[eas-update/debug-updates/]=eas-update/debug/ 173d7273661SQuinlan Jungredirects[eas-update/how-eas-update-works/]=eas-update/how-it-works/ 174d7273661SQuinlan Jungredirects[eas-update/migrate-to-eas-update/]=eas-update/migrate-from-classic-updates/ 175d7273661SQuinlan Jung 17659f5e389SAman Mittal# Removed API reference docs 17759f5e389SAman Mittalredirects[versions/latest/sdk/facebook]=guides/authentication/ 17859f5e389SAman Mittalredirects[versions/latest/sdk/taskmanager]=versions/latest/sdk/task-manager/ 17959f5e389SAman Mittalredirects[versions/latest/sdk/videothumbnails]=versions/latest/sdk/video-thumbnails/ 18059f5e389SAman Mittalredirects[versions/latest/sdk/appearance]=versions/latest/react-native/appearance/ 18159f5e389SAman Mittalredirects[versions/latest/sdk/app-loading]=versions/latest/sdk/splash-screen/ 18259f5e389SAman Mittalredirects[versions/latest/sdk/app-auth]=guides/authentication/ 183d27f77b9SKeith Kurakredirects[versions/latest/sdk/firebase-core]=guides/using-firebase/ 184d27f77b9SKeith Kurakredirects[versions/latest/sdk/firebase-analytics]=guides/using-firebase/ 185d27f77b9SKeith Kurakredirects[versions/latest/sdk/firebase-recaptcha]=guides/using-firebase/ 18659f5e389SAman Mittalredirects[versions/latest/sdk/google-sign-in]=guides/authentication/ 187a06a9af8SAman Mittalredirects[versions/latest/sdk/google]=guides/authentication/ 188a06a9af8SAman Mittalredirects[versions/latest/sdk/amplitude/]=guides/using-analytics/ 189bde45f47SAman Mittalredirects[versions/latest/sdk/util/]=versions/latest/ 190bde45f47SAman Mittal 191bde45f47SAman Mittal# Redirects based on Sentry reports 192bde45f47SAman Mittalredirects[push-notifications]=push-notifications/overview/ 19359f5e389SAman Mittal 1944aa053a7SJuwan Wheatleyecho "::group::[5/6] Add custom redirects" 195d913a939SNick Novitskifor i in "${!redirects[@]}" # iterate over keys 196d913a939SNick Novitskido 197fa846d1fSNick Novitski aws s3 cp \ 1982673e6cbSCedric van Putten --no-progress \ 199fa846d1fSNick Novitski --metadata-directive REPLACE \ 200d913a939SNick Novitski --website-redirect "/${redirects[$i]}" \ 20155028d60SNick Novitski "$target/404.html" \ 202d913a939SNick Novitski "s3://${bucket}/${i}" 20371674d77SCedric van Putten 20471674d77SCedric van Putten # Also add redirects for paths without `.html` or `/` 20571674d77SCedric van Putten # S3 translates URLs with trailing slashes to `path/` -> `path/index.html` 20671674d77SCedric van Putten if [[ $i != *".html" ]] && [[ $i != *"/" ]]; then 20771674d77SCedric van Putten aws s3 cp \ 208cc022ebeSCedric van Putten --no-progress \ 20971674d77SCedric van Putten --metadata-directive REPLACE \ 21071674d77SCedric van Putten --website-redirect "/${redirects[$i]}" \ 21171674d77SCedric van Putten "$target/404.html" \ 21271674d77SCedric van Putten "s3://${bucket}/${i}/index.html" 21371674d77SCedric van Putten fi 214d913a939SNick Novitskidone 2152673e6cbSCedric van Puttenecho "::endgroup::" 2161d2f92e9SCharlie Cruzan 2171625158dSJuwan Wheatley 218fe1ef024SJon Sampif [ "$bucket" = "docs.expo.dev" ]; then 2194aa053a7SJuwan Wheatley echo "::group::[6/6] Notify Google of sitemap changes" 22038fcf40fSJames Ide curl -m 15 "https://www.google.com/ping\?sitemap\=https%3A%2F%2F${bucket}%2Fsitemap.xml" 2211d2f92e9SCharlie Cruzan echo "\n::endgroup::" 222fe1ef024SJon Sampfi 223