modified version of jenkins debian glue (https://github.com/mika/jenkins-debian-glue) for devuan
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

225 lines
7.0 KiB

  1. #!/bin/bash
  2. if [ -z ${JENKINS_DEBIAN_GLUE_QUIET:-} ]; then
  3. set -x
  4. fi
  5. set -e
  6. set -u
  7. export LC_ALL=C
  8. export LANG=C
  9. if [ -r /etc/jenkins/debian_glue ] ; then
  10. . /etc/jenkins/debian_glue
  11. fi
  12. [ -n "${DEBEMAIL:-}" ] || DEBEMAIL="jenkins-debian-glue Autobuilder <jenkins@`hostname -f`>"
  13. export DEBEMAIL
  14. if [ ! -d source ] ; then
  15. echo "Please run the script in the jenkins workspace." >&2
  16. echo 'NOTE: Make sure to set the "Local module directory (optional)" option in the Subversion configuration to "source"' >&2
  17. exit 1
  18. fi
  19. if [ -z "${BUILD_NUMBER:-}" ] ; then
  20. echo "No BUILD_NUMBER defined, please run it in jenkins." >&2
  21. exit 1
  22. fi
  23. if [ -z "${SVN_REVISION:-}" ] ; then
  24. echo "No SVN_REVISION defined, please run it with a subversion repository." >&2
  25. exit 1
  26. fi
  27. if ! [ -x "$(which svn2cl)" ] ; then
  28. echo "Error: svn2cl not available, please install subversion-tools <= 1.6.18dfsg-1 or svn2cl." >&2
  29. exit 1
  30. fi
  31. if ! [ -x "$(which svn)" ] ; then
  32. echo "Error: svn not available, please install subversion." >&2
  33. exit 1
  34. fi
  35. if ! [ -x "$(which dpkg-parsechangelog)" ] ; then
  36. echo "Error: dpkg-parsechangelog not available, please install dpkg-dev." >&2
  37. exit 1
  38. fi
  39. JENKINS_DEBIAN_GLUE_VERSION=$(dpkg --list jenkins-debian-glue 2>/dev/null | awk '/^ii/ {print $3}')
  40. if [ -n "${JENKINS_DEBIAN_GLUE_VERSION:-}" ] ; then
  41. echo "*** Running jenkins-debian-glue version $JENKINS_DEBIAN_GLUE_VERSION ***"
  42. fi
  43. echo "*** source package build phase ***"
  44. rm -f ./* || true
  45. ORIG_DIR=$(pwd)
  46. cd source/${branch:-}
  47. if ! [ -r debian/changelog ] ; then
  48. echo "Error: could not find debian/changelog (not a Debian package or wrong tag/branch?)" >&2
  49. exit 1
  50. fi
  51. # Force the upgrade if subversion 1.7 (which introduced the upgrade command) or
  52. # later is available. Otherwise, if the system has been upgraded, the 'svn info'
  53. # will fail with an unhelpful error message
  54. SVN_VERSION="$(svn --version | awk '/, version / {print $3}')"
  55. if dpkg --compare-versions "$SVN_VERSION" ge 1.7 ; then
  56. echo "*** Executing 'svn upgrade' to make sure svn is up2date ***"
  57. svn upgrade
  58. fi
  59. SINCE_REVISION=$(svn info debian/changelog 2>/dev/null | awk '/Last Changed Rev:/ {print $4}')
  60. if [ -z "${SINCE_REVISION:-}" ] ; then
  61. echo "Error: could not detect svn revision which modified debian/changelog." >&2
  62. exit 1
  63. fi
  64. # required for dpkg-parsechangelog
  65. if ! [ -r debian/changelog ] ; then
  66. echo "Error: debian/changelog could not be read. Is this really a Debian package?" >&2
  67. exit 1
  68. fi
  69. # package name
  70. PACKAGE=$(dpkg-parsechangelog --count 1 | awk '/^Source: / {print $2}')
  71. # get newest version number from changelog
  72. PREVIOUS_VERSION=$(dpkg-parsechangelog --count 1 | awk '/^Version: / {print $2}')
  73. build_snapshot() {
  74. DISTRIBUTION=$(dpkg-parsechangelog --count 1 | awk '/^Distribution/ {print $2}')
  75. if [ -n "${TIMESTAMP_FORMAT:-}" ] ; then
  76. echo "*** Using custom timestamp format as specified by TIMESTAMP_FORMAT ***"
  77. TIMESTAMP="$(date -u +"$TIMESTAMP_FORMAT")"
  78. else
  79. TIMESTAMP="$(date -u +%Y%m%d%H%M%S)"
  80. fi
  81. if [ "$DISTRIBUTION" = "UNRELEASED" ] ; then
  82. # we do NOT raise the version number, if we detect an unreleased version
  83. SNAPSHOT_VERSION="${PREVIOUS_VERSION}~${TIMESTAMP}.svn${SVN_REVISION}.${BUILD_NUMBER}"
  84. else
  85. # calculate new snapshot version
  86. SNAPSHOT_VERSION="$(increase-version-number "$PREVIOUS_VERSION")~${TIMESTAMP}.svn${SVN_REVISION}.${BUILD_NUMBER}"
  87. fi
  88. # generate changelog
  89. SVN_CHANGELOG_ORIG=$(mktemp)
  90. SVN_CHANGELOG_EDIT=$(mktemp)
  91. # build GNU like changelog with svn2cl as helper tool
  92. # timeout after 15 seconds without progress, we might be running into e.g.
  93. # "xsltApplyXSLTTemplate: A potential infinite template recursion was detected."
  94. if ! timeout -k 16 16 svn2cl --reparagraph --stdout --include-rev -r HEAD:$SINCE_REVISION > "$SVN_CHANGELOG_ORIG" ; then
  95. echo ' * Sorry, generating changelog using svn2cl failed. :(
  96. Make sure the svn2cl command works on the jenkins host.
  97. For example validating server certificates is a common error.
  98. ' > "$SVN_CHANGELOG_ORIG"
  99. fi
  100. ## disclaimer: use separate sed calls to make it easier to adjust if necessary
  101. # reduce changelog to just the first line of the commit message
  102. sed -n '/^\t*\s*\* \[r/,/^\t*\s*$/p' "$SVN_CHANGELOG_ORIG" > "$SVN_CHANGELOG_EDIT"
  103. # get rid of author information that might be present from git-svn users
  104. sed -i '/^\t\s\sFrom: /d' "$SVN_CHANGELOG_EDIT"
  105. # replace tabs at beginning of lines with two spaces
  106. sed -i 's/^\t/ /' "$SVN_CHANGELOG_EDIT"
  107. # get rid of lines with just 4 space chars only
  108. sed -i '/^ $/d' "$SVN_CHANGELOG_EDIT"
  109. # get rid of empty lines
  110. sed -i '/^$/d' "$SVN_CHANGELOG_EDIT"
  111. # get rid of of the timestamp lines, looking like:
  112. # 2011-12-02 21:25 mprokop
  113. sed -ri '/^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}/d' "$SVN_CHANGELOG_EDIT"
  114. cat > debian/changelog.new << EOF
  115. $PACKAGE ($SNAPSHOT_VERSION) UNRELEASED; urgency=low
  116. ** SNAPSHOT build **
  117. EOF
  118. cat "$SVN_CHANGELOG_EDIT" >> debian/changelog.new
  119. cat >> debian/changelog.new << EOF
  120. -- $DEBEMAIL $(date -u -R)
  121. EOF
  122. # append original changelog
  123. cat debian/changelog >> debian/changelog.new
  124. # finally install new changelog
  125. mv debian/changelog.new debian/changelog
  126. rm -f "$SVN_CHANGELOG_ORIG" "$SVN_CHANGELOG_EDIT"
  127. }
  128. case "${branch:-}" in
  129. tags/*) echo "Building a tag version, not modifying the package" ;;
  130. *) build_snapshot;;
  131. esac
  132. cd $ORIG_DIR
  133. debian_only="$(svn propget mergeWithUpstream source/${branch:-}/debian)"
  134. if [ -n "${SBP_OPTS:-}" ] ; then
  135. echo "*** Found environment variable SBP_OPTS, set to ${SBP_OPTS} ***"
  136. else
  137. echo "*** Using svn-buildpackage default options provided by jenkins-debian-glue ***"
  138. SBP_OPTS="-nc --svn-download-orig -S --svn-builder dpkg-buildpackage -d --svn-move-to=${ORIG_DIR} --svn-dont-purge -uc -us --svn-ignore-new -rfakeroot"
  139. fi
  140. if [ "${debian_only:-}" = "1" ] ; then
  141. (
  142. cd "source/${branch:-}"
  143. echo "mergeWithUpstream detected, using svn-buildpackage to create source package"
  144. svn-buildpackage ${SBP_OPTS:-}
  145. )
  146. else
  147. if [ -n "${PRE_SOURCE_HOOK:-}" ] ; then
  148. echo "*** Found environment variable PRE_SOURCE_HOOK, set to ${PRE_SOURCE_HOOK:-} ***"
  149. sh ${PRE_SOURCE_HOOK:-}
  150. fi
  151. dpkg-source --tar-ignore=\.svn -b "source/${branch:-}"
  152. (
  153. if [ -n "${SNAPSHOT_VERSION:-}" ] ; then
  154. CHANGES_FILE="${ORIG_DIR}/${PACKAGE}_${SNAPSHOT_VERSION}_source.changes"
  155. else
  156. CHANGES_FILE="${ORIG_DIR}/${PACKAGE}_${PREVIOUS_VERSION}_source.changes"
  157. fi
  158. cd "source/${branch:-}"
  159. dpkg-genchanges -S -u"${ORIG_DIR}" > "${CHANGES_FILE}"
  160. )
  161. fi
  162. if [ -n "${KEY_ID:-}" ] ; then
  163. echo "*** Found environment variable KEY_ID, set to ${KEY_ID:-}, signing source package ***"
  164. if ! [ -x "$(which debsign)" ] ; then
  165. echo "Error: debsign not available, please make sure the devscripts package is installed." >&2
  166. exit 1
  167. fi
  168. debsign -k"${KEY_ID:-}" *_source.changes
  169. fi
  170. # revert to original debian/changelog to avoid highly increasing version numbers with each build
  171. ( cd source/${branch:-} ; svn revert debian/changelog )
  172. # vim:foldmethod=marker ts=2 ft=sh ai expandtab sw=2