publish.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/usr/bin/env bash
  2. set -eu
  3. which awk sed jq curl perl >/dev/null
  4. cd "$(dirname "$0")/../.."
  5. if ! git diff --quiet --exit-code; then
  6. echo "Repository contains uncommitted changes"
  7. exit
  8. fi
  9. VERSION="$1"
  10. DATE=$(date +%F)
  11. TAG="v$VERSION"
  12. VERSION_REGEX='[0-9]+\.[0-9]+\.[0-9]+(-[a-z0-9]+)?'
  13. STARS=$(curl -s https://api.github.com/repos/bblanchon/ArduinoJson | jq '.stargazers_count')
  14. update_version_in_source () {
  15. IFS=".-" read MAJOR MINOR REVISION EXTRA < <(echo "$VERSION")
  16. UNDERLINE=$(printf -- '-%.0s' $(seq 1 ${#TAG}))
  17. sed -i~ -bE "1,20{s/$VERSION_REGEX/$VERSION/g}" README.md
  18. rm README.md~
  19. sed -i~ -bE "4s/HEAD/$TAG ($DATE)/; 5s/-+/$UNDERLINE/" CHANGELOG.md
  20. rm CHANGELOG.md~
  21. sed -i~ -bE "s/(project\\s*\\(ArduinoJson\\s+VERSION\\s+).*?\\)/\\1$MAJOR.$MINOR.$REVISION)/" CMakeLists.txt
  22. rm CMakeLists.txt~
  23. sed -i~ -bE \
  24. -e "s/\"version\":.*$/\"version\": \"$VERSION\",/" \
  25. -e "s/[0-9]+ stars/$STARS stars/" \
  26. library.json
  27. rm library.json~
  28. sed -i~ -bE \
  29. -e "s/version=.*$/version=$VERSION/" \
  30. -e "s/[0-9]+ stars/$STARS stars/" \
  31. library.properties
  32. rm library.properties~
  33. sed -i~ -bE "s/version: .*$/version: $VERSION.{build}/" appveyor.yml
  34. rm appveyor.yml~
  35. sed -i~ -bE \
  36. -e "s/^version: .*$/version: \"$VERSION\"/" \
  37. -e "s/[0-9]+ stars/$STARS stars/" \
  38. idf_component.yml
  39. rm idf_component.yml~
  40. sed -i~ -bE \
  41. -e "s/ARDUINOJSON_VERSION .*$/ARDUINOJSON_VERSION \"$VERSION\"/" \
  42. -e "s/ARDUINOJSON_VERSION_MAJOR .*$/ARDUINOJSON_VERSION_MAJOR $MAJOR/" \
  43. -e "s/ARDUINOJSON_VERSION_MINOR .*$/ARDUINOJSON_VERSION_MINOR $MINOR/" \
  44. -e "s/ARDUINOJSON_VERSION_REVISION .*$/ARDUINOJSON_VERSION_REVISION $REVISION/" \
  45. -e "s/ARDUINOJSON_VERSION_MACRO .*$/ARDUINOJSON_VERSION_MACRO V$MAJOR$MINOR$REVISION/" \
  46. src/ArduinoJson/version.hpp
  47. rm src/ArduinoJson/version.hpp*~
  48. }
  49. commit_new_version () {
  50. git add src/ArduinoJson/version.hpp README.md CHANGELOG.md library.json library.properties appveyor.yml CMakeLists.txt idf_component.yml
  51. git commit -m "Set version to $VERSION"
  52. }
  53. add_tag () {
  54. CHANGES=$(awk '/\* /{ FOUND=1; print; next } { if (FOUND) exit}' CHANGELOG.md)
  55. git tag -m "ArduinoJson $VERSION"$'\n'"$CHANGES" "$TAG"
  56. }
  57. push () {
  58. git push --follow-tags
  59. }
  60. update_version_in_source
  61. commit_new_version
  62. add_tag
  63. push
  64. extras/scripts/build-single-header.sh "src/ArduinoJson.h" "../ArduinoJson-$TAG.h"
  65. extras/scripts/build-single-header.sh "src/ArduinoJson.hpp" "../ArduinoJson-$TAG.hpp"
  66. extras/scripts/get-release-page.sh "$VERSION" "CHANGELOG.md" "../ArduinoJson-$TAG.h" > "../ArduinoJson-$TAG.md"
  67. echo "You can now copy ../ArduinoJson-$TAG.md into arduinojson.org/collections/_versions/$VERSION.md"