deploy.sh 643 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/bash
  2. set -euxo pipefail
  3. ROOT=$(
  4. cd $(dirname $0)/..
  5. /bin/pwd
  6. )
  7. DIST="$ROOT/dist/"
  8. PUBLISH_BRANCH=$1
  9. VERSION=$(cat package.json | jq -r .version)
  10. git fetch --all
  11. git stash
  12. git checkout $PUBLISH_BRANCH
  13. git pull origin $PUBLISH_BRANCH
  14. pushd "v/"
  15. # If the folder already exists we want to repalce it
  16. if [ -d $VERSION ]; then
  17. rm -r $VERSION
  18. fi
  19. cp -r $DIST $VERSION
  20. git add $VERSION
  21. if [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  22. rm latest
  23. ln -s $VERSION latest
  24. git add latest
  25. fi
  26. git diff-index --quiet HEAD || git commit -q -m "Publish v$VERSION"
  27. git push origin $PUBLISH_BRANCH
  28. popd
  29. git checkout -
  30. git stash apply