prepare-release-base.sh 7.2 KB

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