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/ 82# duplicate docs file, consolidate into one page 83redirects[versions/latest/sdk/introduction/index.html]=versions/latest/sdk/overview/ 84# project-lifecycle is now covered by managed-vs-bare 85redirects[versions/latest/introduction/project-lifecycle/]=versions/latest/introduction/managed-vs-bare/ 86# exp-cli is now expo-cli 87redirects[versions/latest/guides/exp-cli.html]=versions/latest/workflow/expo-cli/ 88redirects[versions/latest/guides/exp-cli]=versions/latest/workflow/expo-cli/ 89# Migrated FAQ pages 90redirects[faq/image-background]=ui-programming/image-background/ 91redirects[faq/react-native-styling-buttons]=ui-programming/react-native-styling-buttons/ 92redirects[faq/react-native-version-mismatch]=troubleshooting/react-native-version-mismatch/ 93redirects[faq/clear-cache-windows]=troubleshooting/clear-cache-windows/ 94redirects[faq/clear-cache-macos-linux]=troubleshooting/clear-cache-macos-linux/ 95redirects[faq/application-has-not-been-registered]=troubleshooting/application-has-not-been-registered/ 96redirects[distribution/building-standalone-apps]=classic/building-standalone-apps/ 97redirects[distribution/webhooks]=build-reference/build-webhook/ 98redirects[distribution/turtle-cli]=classic/turtle-cli/ 99redirects[distribution/app-signing]=app-signing/app-credentials/ 100redirects[guides/adhoc-builds]=archived/adhoc-builds/ 101 102echo "::group::[5/6] Add custom redirects" 103for i in "${!redirects[@]}" # iterate over keys 104do 105 aws s3 cp \ 106 --no-progress \ 107 --metadata-directive REPLACE \ 108 --website-redirect "/${redirects[$i]}" \ 109 "$target/404.html" \ 110 "s3://${bucket}/${i}" 111 112 # Also add redirects for paths without `.html` or `/` 113 # S3 translates URLs with trailing slashes to `path/` -> `path/index.html` 114 if [[ $i != *".html" ]] && [[ $i != *"/" ]]; then 115 aws s3 cp \ 116 --no-progress \ 117 --metadata-directive REPLACE \ 118 --website-redirect "/${redirects[$i]}" \ 119 "$target/404.html" \ 120 "s3://${bucket}/${i}/index.html" 121 fi 122done 123echo "::endgroup::" 124 125 126echo "::group::[6/6] Notify Google of sitemap changes" 127curl -m 15 "https://www.google.com/ping\?sitemap\=https%3A%2F%2F${bucket}%2Fsitemap.xml" 128echo "\n::endgroup::" 129