publish.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env bash
  2. set -eu
  3. which awk sed jq 7z 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. update_version_in_source () {
  14. IFS=".-" read MAJOR MINOR REVISION EXTRA < <(echo "$VERSION")
  15. UNDERLINE=$(printf -- '-%.0s' $(seq 1 ${#TAG}))
  16. sed -i~ -bE "1,20{s/$VERSION_REGEX/$VERSION/g}" README.md
  17. rm README.md~
  18. sed -i~ -bE "4s/HEAD/$TAG ($DATE)/; 5s/-+/$UNDERLINE/" CHANGELOG.md
  19. rm CHANGELOG.md~
  20. sed -i~ -bE "s/(project\\s*\\(ArduinoJson\\s+VERSION\\s+).*?\\)/\\1$MAJOR.$MINOR.$REVISION)/" CMakeLists.txt
  21. rm CMakeLists.txt~
  22. sed -i~ -bE "s/\"version\":.*$/\"version\": \"$VERSION\",/" library.json
  23. rm library.json~
  24. sed -i~ -bE "s/version=.*$/version=$VERSION/" library.properties
  25. rm library.properties~
  26. sed -i~ -bE "s/version: .*$/version: $VERSION.{build}/" appveyor.yml
  27. rm appveyor.yml~
  28. sed -i~ -bE "s/^version: .*$/version: \"$VERSION\"/" idf_component.yml
  29. rm idf_component.yml~
  30. sed -i~ -bE \
  31. -e "s/ARDUINOJSON_VERSION .*$/ARDUINOJSON_VERSION \"$VERSION\"/" \
  32. -e "s/ARDUINOJSON_VERSION_MAJOR .*$/ARDUINOJSON_VERSION_MAJOR $MAJOR/" \
  33. -e "s/ARDUINOJSON_VERSION_MINOR .*$/ARDUINOJSON_VERSION_MINOR $MINOR/" \
  34. -e "s/ARDUINOJSON_VERSION_REVISION .*$/ARDUINOJSON_VERSION_REVISION $REVISION/" \
  35. -e "s/ARDUINOJSON_VERSION_MACRO .*$/ARDUINOJSON_VERSION_MACRO V$MAJOR$MINOR$REVISION/" \
  36. src/ArduinoJson/version.hpp
  37. rm src/ArduinoJson/version.hpp*~
  38. }
  39. commit_new_version () {
  40. git add src/ArduinoJson/version.hpp README.md CHANGELOG.md library.json library.properties appveyor.yml CMakeLists.txt idf_component.yml
  41. git commit -m "Set version to $VERSION"
  42. }
  43. add_tag () {
  44. CHANGES=$(awk '/\* /{ FOUND=1; print; next } { if (FOUND) exit}' CHANGELOG.md)
  45. git tag -m "ArduinoJson $VERSION"$'\n'"$CHANGES" "$TAG"
  46. }
  47. push () {
  48. git push --follow-tags
  49. }
  50. update_version_in_source
  51. commit_new_version
  52. add_tag
  53. push
  54. extras/scripts/build-arduino-package.sh . "../ArduinoJson-$TAG.zip"
  55. extras/scripts/build-single-header.sh "src/ArduinoJson.h" "../ArduinoJson-$TAG.h"
  56. extras/scripts/build-single-header.sh "src/ArduinoJson.hpp" "../ArduinoJson-$TAG.hpp"
  57. extras/scripts/get-release-page.sh "$VERSION" "CHANGELOG.md" "../ArduinoJson-$TAG.h" > "../ArduinoJson-$TAG.md"
  58. echo "You can now copy ../ArduinoJson-$TAG.md into arduinojson.org/collections/_versions/$VERSION.md"