lernaVersion.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing,
  13. # software distributed under the License is distributed on an
  14. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. # KIND, either express or implied. See the License for the
  16. # specific language governing permissions and limitations
  17. # under the License.
  18. rootDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
  19. lernaVersionArg="$1"
  20. if [[ -z $lernaVersionArg ]]; then
  21. echo '[ERROR] Please provide argument for "lerna version".'
  22. exit 1
  23. fi
  24. currentNpm=$(npm --version)
  25. npmVersion=$(node -e "process.stdout.write(require('./package.json').engines.npm)");
  26. isSatisfiedNpm=$(node -e "process.stdout.write(require('semver').satisfies('$currentNpm', '$npmVersion').toString())");
  27. currentNode=$(node --version)
  28. nodeVersion=$(node -e "process.stdout.write(require('./package.json').engines.node)");
  29. isSatisfiedNode=$(node -e "process.stdout.write(require('semver').satisfies('$currentNode', '$nodeVersion').toString())");
  30. # Check node version compatible with package.json
  31. if [[ $isSatisfiedNode != 'true' ]]; then
  32. echo "[ERROR] Your node version($currentNode) is not compatible with package.json($nodeVersion)"
  33. exit 1
  34. fi
  35. # Check npm version compatible with package.json
  36. if [[ $isSatisfiedNpm != 'true' ]]; then
  37. echo "[ERROR] Your npm version($currentNpm) is not compatible with package.json($npmVersion)"
  38. exit 1
  39. fi
  40. # Ignore Lerna's tag and push
  41. lerna version $1 --no-push --no-git-tag-version --yes
  42. if [[ -z $(git diff --stat) ]]; then
  43. echo '[ERROR] No changed packages to version.'
  44. exit 1
  45. fi
  46. # Get the current tag version
  47. tag=v$(node -e "process.stdout.write(require('./lerna.json').version)");
  48. message="chore(plugins): publish $tag"
  49. if [[ $? -ne 0 ]]; then
  50. echo '[ERROR] Can not update package-lock.json'
  51. exit 1
  52. fi
  53. # Auto-tag and auto-commit like usual
  54. git commit --all -m "${message}"
  55. git tag -a ${tag} -m ${tag}
  56. git push origin ${tag}
  57. git push