circle-release-next-packages.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env bash
  2. function parse_git_hash() {
  3. git rev-parse --short HEAD 2> /dev/null | sed "s/\(.*\)/\1/"
  4. }
  5. function prapare_version_commit () {
  6. echo $'\nCommiting version changes. This commit will not be checked-in!'
  7. git config --global user.email "circleci@grafana.com"
  8. git config --global user.name "CirceCI"
  9. git commit -am "Version commit"
  10. }
  11. function unpublish_previous_canary () {
  12. echo $'\nUnpublishing previous canary packages'
  13. for PACKAGE in ui toolkit data runtime
  14. do
  15. # dist-tag next to be changed to canary when https://github.com/grafana/grafana/pull/18195 is merged
  16. CURRENT_CANARY=$(npm view @grafana/${PACKAGE} dist-tags.canary)
  17. if [ -z "${CURRENT_CANARY}" ]; then
  18. echo "@grafana/${PACKAGE} - Nothing to unpublish"
  19. else
  20. echo "Unpublish @grafana/${PACKAGE}@${CURRENT_CANARY}"
  21. npm unpublish "@grafana/${PACKAGE}@${CURRENT_CANARY}"
  22. fi
  23. done
  24. }
  25. # Get current version from lerna.json
  26. PACKAGE_VERSION=$(grep '"version"' lerna.json | cut -d '"' -f 4)
  27. # Get current commit's short hash
  28. GIT_SHA=$(parse_git_hash)
  29. echo "Commit: ${GIT_SHA}"
  30. echo "Current lerna.json version: ${PACKAGE_VERSION}"
  31. # check if there were any changes to packages between current and previous commit
  32. count=$(git diff HEAD~1..HEAD --name-only -- packages | awk '{c++} END {print c}')
  33. if [ -z "$count" ]; then
  34. echo "No changes in packages, skipping packages publishing"
  35. else
  36. echo "Changes detected in ${count} packages"
  37. echo "Releasing packages under ${PACKAGE_VERSION}-${GIT_SHA}"
  38. npx lerna version "${PACKAGE_VERSION}-${GIT_SHA}" --no-git-tag-version --no-push --force-publish -y
  39. echo $'\nGit status:'
  40. git status -s
  41. echo $'\nBuilding packages'
  42. yarn packages:build
  43. exit_status=$?
  44. if [ $exit_status -eq 1 ]; then
  45. echo "Packages build failed, skipping canary release"
  46. # TODO: notify on slack/email?
  47. exit
  48. fi
  49. prapare_version_commit
  50. unpublish_previous_canary
  51. echo $'\nPublishing packages'
  52. yarn packages:publishCanary
  53. fi