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.
 
 
 
 
 

139 lines
3.9 KiB

  1. #!/bin/sh
  2. set -x
  3. set -e
  4. set -u
  5. export LC_ALL=C
  6. export LANG=C
  7. [ -n "${DEBEMAIL:-}" ] || DEBEMAIL="jenkins.grml.org Autobuilder <jenkins@grml.org>"
  8. export DEBEMAIL
  9. if [ ! -d source ] ; then
  10. echo "Please run the script in the jenkins workspace." >&2
  11. exit 1
  12. fi
  13. if [ -z "${BUILD_NUMBER:-}" ] ; then
  14. echo "No BUILD_NUMBER defined, please run it in jenkins." >&2
  15. exit 1
  16. fi
  17. if [ -z "${SVN_REVISION:-}" ] ; then
  18. echo "No SVN_REVISION defined, please run it with a subversion repository." >&2
  19. exit 1
  20. fi
  21. if ! [ -x "$(which svn2cl)" ] ; then
  22. echo "Error: svn2cl not available, please install subversion-tools." >&2
  23. exit 1
  24. fi
  25. if ! [ -x "$(which svn)" ] ; then
  26. echo "Error: svn not available, please install subversion." >&2
  27. exit 1
  28. fi
  29. if ! [ -x "$(which dpkg-parsechangelog)" ] ; then
  30. echo "Error: dpkg-parsechangelog not available, please install dpkg-dev." >&2
  31. exit 1
  32. fi
  33. echo "*** source package build phase ***"
  34. rm -f ./* || true
  35. ORIG_DIR=$(pwd)
  36. cd source/${branch:-}
  37. if ! [ -r debian/changelog ] ; then
  38. echo "Error: could not find debian/changelog (not a Debian package or wrong tag/branch?)" >&2
  39. exit 1
  40. fi
  41. SINCE_REVISION=$(svn info debian/changelog 2>/dev/null | awk '/Last Changed Rev:/ {print $4}')
  42. if [ -z "${SINCE_REVISION:-}" ] ; then
  43. echo "Error: could not detect svn revision which modified debian/changelog." >&2
  44. exit 1
  45. fi
  46. # package name
  47. PACKAGE=$(dpkg-parsechangelog --count 1 | awk '/^Source: / {print $2}')
  48. # get newest version number from changelog
  49. PREVIOUS_VERSION=$(dpkg-parsechangelog --count 1 | awk '/^Version: / {print $2}')
  50. build_snapshot() {
  51. DISTRIBUTION=$(dpkg-parsechangelog --count 1 | awk '/^Distribution/ {print $2}')
  52. TIMESTAMP=$(date +%s) # seconds since 1970-01-01 00:00:00 UTC, ensuring version gets always newer...
  53. if [ "$DISTRIBUTION" = "UNRELEASED" ] ; then
  54. # we do NOT raise the version number, if we detect an unreleased version
  55. SNAPSHOT_VERSION="${PREVIOUS_VERSION}~${TIMESTAMP}.svn${SVN_REVISION}.${BUILD_NUMBER}"
  56. else
  57. # calculate new snapshot version
  58. SNAPSHOT_VERSION="$(increase-version-number "$PREVIOUS_VERSION")~${TIMESTAMP}.svn${SVN_REVISION}.${BUILD_NUMBER}"
  59. fi
  60. # generate changelog
  61. SVN_CHANGELOG=$(mktemp)
  62. # build GNU like changelog with svn2cl as helper tool
  63. # timeout after 15 seconds without progress, we might be running into e.g.
  64. # "xsltApplyXSLTTemplate: A potential infinite template recursion was detected."
  65. if ! timeout -k 16 16 svn2cl --reparagraph --stdout --include-rev -r HEAD:$SINCE_REVISION > "$SVN_CHANGELOG" ; then
  66. echo ' * Sorry, generating changelog using svn2cl failed. :(
  67. Make sure the svn2cl command works on the jenkins host.
  68. For example validating server certificates is a common error.
  69. ' > "$SVN_CHANGELOG"
  70. fi
  71. # reduce changelog to just the first line of the commit message
  72. sed -in '/^\t*\s*\* \[r/,/^\t*\s*$/p' "$SVN_CHANGELOG"
  73. # shorten tabs at beginning of lines
  74. sed -i 's/\t/ /' "$SVN_CHANGELOG"
  75. cat > debian/changelog.new << EOF
  76. $PACKAGE ($SNAPSHOT_VERSION) unstable; urgency=low
  77. ** SNAPSHOT build **
  78. EOF
  79. cat "$SVN_CHANGELOG" >> debian/changelog.new
  80. cat >> debian/changelog.new << EOF
  81. -- $DEBEMAIL $(date -u -R)
  82. EOF
  83. # append original changelog
  84. cat debian/changelog >> debian/changelog.new
  85. # finally install new changelog
  86. mv debian/changelog.new debian/changelog
  87. rm -f "$SVN_CHANGELOG"
  88. }
  89. case "${branch:-}" in
  90. tags/*) echo "Building a tag version, not modifying the package" ;;
  91. *) build_snapshot;;
  92. esac
  93. cd $ORIG_DIR
  94. dpkg-source --tar-ignore=\.svn -b source/${branch:-}
  95. # revert to original debian/changelog to avoid highly increasing version numbers with each build
  96. ( cd source/${branch:-} ; svn revert debian/changelog )
  97. # needed for deploying artifacts
  98. mkdir -p "${JENKINS_HOME}/userContent/${JOB_NAME}/"
  99. echo "*** Cleaning up ${JENKINS_HOME}/userContent/${JOB_NAME} to get rid of possibly outdated data ***"
  100. rm -f "${JENKINS_HOME}/userContent/${JOB_NAME}/"*
  101. # vim:foldmethod=marker ts=2 ft=sh ai expandtab sw=2