prepare-release-base.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #!/bin/sh
  2. set -e
  3. REPO="${1}"
  4. EVENT_NAME="${2}"
  5. EVENT_TYPE="${3}"
  6. EVENT_VERSION="${4}"
  7. ##############################################################
  8. # Version validation functions
  9. check_version_format() {
  10. if ! echo "${EVENT_VERSION}" | grep -qE '^v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$'; then
  11. echo "::error::The supplied version (${EVENT_VERSION}) is not a valid version string."
  12. return 1
  13. fi
  14. }
  15. patch_is_zero() {
  16. if ! echo "${EVENT_VERSION}" | grep -qE '^v[[:digit:]]+\.[[:digit:]]+\.0$'; then
  17. echo "::error::The patch number for a ${EVENT_TYPE} build must be 0."
  18. return 1
  19. fi
  20. }
  21. minor_is_zero() {
  22. if ! echo "${EVENT_VERSION}" | grep -qE '^v[[:digit:]]+\.0'; then
  23. echo "::error::The minor version number for a ${EVENT_TYPE} build must be 0."
  24. return 1
  25. fi
  26. }
  27. major_matches() {
  28. current_major="$(cut -f 1 -d '-' packaging/version | cut -f 1 -d '.' | cut -f 2 -d 'v')"
  29. target_major="$(echo "${EVENT_VERSION}" | cut -f 1 -d '.' | cut -f 2 -d 'v')"
  30. if [ "${target_major}" != "${current_major}" ]; then
  31. echo "::error::Major version mismatch, expected ${current_major} but got ${target_major}."
  32. return 1
  33. fi
  34. }
  35. minor_matches() {
  36. current_minor="$(cut -f 1 -d '-' packaging/version | cut -f 2 -d '.')"
  37. target_minor="$(echo "${EVENT_VERSION}" | cut -f 2 -d '.')"
  38. if [ "${target_minor}" != "${current_minor}" ]; then
  39. echo "::error::Minor version mismatch, expected ${current_minor} but got ${target_minor}."
  40. return 1
  41. fi
  42. }
  43. check_for_existing_tag() {
  44. if git tag | grep -qE "^${EVENT_VERSION}$"; then
  45. echo "::error::A tag for version ${EVENT_VERSION} already exists."
  46. return 1
  47. fi
  48. }
  49. check_newer_major_version() {
  50. current="$(cut -f 1 -d '-' packaging/version | cut -f 1 -d '.' | cut -f 2 -d 'v')"
  51. target="$(echo "${EVENT_VERSION}" | cut -f 1 -d '.' | cut -f 2 -d 'v')"
  52. if [ "${target}" -le "${current}" ]; then
  53. echo "::error::Version ${EVENT_VERSION} is not newer than the current version."
  54. return 1
  55. fi
  56. }
  57. check_newer_minor_version() {
  58. current="$(cut -f 1 -d '-' packaging/version | cut -f 2 -d '.')"
  59. target="$(echo "${EVENT_VERSION}" | cut -f 2 -d '.')"
  60. if [ "${target}" -le "${current}" ]; then
  61. echo "::error::Version ${EVENT_VERSION} is not newer than the current version."
  62. return 1
  63. fi
  64. }
  65. check_newer_patch_version() {
  66. current="$(cut -f 1 -d '-' packaging/version | cut -f 3 -d '.')"
  67. target="$(echo "${EVENT_VERSION}" | cut -f 3 -d '.')"
  68. if [ "${target}" -le "${current}" ]; then
  69. echo "::error::Version ${EVENT_VERSION} is not newer than the current version."
  70. return 1
  71. fi
  72. }
  73. ##############################################################
  74. # Core logic
  75. git config user.name "netdatabot"
  76. git config user.email "bot@netdata.cloud"
  77. if [ "${REPO}" != "netdata/netdata" ]; then
  78. echo "::notice::Not running in the netdata/netdata repository, not queueing a release build."
  79. echo "::set-output name=run::false"
  80. elif [ "${EVENT_NAME}" = 'schedule' ] || [ "${EVENT_TYPE}" = 'nightly' ]; then
  81. echo "::notice::Preparing a nightly release build."
  82. LAST_TAG=$(git describe --abbrev=0 --tags)
  83. COMMITS_SINCE_RELEASE=$(git rev-list "${LAST_TAG}"..HEAD --count)
  84. NEW_VERSION="${LAST_TAG}-$((COMMITS_SINCE_RELEASE + 1))-nightly"
  85. LAST_VERSION_COMMIT="$(git rev-list -1 HEAD packaging/version)"
  86. HEAD_COMMIT="$(git rev-parse HEAD)"
  87. if [ "${EVENT_NAME}" = 'schedule' ] && [ "${LAST_VERSION_COMMIT}" = "${HEAD_COMMIT}" ] && grep -qE '.*-nightly$' packaging/version; then
  88. echo "::notice::No commits since last nightly build, not publishing a new nightly build."
  89. echo "::set-output name=run::false"
  90. else
  91. echo "${NEW_VERSION}" > packaging/version || exit 1
  92. echo "::set-output name=run::true"
  93. echo "::set-output name=message::Update changelog and version for nightly build: ${NEW_VERSION}."
  94. echo "::set-output name=ref::master"
  95. echo "::set-output name=type::nightly"
  96. echo "::set-output name=branch::master"
  97. echo "::set-output name=version::nightly"
  98. fi
  99. elif [ "${EVENT_TYPE}" = 'patch' ] && [ "${EVENT_VERSION}" != "nightly" ]; then
  100. echo "::notice::Preparing a patch release build."
  101. check_version_format || exit 1
  102. check_for_existing_tag || exit 1
  103. branch_name="$(echo "${EVENT_VERSION}" | cut -f 1-2 -d '.')"
  104. if ! git checkout "${branch_name}"; then
  105. echo "::error::Could not find a branch for the ${branch_name}.x release series."
  106. exit 1
  107. fi
  108. minor_matches || exit 1
  109. major_matches || exit 1
  110. check_newer_patch_version || exit 1
  111. echo "${EVENT_VERSION}" > packaging/version || exit 1
  112. echo "::set-output name=run::true"
  113. echo "::set-output name=message::Patch release ${EVENT_VERSION}."
  114. echo "::set-output name=ref::${EVENT_VERSION}"
  115. echo "::set-output name=type::release"
  116. echo "::set-output name=branch::${branch_name}"
  117. echo "::set-output name=version::$(tr -d 'v' < packaging/version)"
  118. elif [ "${EVENT_TYPE}" = 'minor' ] && [ "${EVENT_VERSION}" != "nightly" ]; then
  119. echo "::notice::Preparing a minor release build."
  120. check_version_format || exit 1
  121. patch_is_zero || exit 1
  122. major_matches || exit 1
  123. check_newer_minor_version || exit 1
  124. check_for_existing_tag || exit 1
  125. branch_name="$(echo "${EVENT_VERSION}" | cut -f 1-2 -d '.')"
  126. if [ -n "$(git branch --list "${branch_name}")" ]; then
  127. echo "::error::A branch named ${branch_name} already exists in the repository."
  128. exit 1
  129. fi
  130. echo "${EVENT_VERSION}" > packaging/version || exit 1
  131. echo "::set-output name=run::true"
  132. echo "::set-output name=message::Minor release ${EVENT_VERSION}."
  133. echo "::set-output name=ref::${EVENT_VERSION}"
  134. echo "::set-output name=type::release"
  135. echo "::set-output name=branch::master"
  136. echo "::set-output name=new-branch:${branch_name}"
  137. echo "::set-output name=version::$(tr -d 'v' < packaging/version)"
  138. elif [ "${EVENT_TYPE}" = 'major' ] && [ "${EVENT_VERSION}" != "nightly" ]; then
  139. echo "::notice::Preparing a major release build."
  140. check_version_format || exit 1
  141. minor_is_zero || exit 1
  142. patch_is_zero || exit 1
  143. check_newer_major_version || exit 1
  144. check_for_existing_tag || exit 1
  145. echo "${EVENT_VERSION}" > packaging/version || exit 1
  146. echo "::set-output name=run::true"
  147. echo "::set-output name=message::Major release ${EVENT_VERSION}"
  148. echo "::set-output name=ref::${EVENT_VERSION}"
  149. echo "::set-output name=type::release"
  150. echo "::set-output name=branch::master"
  151. echo "::set-output name=version::$(tr -d 'v' < packaging/version)"
  152. else
  153. echo '::error::Unrecognized release type or invalid version.'
  154. exit 1
  155. fi