publish.sh 2.1 KB

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