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. src/ArduinoJson/version.hpp
  36. rm src/ArduinoJson/version.hpp*~
  37. }
  38. commit_new_version () {
  39. git add src/ArduinoJson/version.hpp README.md CHANGELOG.md library.json library.properties appveyor.yml CMakeLists.txt
  40. git commit -m "Set version to $VERSION"
  41. }
  42. add_tag () {
  43. CHANGES=$(awk '/\* /{ FOUND=1; print; next } { if (FOUND) exit}' CHANGELOG.md)
  44. git tag -m "ArduinoJson $VERSION"$'\n'"$CHANGES" "$TAG"
  45. }
  46. push () {
  47. git push --follow-tags
  48. }
  49. update_version_in_source
  50. commit_new_version
  51. add_tag
  52. push
  53. extras/scripts/build-arduino-package.sh . "../ArduinoJson-$TAG.zip"
  54. extras/scripts/build-single-header.sh "src/ArduinoJson.h" "../ArduinoJson-$TAG.h"
  55. extras/scripts/build-single-header.sh "src/ArduinoJson.hpp" "../ArduinoJson-$TAG.hpp"
  56. extras/scripts/wandbox/publish.sh "../ArduinoJson-$TAG.h" > "../ArduinoJson-$TAG-wandbox.txt" || echo "Wandbox failed!"
  57. extras/scripts/get-release-page.sh "$VERSION" "CHANGELOG.md" "../ArduinoJson-$TAG-wandbox.txt" > "../ArduinoJson-$TAG.md"
  58. echo "You can now copy ../ArduinoJson-$TAG.md into arduinojson.org/collections/_versions/$VERSION.md"