publish.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/bash
  2. # TODO all steps will be executed even if some steps will fail
  3. if [ -z $1 ]; then
  4. echo "Provide a new version as a first argument"
  5. exit 1
  6. fi
  7. VERSION=$1
  8. COMPANY="heartexlabs"
  9. REPO="label-studio"
  10. # Colors for colored output
  11. GREEN='\033[0;32m'
  12. NC='\033[0m' # No Color
  13. # Just to be sure
  14. git pull
  15. # Create new build
  16. rm -rf build
  17. yarn build:module
  18. rm build/.gitignore
  19. # Replace links to published files in README to the actual one
  20. # `ls -tU` sorts files by creation date (recent is first)
  21. # `head -1` gets the first one (the recent)
  22. sed -E -e "s/main\..*js/$(cd build/static/js && ls -tU *.js | head -1)/"\
  23. -e "s/main\..*css/$(cd build/static/css && ls -tU *.css | head -1)/"\
  24. -e "s/[0-9]\.[0-9]+\.[0-9]+/$VERSION/"\
  25. -i '' README.md
  26. git add README.md
  27. # Patch version
  28. sed -E -e "s/^ \"version\".*$/ \"version\": \"$VERSION\",/" -i '' package.json package-lock.json
  29. git add package.json package-lock.json
  30. echo && echo -e "${GREEN}### README and package.json modified successfully${NC}" && echo
  31. # Create release commit and tag and push them
  32. git commit -m "$VERSION"
  33. git tag v$VERSION
  34. git push
  35. git push origin v$VERSION
  36. echo && echo -e "${GREEN}### Release commit and tag pushed to github${NC}" && echo
  37. # Remove prepublish step because we are using custom script
  38. sed -E -e "s/^ *\"prepublishOnly\".*$//" -i '' package.json
  39. # Authenticate within npmjs.com using Access Token from NPMJS_TOKEN
  40. echo "//registry.npmjs.org/:_authToken=${NPMJS_TOKEN}" > ".npmrc"
  41. # Publish the package
  42. npm publish
  43. echo && echo -e "${GREEN}### NPM package published${NC}" && echo
  44. # GitHub Packages requires scoped @company/repo name
  45. sed -E -e "s/^ \"name\".*$/ \"name\": \"@$COMPANY\/$REPO\",/" -i '' package.json
  46. # Authenticate within Github Packages using Personal Access Token
  47. echo "//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES_TOKEN}" > ".npmrc"
  48. # Publish the package
  49. npm publish --registry=https://npm.pkg.github.com/
  50. echo && echo -e "${GREEN}### GitHub package published${NC}" && echo
  51. # Restore modified files
  52. git checkout -- package.json package-lock.json
  53. # clean up
  54. rm -rf build