endtoend-build-ci 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/env bash
  2. set -o pipefail
  3. set -o errexit
  4. set -o nounset
  5. # Set magic variables for current file & dir
  6. __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  7. __file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
  8. __base="$(basename ${__file} .sh)"
  9. __root="$(cd "$(dirname "${__dir}")" && pwd)"
  10. if [ -z "${CI:-}" ]; then
  11. echo "!! Running CI-style end-to-end tests but CI environment variable is not set"
  12. echo "It is generally ill-advised to run the full end-to-end suite on your local machine."
  13. echo "You are probably looking for this instead:"
  14. echo " yarn run test:endtoend:local"
  15. echo ""
  16. echo "Hit Ctrl+C to stop or Enter if you REALLY DO want to run the full thing."
  17. read
  18. else
  19. echo ::group::endtoend_build_ci
  20. fi
  21. set -o xtrace
  22. YARN="corepack yarn"
  23. VERDACCIO_REGISTRY=http://localhost:4002
  24. CURRENT_COMMIT="$(git rev-parse HEAD)"
  25. cleanup() {
  26. rm -rf "${__root}/test/endtoend/node_modules"
  27. rm -rf "${__root}/test/endtoend/tmp"
  28. git reset
  29. git checkout $CURRENT_COMMIT
  30. if [ -n "${CI:-}" ]; then
  31. echo ::endgroup::
  32. fi
  33. }
  34. function on_exit() {
  35. # revert to public registry
  36. $YARN config unset npmScopes --home
  37. $YARN config unset npmRegistryServer --home
  38. $YARN config unset npmAuthToken --home
  39. $YARN config unset unsafeHttpWhitelist --home
  40. cleanup
  41. }
  42. trap on_exit EXIT
  43. echo "Preparing for end to end test: copying static HTML and CSS, building JS"
  44. rm -rf "${__root}/test/endtoend/node_modules"
  45. # list of @uppy/* packages
  46. PACKAGES="$($YARN workspaces list --json | node -e 'require("readline").createInterface({input:process.stdin}).on("line",l=>{const{name}=JSON.parse(l);if(name?.startsWith("@uppy/"))console.log(name)})')"
  47. cleanup
  48. # Initialise verdaccio storage path.
  49. mkdir -p "${__root}/test/endtoend/tmp/verdaccio"
  50. $YARN run build
  51. # https://github.com/facebook/create-react-app/pull/4626
  52. TOKEN="$($YARN npm-auth-to-token -u user -p password -e user@example.com -r "$VERDACCIO_REGISTRY")"
  53. git checkout -b endtoend-test-build
  54. # HACK this thing changes all the time for some reason on CI
  55. # so I'll just ignore it…
  56. git checkout -- yarn.lock
  57. $YARN config set npmRegistryServer "$VERDACCIO_REGISTRY" --home
  58. $YARN config set npmAuthToken "$TOKEN" --home
  59. $YARN config set npmScopes.uppy.npmRegistryServer "$VERDACCIO_REGISTRY" --home
  60. $YARN config set npmScopes.uppy.npmPublishRegistry "$VERDACCIO_REGISTRY" --home
  61. $YARN config set npmScopes.uppy.npmAuthToken "$TOKEN" --home
  62. $YARN config set unsafeHttpWhitelist "localhost" --home
  63. # Simulate a publish of everything, to the local registry,
  64. # without changing things in git
  65. ENDTOEND=1 $YARN workspaces foreach --include '@uppy/*'\
  66. version prerelease -d
  67. $YARN version apply --all --prerelease
  68. ENDTOEND=1 $YARN workspaces foreach --include '@uppy/*'\
  69. npm publish
  70. bash "${__dir}/endtoend-build-tests"
  71. cleanup