circle-release-next-packages.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.next)
  17. echo "Unpublish @grafana/${PACKAGE}@${CURRENT_CANARY}"
  18. npm unpublish "@grafana/${PACKAGE}@${CURRENT_CANARY}"
  19. done
  20. }
  21. # Get current version from lerna.json
  22. PACKAGE_VERSION=$(grep '"version"' lerna.json | cut -d '"' -f 4)
  23. # Get current commit's short hash
  24. GIT_SHA=$(parse_git_hash)
  25. echo "Commit: ${GIT_SHA}"
  26. echo "Current lerna.json version: ${PACKAGE_VERSION}"
  27. # check if there were any changes to packages between current and previous commit
  28. count=$(git diff HEAD~1..HEAD --name-only -- packages | awk '{c++} END {print c}')
  29. if [ -z "$count" ]; then
  30. echo "No changes in packages, skipping packages publishing"
  31. else
  32. echo "Changes detected in ${count} packages"
  33. echo "Releasing packages under ${PACKAGE_VERSION}-${GIT_SHA}"
  34. npx lerna version "${PACKAGE_VERSION}-${GIT_SHA}" --no-git-tag-version --no-push --force-publish -y
  35. echo $'\nGit status:'
  36. git status -s
  37. echo $'\nBuilding packages'
  38. yarn packages:build
  39. exit_status=$?
  40. if [ $exit_status -eq 1 ]; then
  41. echo "Packages build failed, skipping canary release"
  42. # TODO: notify on slack/email?
  43. exit
  44. fi
  45. prapare_version_commit
  46. unpublish_previous_canary
  47. echo $'\nPublishing packages'
  48. yarn packages:publishNext
  49. fi