upload-to-cdn.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #!/usr/bin/env bash
  2. # Upload Uppy releases to Edgly.net CDN. Copyright (c) 2018, Transloadit Ltd.
  3. #
  4. # This file:
  5. #
  6. # - Assumes EDGLY_KEY and EDGLY_SECRET are available (e.g. set via Travis secrets)
  7. # - Tries to load env.sh instead, if not
  8. # - Checks if a tag is being built (on Travis - otherwise opts to continue execution regardless)
  9. # - Installs AWS CLI if needed
  10. # - Assumed a fully built uppy is in root dir (unless a specific tag was specified, then it's fetched from npm)
  11. # - Runs npm pack, and stores files to e.g. https://transloadit.edgly.net/releases/uppy/v0.30.5/uppy.css
  12. # - Uses local package by default, if [version] argument was specified, takes package from npm
  13. #
  14. # Run as:
  15. #
  16. # ./upload-to-cdn.sh [version]
  17. #
  18. # To upload all versions in one go (DANGER):
  19. #
  20. # git tag |awk -Fv '{print "./bin/upload-to-cdn.sh "$2}' |bash
  21. #
  22. # Authors:
  23. #
  24. # - Kevin van Zonneveld <kevin@transloadit.com>
  25. set -o pipefail
  26. set -o errexit
  27. set -o nounset
  28. # set -o xtrace
  29. # Set magic variables for current FILE & DIR
  30. __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  31. __file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
  32. __base="$(basename ${__file} .sh)"
  33. __root="$(cd "$(dirname "${__dir}")" && pwd)"
  34. versionSuffix=""
  35. # versionSuffix="-test3"
  36. function fatal () {
  37. echo "❌ ${*}";
  38. exit 1
  39. }
  40. pushd "${__root}" > /dev/null 2>&1
  41. if [ -n "${TRAVIS:-}" ]; then
  42. if [ "${TRAVIS_PULL_REQUEST:-}" != "false" ]; then
  43. echo "On Travis (TRAVIS is '${TRAVIS}'), I'm not pushing releases to the CDN for pull requests (TRAVIS_PULL_REQUEST is '${TRAVIS_PULL_REQUEST}')"
  44. exit 0
  45. fi
  46. if [[ ! "$TRAVIS_COMMIT_MESSAGE" =~ ^Release* ]]; then
  47. echo "On Travis (TRAVIS is '${TRAVIS}'), I'm not pushing releases to the CDN unless commit message starts with 'Release' (TRAVIS_COMMIT_MESSAGE is '${TRAVIS_COMMIT_MESSAGE}')"
  48. exit 0
  49. fi
  50. fi
  51. if [ -z "${EDGLY_KEY:-}" ] && [ -f ./env.sh ]; then
  52. source ./env.sh
  53. fi
  54. [ -z "${EDGLY_KEY:-}" ] && fatal "Unable to find or source EDGLY_KEY env var"
  55. type aws || pip install --user awscli
  56. remoteVersion="${1:-}"
  57. version="${remoteVersion}"
  58. if [ -z "${remoteVersion}" ]; then
  59. localVersion=$(node -pe "require('./packages/uppy/package.json').version")
  60. echo "${localVersion}"
  61. version="${localVersion}"
  62. fi
  63. majorVersion=$(echo "${version}${versionSuffix}" |awk -F. '{print $1}')
  64. echo -n "--> Check if not overwriting an existing tag ... "
  65. env \
  66. AWS_ACCESS_KEY_ID="${EDGLY_KEY}" \
  67. AWS_SECRET_ACCESS_KEY="${EDGLY_SECRET}" \
  68. aws s3 ls \
  69. --region="us-east-1" \
  70. "s3://crates.edgly.net/756b8efaed084669b02cb99d4540d81f/default/releases/uppy/v${version}${versionSuffix}/uppy.min.css" > /dev/null 2>&1 && fatal "Tag ${version}${versionSuffix} already exists"
  71. echo "✅"
  72. echo "--> Obtain relevant npm files for robodog ${version}${versionSuffix} ... "
  73. pushd packages/@uppy/robodog
  74. if [ -z "${remoteVersion}" ]; then
  75. echo "Warning, writing a local build to the CDN, this is usually not what you want. Sleeping 3s. Press CTRL+C! "
  76. sleep 3
  77. npm pack
  78. else
  79. npm pack "@uppy/robodog@${remoteVersion}"
  80. fi
  81. popd > /dev/null 2>&1
  82. echo "✅"
  83. rm -rf /tmp/robodog-to-edgly
  84. mkdir -p /tmp/robodog-to-edgly
  85. cp -af "packages/@uppy/robodog/uppy-robodog-${version}.tgz" /tmp/robodog-to-edgly/
  86. tar zxvf "packages/@uppy/robodog/uppy-robodog-${version}.tgz" -C /tmp/robodog-to-edgly/
  87. echo "--> Upload robodog to edgly.net CDN"
  88. pushd /tmp/robodog-to-edgly/package/dist
  89. # --delete \
  90. env \
  91. AWS_ACCESS_KEY_ID="${EDGLY_KEY}" \
  92. AWS_SECRET_ACCESS_KEY="${EDGLY_SECRET}" \
  93. aws s3 sync \
  94. --region="us-east-1" \
  95. --exclude 'node_modules/*' \
  96. ./ "s3://crates.edgly.net/756b8efaed084669b02cb99d4540d81f/default/releases/uppy/v${version}${versionSuffix}"
  97. echo "Saved https://transloadit.edgly.net/releases/uppy/v${version}${versionSuffix}/"
  98. popd > /dev/null 2>&1
  99. rm -rf /tmp/robodog-to-edgly
  100. echo "--> Obtain relevant npm files for locales ${version}${versionSuffix} ... "
  101. pushd packages/@uppy/locales
  102. if [ -z "${remoteVersion}" ]; then
  103. npm pack || fatal "Unable to fetch "
  104. else
  105. npm pack "@uppy/locales@${remoteVersion}"
  106. fi
  107. popd > /dev/null 2>&1
  108. echo "✅"
  109. rm -rf /tmp/locales-to-edgly
  110. mkdir -p /tmp/locales-to-edgly
  111. cp -af "packages/@uppy/locales/uppy-locales-${version}.tgz" /tmp/locales-to-edgly/
  112. tar zxvf "packages/@uppy/locales/uppy-locales-${version}.tgz" -C /tmp/locales-to-edgly/
  113. echo "--> Upload locales to edgly.net CDN"
  114. pushd /tmp/locales-to-edgly/package/dist
  115. # --delete \
  116. env \
  117. AWS_ACCESS_KEY_ID="${EDGLY_KEY}" \
  118. AWS_SECRET_ACCESS_KEY="${EDGLY_SECRET}" \
  119. aws s3 sync \
  120. --region="us-east-1" \
  121. --exclude 'node_modules/*' \
  122. ./ "s3://crates.edgly.net/756b8efaed084669b02cb99d4540d81f/default/releases/uppy/v${version}${versionSuffix}/locales"
  123. echo "Saved https://transloadit.edgly.net/releases/uppy/v${version}${versionSuffix}/locales/"
  124. popd > /dev/null 2>&1
  125. rm -rf /tmp/locales-to-edgly
  126. echo "--> Obtain relevant npm files for uppy ${version}${versionSuffix} ... "
  127. pushd packages/uppy
  128. if [ -z "${remoteVersion}" ]; then
  129. npm pack || fatal "Unable to fetch "
  130. else
  131. npm pack "uppy@${remoteVersion}"
  132. fi
  133. popd > /dev/null 2>&1
  134. echo "✅"
  135. rm -rf /tmp/uppy-to-edgly
  136. mkdir -p /tmp/uppy-to-edgly
  137. cp -af "packages/uppy/uppy-${version}.tgz" /tmp/uppy-to-edgly/
  138. tar zxvf "packages/uppy/uppy-${version}.tgz" -C /tmp/uppy-to-edgly/
  139. echo "--> Upload uppy to edgly.net CDN"
  140. pushd /tmp/uppy-to-edgly/package/dist
  141. # --delete \
  142. env \
  143. AWS_ACCESS_KEY_ID="${EDGLY_KEY}" \
  144. AWS_SECRET_ACCESS_KEY="${EDGLY_SECRET}" \
  145. aws s3 sync \
  146. --region="us-east-1" \
  147. --exclude 'node_modules/*' \
  148. ./ "s3://crates.edgly.net/756b8efaed084669b02cb99d4540d81f/default/releases/uppy/v${version}${versionSuffix}"
  149. echo "Saved https://transloadit.edgly.net/releases/uppy/v${version}${versionSuffix}/"
  150. popd > /dev/null 2>&1
  151. rm -rf /tmp/uppy-to-edgly
  152. if [ "${versionSuffix}" != "" ]; then
  153. echo "Not setting latest version because versionSuffix was set, which is used for testing only"
  154. else
  155. echo "${version}" | env \
  156. AWS_ACCESS_KEY_ID="${EDGLY_KEY}" \
  157. AWS_SECRET_ACCESS_KEY="${EDGLY_SECRET}" \
  158. aws s3 cp \
  159. --region="us-east-1" \
  160. --content-type="text/plain" \
  161. - "s3://crates.edgly.net/756b8efaed084669b02cb99d4540d81f/default/releases/uppy/latest.txt"
  162. echo "Saved https://transloadit.edgly.net/releases/uppy/latest.txt"
  163. echo "${version}" | env \
  164. AWS_ACCESS_KEY_ID="${EDGLY_KEY}" \
  165. AWS_SECRET_ACCESS_KEY="${EDGLY_SECRET}" \
  166. aws s3 cp \
  167. --region="us-east-1" \
  168. --content-type="text/plain" \
  169. - "s3://crates.edgly.net/756b8efaed084669b02cb99d4540d81f/default/releases/uppy/v${majorVersion}-latest.txt"
  170. echo "Saved https://transloadit.edgly.net/releases/uppy/v${majorVersion}-latest.txt"
  171. fi
  172. popd > /dev/null 2>&1