prepare-release-base.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 "::set-output name=run::false"
  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 "::set-output name=run::false"
  91. else
  92. echo "${NEW_VERSION}" > packaging/version || exit 1
  93. echo "::set-output name=run::true"
  94. echo "::set-output name=message::Update changelog and version for nightly build: ${NEW_VERSION}."
  95. echo "::set-output name=ref::master"
  96. echo "::set-output name=type::nightly"
  97. echo "::set-output name=branch::master"
  98. echo "::set-output name=version::nightly"
  99. fi
  100. elif [ "${EVENT_TYPE}" = 'patch' ] && [ "${EVENT_VERSION}" != "nightly" ]; then
  101. echo "::notice::Preparing a patch release build."
  102. check_version_format || exit 1
  103. check_for_existing_tag || exit 1
  104. branch_name="$(echo "${EVENT_VERSION}" | cut -f 1-2 -d '.')"
  105. if ! git checkout "${branch_name}"; then
  106. echo "::error::Could not find a branch for the ${branch_name}.x release series."
  107. exit 1
  108. fi
  109. minor_matches || exit 1
  110. major_matches || exit 1
  111. check_newer_patch_version || exit 1
  112. echo "${EVENT_VERSION}" > packaging/version || exit 1
  113. echo "::set-output name=run::true"
  114. echo "::set-output name=message::Patch release ${EVENT_VERSION}."
  115. echo "::set-output name=ref::${EVENT_VERSION}"
  116. echo "::set-output name=type::release"
  117. echo "::set-output name=branch::${branch_name}"
  118. echo "::set-output name=version::$(tr -d 'v' < packaging/version)"
  119. elif [ "${EVENT_TYPE}" = 'minor' ] && [ "${EVENT_VERSION}" != "nightly" ]; then
  120. echo "::notice::Preparing a minor release build."
  121. check_version_format || exit 1
  122. patch_is_zero || exit 1
  123. major_matches || exit 1
  124. check_newer_minor_version || exit 1
  125. check_for_existing_tag || exit 1
  126. branch_name="$(echo "${EVENT_VERSION}" | cut -f 1-2 -d '.')"
  127. if [ -n "$(git branch --list "${branch_name}")" ]; then
  128. echo "::error::A branch named ${branch_name} already exists in the repository."
  129. exit 1
  130. fi
  131. echo "${EVENT_VERSION}" > packaging/version || exit 1
  132. echo "::set-output name=run::true"
  133. echo "::set-output name=message::Minor release ${EVENT_VERSION}."
  134. echo "::set-output name=ref::${EVENT_VERSION}"
  135. echo "::set-output name=type::release"
  136. echo "::set-output name=branch::master"
  137. echo "::set-output name=new-branch::${branch_name}"
  138. echo "::set-output name=version::$(tr -d 'v' < packaging/version)"
  139. elif [ "${EVENT_TYPE}" = 'major' ] && [ "${EVENT_VERSION}" != "nightly" ]; then
  140. echo "::notice::Preparing a major release build."
  141. check_version_format || exit 1
  142. minor_is_zero || exit 1
  143. patch_is_zero || exit 1
  144. check_newer_major_version || exit 1
  145. check_for_existing_tag || exit 1
  146. echo "${EVENT_VERSION}" > packaging/version || exit 1
  147. echo "::set-output name=run::true"
  148. echo "::set-output name=message::Major release ${EVENT_VERSION}"
  149. echo "::set-output name=ref::${EVENT_VERSION}"
  150. echo "::set-output name=type::release"
  151. echo "::set-output name=branch::master"
  152. echo "::set-output name=version::$(tr -d 'v' < packaging/version)"
  153. else
  154. echo '::error::Unrecognized release type or invalid version.'
  155. exit 1
  156. fi