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.

generate-git-snapshot 18 KiB

Rework generate-git-snapshot to make sure quilt can't break the build When using the dpkg 3.0 (quilt) format (see debian/source/format) there might be quilt patches still applied in the source tree, either because of a broken build or under certain - though not yet clearly identified - situations which seem to end with a "diff: standard output: Broken pipe" message in the build log. This then might end up in a build failure like: | + cd /var/lib/jenkins/workspace/glusterfs-source | + dpkg-source -i -I -b source | dpkg-source: info: using source format `3.0 (quilt)' | diff: standard output: Broken pipe | diff: standard output: Broken pipe | dpkg-source: info: building glusterfs using existing ./glusterfs_3.2.7.orig.tar.gz | dpkg-source: info: local changes detected, the modified files are: | source/ChangeLog | source/doc/gluster.8 | source/doc/glusterfs.8 | source/libglusterfs/src/common-utils.c | source/rpc/rpc-lib/src/rpcsvc.c | source/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c | dpkg-source: error: aborting due to unexpected upstream changes, see /tmp/glusterfs_3.2.7-2~bpo60+1.diff.3Wkisr | dpkg-source: info: you can integrate the local changes with dpkg-source --commit While everything has been cleanly integrated in debian/patches/ the build process fails because it looks like there have been modifications to upstream sources whereas it's just wrong information about patches applied. So instead make sure we enter a clean git repository before doing any changes (this can be skipped via SKIP_GIT_CLEANUP=true) and also unapply all present quilt patches (this can be skipped via SKIP_QUILT_CLEANUP=true). Finally replace the dpkg-source call with dpkg-buildpackage and its --source-option=--unapply-patches feature. While the combination of the git cleanup, quilt cleanup and dpkg-source->dpkg-buildpackage is more than explicitely necessary this provides more flexibility if needed. Thanks: Raphael Hertzog <hertzog@debian.org> for his dpkg related feedback
8 years ago
Rework generate-git-snapshot to make sure quilt can't break the build When using the dpkg 3.0 (quilt) format (see debian/source/format) there might be quilt patches still applied in the source tree, either because of a broken build or under certain - though not yet clearly identified - situations which seem to end with a "diff: standard output: Broken pipe" message in the build log. This then might end up in a build failure like: | + cd /var/lib/jenkins/workspace/glusterfs-source | + dpkg-source -i -I -b source | dpkg-source: info: using source format `3.0 (quilt)' | diff: standard output: Broken pipe | diff: standard output: Broken pipe | dpkg-source: info: building glusterfs using existing ./glusterfs_3.2.7.orig.tar.gz | dpkg-source: info: local changes detected, the modified files are: | source/ChangeLog | source/doc/gluster.8 | source/doc/glusterfs.8 | source/libglusterfs/src/common-utils.c | source/rpc/rpc-lib/src/rpcsvc.c | source/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c | dpkg-source: error: aborting due to unexpected upstream changes, see /tmp/glusterfs_3.2.7-2~bpo60+1.diff.3Wkisr | dpkg-source: info: you can integrate the local changes with dpkg-source --commit While everything has been cleanly integrated in debian/patches/ the build process fails because it looks like there have been modifications to upstream sources whereas it's just wrong information about patches applied. So instead make sure we enter a clean git repository before doing any changes (this can be skipped via SKIP_GIT_CLEANUP=true) and also unapply all present quilt patches (this can be skipped via SKIP_QUILT_CLEANUP=true). Finally replace the dpkg-source call with dpkg-buildpackage and its --source-option=--unapply-patches feature. While the combination of the git cleanup, quilt cleanup and dpkg-source->dpkg-buildpackage is more than explicitely necessary this provides more flexibility if needed. Thanks: Raphael Hertzog <hertzog@debian.org> for his dpkg related feedback
8 years ago
Rework generate-git-snapshot to make sure quilt can't break the build When using the dpkg 3.0 (quilt) format (see debian/source/format) there might be quilt patches still applied in the source tree, either because of a broken build or under certain - though not yet clearly identified - situations which seem to end with a "diff: standard output: Broken pipe" message in the build log. This then might end up in a build failure like: | + cd /var/lib/jenkins/workspace/glusterfs-source | + dpkg-source -i -I -b source | dpkg-source: info: using source format `3.0 (quilt)' | diff: standard output: Broken pipe | diff: standard output: Broken pipe | dpkg-source: info: building glusterfs using existing ./glusterfs_3.2.7.orig.tar.gz | dpkg-source: info: local changes detected, the modified files are: | source/ChangeLog | source/doc/gluster.8 | source/doc/glusterfs.8 | source/libglusterfs/src/common-utils.c | source/rpc/rpc-lib/src/rpcsvc.c | source/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c | dpkg-source: error: aborting due to unexpected upstream changes, see /tmp/glusterfs_3.2.7-2~bpo60+1.diff.3Wkisr | dpkg-source: info: you can integrate the local changes with dpkg-source --commit While everything has been cleanly integrated in debian/patches/ the build process fails because it looks like there have been modifications to upstream sources whereas it's just wrong information about patches applied. So instead make sure we enter a clean git repository before doing any changes (this can be skipped via SKIP_GIT_CLEANUP=true) and also unapply all present quilt patches (this can be skipped via SKIP_QUILT_CLEANUP=true). Finally replace the dpkg-source call with dpkg-buildpackage and its --source-option=--unapply-patches feature. While the combination of the git cleanup, quilt cleanup and dpkg-source->dpkg-buildpackage is more than explicitely necessary this provides more flexibility if needed. Thanks: Raphael Hertzog <hertzog@debian.org> for his dpkg related feedback
8 years ago
Rework generate-git-snapshot to make sure quilt can't break the build When using the dpkg 3.0 (quilt) format (see debian/source/format) there might be quilt patches still applied in the source tree, either because of a broken build or under certain - though not yet clearly identified - situations which seem to end with a "diff: standard output: Broken pipe" message in the build log. This then might end up in a build failure like: | + cd /var/lib/jenkins/workspace/glusterfs-source | + dpkg-source -i -I -b source | dpkg-source: info: using source format `3.0 (quilt)' | diff: standard output: Broken pipe | diff: standard output: Broken pipe | dpkg-source: info: building glusterfs using existing ./glusterfs_3.2.7.orig.tar.gz | dpkg-source: info: local changes detected, the modified files are: | source/ChangeLog | source/doc/gluster.8 | source/doc/glusterfs.8 | source/libglusterfs/src/common-utils.c | source/rpc/rpc-lib/src/rpcsvc.c | source/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c | dpkg-source: error: aborting due to unexpected upstream changes, see /tmp/glusterfs_3.2.7-2~bpo60+1.diff.3Wkisr | dpkg-source: info: you can integrate the local changes with dpkg-source --commit While everything has been cleanly integrated in debian/patches/ the build process fails because it looks like there have been modifications to upstream sources whereas it's just wrong information about patches applied. So instead make sure we enter a clean git repository before doing any changes (this can be skipped via SKIP_GIT_CLEANUP=true) and also unapply all present quilt patches (this can be skipped via SKIP_QUILT_CLEANUP=true). Finally replace the dpkg-source call with dpkg-buildpackage and its --source-option=--unapply-patches feature. While the combination of the git cleanup, quilt cleanup and dpkg-source->dpkg-buildpackage is more than explicitely necessary this provides more flexibility if needed. Thanks: Raphael Hertzog <hertzog@debian.org> for his dpkg related feedback
8 years ago
Rework generate-git-snapshot to make sure quilt can't break the build When using the dpkg 3.0 (quilt) format (see debian/source/format) there might be quilt patches still applied in the source tree, either because of a broken build or under certain - though not yet clearly identified - situations which seem to end with a "diff: standard output: Broken pipe" message in the build log. This then might end up in a build failure like: | + cd /var/lib/jenkins/workspace/glusterfs-source | + dpkg-source -i -I -b source | dpkg-source: info: using source format `3.0 (quilt)' | diff: standard output: Broken pipe | diff: standard output: Broken pipe | dpkg-source: info: building glusterfs using existing ./glusterfs_3.2.7.orig.tar.gz | dpkg-source: info: local changes detected, the modified files are: | source/ChangeLog | source/doc/gluster.8 | source/doc/glusterfs.8 | source/libglusterfs/src/common-utils.c | source/rpc/rpc-lib/src/rpcsvc.c | source/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c | dpkg-source: error: aborting due to unexpected upstream changes, see /tmp/glusterfs_3.2.7-2~bpo60+1.diff.3Wkisr | dpkg-source: info: you can integrate the local changes with dpkg-source --commit While everything has been cleanly integrated in debian/patches/ the build process fails because it looks like there have been modifications to upstream sources whereas it's just wrong information about patches applied. So instead make sure we enter a clean git repository before doing any changes (this can be skipped via SKIP_GIT_CLEANUP=true) and also unapply all present quilt patches (this can be skipped via SKIP_QUILT_CLEANUP=true). Finally replace the dpkg-source call with dpkg-buildpackage and its --source-option=--unapply-patches feature. While the combination of the git cleanup, quilt cleanup and dpkg-source->dpkg-buildpackage is more than explicitely necessary this provides more flexibility if needed. Thanks: Raphael Hertzog <hertzog@debian.org> for his dpkg related feedback
8 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. #!/bin/bash
  2. if [ -z ${JENKINS_DEBIAN_GLUE_QUIET:-} ]; then
  3. set -x
  4. fi
  5. set -e
  6. set -u
  7. if [ -r /etc/jenkins/debian_glue ] ; then
  8. . /etc/jenkins/debian_glue
  9. fi
  10. [ -n "${DEBEMAIL:-}" ] || DEBEMAIL="jenkins-debian-glue Autobuilder <jenkins@`hostname -f`>"
  11. export DEBEMAIL
  12. [ -n "${SOURCE_DIRECTORY:-}" ] || SOURCE_DIRECTORY='source' # where checkout of sources resides
  13. if [ ! -d "${SOURCE_DIRECTORY}" ] ; then
  14. echo "Please run the script in the jenkins workspace." >&2
  15. echo 'NOTE: Make sure that "Source Code Management -> Git -> Additional Behaviours -> Check out to a sub-directory" is set to "source"' >&2
  16. exit 1
  17. fi
  18. if [ -z "${BUILD_NUMBER:-}" ] ; then
  19. echo "No BUILD_NUMBER defined, please run it in jenkins." >&2
  20. exit 1
  21. fi
  22. if [ -z "${GIT_COMMIT:-}" ] ; then
  23. echo "No GIT_COMMIT defined, please run it with git-plugin in jenkins. ">&2
  24. exit 1
  25. fi
  26. # since git-buildpackage >=0.6.24 only the gbp command is available
  27. if [ -x "$(which gbp)" ] ; then
  28. GBP_DCH="gbp dch"
  29. GBP_BUILDPACKAGE="gbp buildpackage"
  30. else
  31. GBP_DCH="git-dch"
  32. GBP_BUILDPACKAGE="git-buildpackage"
  33. fi
  34. JENKINS_DEBIAN_GLUE_VERSION=$(dpkg --list jenkins-debian-glue 2>/dev/null | awk '/^ii/ {print $3}')
  35. if [ -n "${JENKINS_DEBIAN_GLUE_VERSION:-}" ] ; then
  36. echo "*** Running jenkins-debian-glue version $JENKINS_DEBIAN_GLUE_VERSION ***"
  37. fi
  38. if [ -n "${DIST:-}" -a -z "${KEEP_SOURCE_CHANGES:-}" ]; then
  39. echo "*** Warning: DIST is set but KEEP_SOURCE_CHANGES is not, this doesn't make sense. ***"
  40. echo "*** Please consider setting KEEP_SOURCE_CHANGES=true when setting DIST. ***"
  41. if ! ${GBP_DCH} --help 2>&1 | grep -q -- --distribution ; then
  42. echo "Error: ${GBP_DCH} doesn't support the --distribution option. Upgrade git-buildpackage to version 0.6.7 or newer." >&2
  43. exit 1
  44. fi
  45. fi
  46. gbp_opts() {
  47. # support overriding git-buildpackage options
  48. if [ -n "${GBP_OPTS:-}" ] ; then
  49. echo "Found environment variable GBP_OPTS, set to ${GBP_OPTS}"
  50. else
  51. GBP_OPTS=" -nc --git-force-create --git-ignore-new --git-ignore-branch -S -us -uc --git-verbose --git-builder=/bin/true --git-cleaner=/bin/true --git-export-dir= "
  52. echo "Using git-buildpackage default options provided by jenkins-debian-glue"
  53. fi
  54. }
  55. version_information() {
  56. # required for dpkg-parsechangelog
  57. if ! [ -r debian/changelog ] ; then
  58. echo "Error: debian/changelog could not be read. Is this really a Debian package?" >&2
  59. return 1
  60. fi
  61. # retrieve and adjust information
  62. ORIG_VERSION=$(dpkg-parsechangelog --count 1 | awk '/^Version/ {print $2}')
  63. DISTRIBUTION=$(dpkg-parsechangelog --count 1 | awk '/^Distribution/ {print $2}')
  64. APPLY_VERSION_WORKAROUND=false
  65. if [ "${USE_ORIG_VERSION:-}" = "true" ] ; then
  66. echo "*** USE_ORIG_VERSION is set to 'true', keeping original version [${ORIG_VERSION}] from changelog ***"
  67. VERSION_STRING="${ORIG_VERSION}"
  68. else
  69. # we want to get a version string like
  70. # $ORIG_VERSION+0~$TIMESTAMP.$BUILD_NUMBER~1.$GIT_ID
  71. # so the version is always increasing over time, no matter what
  72. INCREASED_VERSION=$(increase-version-number $ORIG_VERSION)
  73. if [ -n "${TIMESTAMP_FORMAT:-}" ] ; then
  74. echo "*** Using custom timestamp format as specified by TIMESTAMP_FORMAT ***"
  75. TIMESTAMP="$(date -u +"$TIMESTAMP_FORMAT")"
  76. else
  77. TIMESTAMP="$(date -u +%Y%m%d%H%M%S)"
  78. fi
  79. BUILD_VERSION="${TIMESTAMP}.${BUILD_NUMBER}" # git-dch appends something like ~1.gbp5f433e then
  80. # we do NOT raise the version number, if we detect an unreleased version,
  81. # otherwise the released version would be older than our snapshot builds
  82. if [ "$DISTRIBUTION" = "UNRELEASED" ] && dpkg --compare-versions "$ORIG_VERSION" lt "$INCREASED_VERSION" ; then
  83. echo "*** Not increasing version number as distribution is set to UNRELEASED ***"
  84. INCREASED_VERSION="$ORIG_VERSION"
  85. if [ "${UNRELEASED_APPEND_COMMIT:-}" = "true" ]; then
  86. # However, as we will use plain 'dch' for this, we still want to have
  87. # the (short) GIT commit id inside the version...
  88. echo "*** UNRELEASED_APPEND_COMMIT is set to 'true', manually appending GIT commit to version number ***"
  89. BUILD_VERSION="${BUILD_VERSION}~${GIT_COMMIT:0:7}"
  90. fi
  91. APPLY_VERSION_WORKAROUND=true
  92. fi
  93. VERSION_STRING="${INCREASED_VERSION}~${BUILD_VERSION}"
  94. fi
  95. if [ -n "${distribution:-}" ] ; then
  96. echo "Distribution variable found. Adding distribution specific version."
  97. VERSION_STRING="${VERSION_STRING}+${distribution//-/_}"
  98. fi
  99. echo "*** Version string set to $VERSION_STRING ***"
  100. }
  101. # support overriding git-dch options
  102. dch_opts() {
  103. if [ -n "${DCH_OPTS:-}" ] ; then
  104. echo "Found environment variable DCH_OPTS, set to ${DCH_OPTS}"
  105. else
  106. DCH_OPTS="-S --multimaint-merge --ignore-branch"
  107. echo "Using default ${GBP_DCH} options (${DCH_OPTS})"
  108. fi
  109. DCH_COMBINED_OPTS="${DCH_OPTS}"
  110. # support overriding extra options for git-dch
  111. if [ -n "${DCH_EXTRA_OPTS:-}" ] ; then
  112. echo "Found environment variable DCH_EXTRA_OPTS, set to ${DCH_EXTRA_OPTS}"
  113. else
  114. DCH_EXTRA_OPTS="--new-version=${VERSION_STRING}"
  115. if [ -n "${DIST:-}" ]; then
  116. DCH_EXTRA_OPTS="${DCH_EXTRA_OPTS} --distribution ${DIST} --force-distribution"
  117. fi
  118. echo "Using extra ${GBP_DCH} options (${DCH_EXTRA_OPTS})"
  119. fi
  120. DCH_COMBINED_OPTS="${DCH_COMBINED_OPTS} ${DCH_EXTRA_OPTS}"
  121. if [ -n "${DCH_LOG_RESTRICTION:-}" ] ; then
  122. echo "Found environment variable DCH_LOG_RESTRICTION, set to ${DCH_LOG_RESTRICTION}"
  123. DCH_COMBINED_OPTS="${DCH_COMBINED_OPTS} ${DCH_LOG_RESTRICTION}"
  124. fi
  125. }
  126. # support overrides from gbp.conf
  127. gbp_conf() {
  128. if [ "${IGNORE_GBP_CONF:-}" = "true" ] ; then
  129. echo "Skipping gbp_conf execution as requested via IGNORE_GBP_CONF ***"
  130. return 0
  131. fi
  132. # List of config files in order
  133. gbp_conf_files=(
  134. /etc/git-buildpackage/gbp.conf
  135. ~/.gbp.conf
  136. .gbp.conf
  137. debian/gbp.conf
  138. .git/gbp.conf
  139. )
  140. # Defaults
  141. UPSTREAM_BRANCH="upstream"
  142. DEBIAN_BRANCH="debian"
  143. PRISTINE_TAR="false"
  144. for gbp_conf_file in "${gbp_conf_files[@]}"; do
  145. if [ -f ${gbp_conf_file} ]; then
  146. local value;
  147. value=$(git config --file ${gbp_conf_file} --get DEFAULT.upstream-branch 2>&- || true)
  148. if [ -n "${value:-}" ]; then
  149. UPSTREAM_BRANCH=${value}
  150. fi
  151. value=$(git config --file ${gbp_conf_file} --get DEFAULT.debian-branch 2>&- || true)
  152. if [ -n "${value:-}" ]; then
  153. DEBIAN_BRANCH=${value}
  154. fi
  155. value=$(git config --file ${gbp_conf_file} --bool --get DEFAULT.pristine-tar 2>&- || true)
  156. if [ -n "${value:-}" ]; then
  157. PRISTINE_TAR=${value}
  158. fi
  159. fi
  160. done
  161. }
  162. create_local_branch() {
  163. [ -n "${1:-}" ] || return 1
  164. local BRANCH="$1"
  165. if git branch -a | grep -q "remotes/origin/${BRANCH}"'$' ; then
  166. git branch -D "${BRANCH}" || true
  167. git branch "${BRANCH}" "remotes/origin/${BRANCH}"
  168. else
  169. echo "NOTE: branch $BRANCH does not exist, ignoring request to checkout therefore."
  170. fi
  171. }
  172. git_dch_auto() {
  173. if $APPLY_VERSION_WORKAROUND ; then
  174. echo "Applying version workaround workaround"
  175. dch -b --distribution=UNRELEASED --newversion=$VERSION_STRING -- \
  176. "SNAPSHOT autobuild for unreleased $ORIG_VERSION via jenkins-debian-glue."
  177. else
  178. ${GBP_DCH} --auto $DCH_COMBINED_OPTS
  179. fi
  180. }
  181. identify_latest_change() {
  182. # debian/changelog might be a symlink (e.g. because debian points to
  183. # pkg/debian), so make sure we don't access a non-existing file
  184. # by calling readlink
  185. git checkout -- $(readlink -f debian/changelog)
  186. local OLD_VERSION=$(dpkg-parsechangelog | awk '/^Version: / {print $2}')
  187. local last_tag=$(git describe $(git rev-list --tags='[^u]*' --max-count=1 HEAD))
  188. local last_merge=$(git describe $(git rev-list --all --merges --max-count=1 HEAD))
  189. local since=${last_tag}
  190. if [ -n "$last_merge" ] ; then
  191. local merge_date=$(git log ${last_merge} --pretty="format:%at" -1)
  192. local tag_date=$(git log ${last_tag} --pretty="format:%at" -1)
  193. if [ ${merge_date} -gt ${tag_date} ] ; then
  194. local since=${last_merge}
  195. fi
  196. fi
  197. echo "Latest tag [${last_tag:-}] / merge [${last_merge:-}] seems to be $since"
  198. ${GBP_DCH} -s "${since}" $DCH_COMBINED_OPTS ${DCH_CHANGELOG_FILE:-}
  199. local NEW_VERSION=$(dpkg-parsechangelog | awk '/^Version: / {print $2}')
  200. if dpkg --compare-versions "$NEW_VERSION" lt "$OLD_VERSION" ; then
  201. echo "Calculated version is older than last release, falling back to auto mode."
  202. # debian/changelog might be a symlink (e.g. because debian points to
  203. # pkg/debian), so make sure we don't access a non-existing file
  204. # by calling readlink
  205. git checkout -- $(readlink -f debian/changelog)
  206. git_dch_auto
  207. fi
  208. }
  209. branch_checkout() {
  210. # git-dch and git-buildpackage refuse to operate on a single git
  211. # commit, so instead create a temporary branch to work on
  212. random_branch="jenkins-debian-glue-buildbranch$RANDOM"
  213. if [ "${SKIP_BRANCH_AND_TAG_HANDLING:-}" = "true" ] ; then
  214. echo "*** Skipping branch/tag handling as requested via SKIP_BRANCH_AND_TAG_HANDLING ***"
  215. echo "Making sure that random_branch $random_branch does not exist"
  216. git branch -D "$random_branch" || true
  217. echo "Checking out branch $random_branch based on git commit $GIT_COMMIT"
  218. git checkout -b "$random_branch" "$GIT_COMMIT"
  219. elif [ -n "${GERRIT_PATCHSET_REVISION:-}" ] ; then
  220. echo "*** We seem to be building for Gerrit ***"
  221. echo "Making sure that random_branch $random_branch does not exist"
  222. git branch -D "$random_branch" || true
  223. echo "*** Fetching Gerrit patchsets/commits from ${GIT_URL} ***"
  224. git fetch --tags --progress ${GIT_URL} +refs/changes/*:refs/remotes/origin/*
  225. echo "Checking out branch $random_branch based on Gerrit patchset revision ${GERRIT_PATCHSET_REVISION} ***"
  226. git checkout -b "$random_branch" "$GERRIT_PATCHSET_REVISION"
  227. elif [ -n "${tag:-}" ] && [ "${tag:-}" != "none" ] ; then
  228. echo "Making sure that random_branch $random_branch does not exist"
  229. git branch -D "$random_branch" || true
  230. echo "Checking out branch $random_branch based on tag $tag"
  231. git checkout -b "$random_branch" "$tag"
  232. elif [ -n "${branch:-}" ] ; then
  233. # prepend "origin" when checking out a branch, otherwise we might be
  234. # checking out a branch which doesn't exist locally yet, failing with:
  235. # | fatal: git checkout: updating paths is incompatible with switching branches.
  236. # | Did you intend to checkout '$BRANCH' which can not be resolved as commit?
  237. local checkout_branch
  238. case "$branch" in
  239. # rewrite refs/heads/FOO to refs/remotes/origin/FOO, otherwise it fails;
  240. # the refs/heads/FOO is something e.g. github pushes through its API
  241. refs/heads/*) checkout_branch="${branch/refs\/heads/refs/remotes/origin}" ;;
  242. # keep as it is when receiving origin/* already
  243. origin/*) checkout_branch="$branch" ;;
  244. # prepend "origin/" otherwise
  245. *) checkout_branch="origin/${branch}" ;;
  246. esac
  247. echo "Making sure that random_branch $random_branch does not exist"
  248. git branch -D "$random_branch" || true
  249. echo "Checking out branch $random_branch based on branch $checkout_branch"
  250. git checkout -b "$random_branch" "$checkout_branch"
  251. else
  252. echo "Making sure that random_branch $random_branch does not exist"
  253. git branch -D "$random_branch" || true
  254. echo "Checking out branch $random_branch based on commit $GIT_COMMIT"
  255. git checkout -b "$random_branch" "$GIT_COMMIT"
  256. fi
  257. }
  258. changelog_generation() {
  259. # Allow skipping of changelog creation, e.g. to build a branch as-is
  260. if [ "${SKIP_DCH:-}" = "true" ] ; then
  261. echo "*** SKIP_DCH is set, not modifying debian/changelog therefore ***"
  262. else
  263. if [ -n "${tag:-}" ] && [ "${tag:-}" != "none" ] ; then
  264. echo "Tag parameter found (and not set to 'none'), not touching the changelog."
  265. elif [ "${1:-}" = "identify" ] ; then
  266. echo "Trying to identify latest tag / merge..."
  267. if ! git describe $(git rev-list --tags='[^u]*' --max-count=1 HEAD) >/dev/null ; then
  268. echo "Failed to identify latest change, falling back to auto mode."
  269. git_dch_auto
  270. else
  271. identify_latest_change
  272. fi
  273. elif [ -r debian/gbp.conf ] ; then
  274. echo "Found debian/gbp.conf, using ${GBP_DCH} with auto mode."
  275. git_dch_auto
  276. else
  277. echo "Using ${GBP_DCH} with auto mode."
  278. git_dch_auto
  279. fi
  280. # get rid of "UNRELEASED" distribution header, only
  281. # necessary if the debian/changelog was modified
  282. if [ -z "${tag:-}" ]; then
  283. local debchange_opts
  284. if [ -n "${DIST:-}" ]; then
  285. debchange_opts="--distribution ${DIST} --force-distribution"
  286. fi
  287. debchange --release ${debchange_opts:-} ""
  288. fi
  289. fi
  290. }
  291. git_cleanup() {
  292. if [ -n "${SKIP_GIT_CLEANUP:-}" ] ; then
  293. echo "*** Skipping git_cleanup as requested via SKIP_GIT_CLEANUP ***"
  294. return 0
  295. fi
  296. echo "*** Cleaning git repository to make sure there are no modified files ***"
  297. echo "*** Note: You can skip this step by setting SKIP_GIT_CLEANUP=true ***"
  298. git clean -fxd
  299. git reset --hard HEAD
  300. }
  301. quilt_cleanup() {
  302. if [ -n "${SKIP_QUILT_CLEANUP:-}" ] ; then
  303. echo "*** Skipping quilt_cleanup as requested via SKIP_QUILT_CLEANUP ***"
  304. return 0
  305. fi
  306. echo "*** Unapplying all possibly applied quilt patches and removing quilt directory ***"
  307. echo "*** Note: You can skip this step by setting SKIP_QUILT_CLEANUP=true ***"
  308. quilt pop -a || true
  309. rm -rf .pc
  310. }
  311. git_source_options() {
  312. #Unless otherwise specified in the debian/source/options
  313. # restrict git source archive depth and limit to only the branch we build.
  314. if [ -z "${GIT_DEPTH:-}" ]; then
  315. GIT_DEPTH=50
  316. fi
  317. local file
  318. local value
  319. local opt_depth
  320. local opt_ref
  321. file="debian/source/options"
  322. if [ -f ${file} ]; then
  323. opt_depth=$(git config --file ${file} --get git-depth 2>&- || true)
  324. opt_ref=$(git config --file ${file} --get git-ref 2>&- || true)
  325. if [ -z "${opt_depth:-}" ]; then
  326. echo "Using source depth of $opt_depth as defined in debian/source/options"
  327. $GIT_DEPTH=${opt_depth}
  328. fi
  329. if [ -z "${opt_ref:-}" ]; then
  330. echo "Adding git source ref: ${opt_ref}"
  331. DBP_EXTRA_OPTS="${DBP_EXTRA_OPTS:-} --source-option=--git-ref=${opt_ref}"
  332. fi
  333. fi
  334. "Setting git depth to $GIT_DEPTH"
  335. DBP_EXTRA_OPTS="${DBP_EXTRA_OPTS:-} --source-option=--git-depth=$GIT_DEPTH"
  336. }
  337. source_format_opts() {
  338. if ! [ -f "debian/source/format" ] ; then
  339. echo '*** WARNING: Source format is not specified in debian/source/format! ***'
  340. return 0
  341. fi
  342. local SRC_FORMAT="$(cat debian/source/format)"
  343. case "$SRC_FORMAT" in
  344. '3.0 (quilt)')
  345. echo "*** Source format detected as 3.0 (quilt) ***";
  346. DBP_EXTRA_OPTS="${DBP_EXTRA_OPTS:-} --source-option=--unapply-patches"
  347. ;;
  348. '3.0 (git)')
  349. echo "*** Source format detected as 3.0 (git) ***"
  350. PRISTINE_TAR=false
  351. SKIP_QUILT_CLEANUP=true
  352. IGNORE_GIT_BUILDPACKAGE=true
  353. git_source_options
  354. ;;
  355. '3.0 (native)')
  356. echo "*** Source format detected as 3.0 (native) ***"
  357. ;;
  358. '3.0')
  359. echo "*** Source format detected as 3.0 ***"
  360. ;;
  361. '1.0')
  362. echo "*** Source format detected as 1.0 ***"
  363. SKIP_QUILT_CLEANUP=true
  364. ;;
  365. *)
  366. echo "*** WARNING: invalid or unknown source format: ${SRC_FORMAT} ***"
  367. ;;
  368. esac
  369. }
  370. # main execution
  371. echo "*** source package build phase ***"
  372. rm -f ./* || true
  373. if [ -n "${PRE_SOURCE_HOOK:-}" ] ; then
  374. echo "*** Found environment variable PRE_SOURCE_HOOK, set to ${PRE_SOURCE_HOOK:-} ***"
  375. sh ${PRE_SOURCE_HOOK:-}
  376. fi
  377. cd "$SOURCE_DIRECTORY"
  378. git_cleanup
  379. source_format_opts
  380. # Only if we are using git-buildpackage...
  381. if [ "${IGNORE_GIT_BUILDPACKAGE:-}" != "true" ] ; then
  382. # gbp.conf handling
  383. gbp_conf
  384. # make sure common branches are available for git-buildpackage
  385. create_local_branch ${UPSTREAM_BRANCH}
  386. create_local_branch ${DEBIAN_BRANCH}
  387. if [ ${PRISTINE_TAR} = 'true' ]; then
  388. create_local_branch pristine-tar
  389. fi
  390. fi
  391. # check out the according branch/tag with help of $random_branch
  392. branch_checkout
  393. if [ -n "${PRE_DCH_HOOK:-}" ] ; then
  394. echo "*** Found environment variable PRE_DCH_HOOK, set to ${PRE_DCH_HOOK:-} ***"
  395. sh ${PRE_DCH_HOOK:-}
  396. fi
  397. # retrieve version information *after* checking out the according branch/tag,
  398. # otherwise version number might result in something different than expected
  399. version_information
  400. # handling of debian/changelog
  401. dch_opts
  402. changelog_generation
  403. # prepare orig.tar.gz using pristine-tar, but without actually building the source package
  404. if [ "${IGNORE_GIT_BUILDPACKAGE:-}" = "true" ] ; then
  405. echo "Skipping git-buildpackage execution as requested via IGNORE_GIT_BUILDPACKAGE ***"
  406. else
  407. gbp_opts # set $GBP_OPTS
  408. ${GBP_BUILDPACKAGE} ${GBP_OPTS:-}
  409. fi
  410. quilt_cleanup
  411. # build source package, run before switching back to previous branch
  412. # to get the actual requested version
  413. dpkg-buildpackage -uc -us -nc -d -S -i -I ${DBP_EXTRA_OPTS:-}
  414. if [ -n "${KEY_ID:-}" ] ; then
  415. echo "*** Found environment variable KEY_ID, set to ${KEY_ID:-}, signing source package ***"
  416. if ! [ -x "$(which debsign)" ] ; then
  417. echo "Error: debsign not available, please make sure the devscripts package is installed." >&2
  418. exit 1
  419. fi
  420. debsign -k"${KEY_ID:-}" ../*_source.changes
  421. fi
  422. if [ -n "${KEEP_SOURCE_CHANGES:-}" ]; then
  423. echo "*** Not removing ../*_source.changes because KEEP_SOURCE_CHANGES is set ***"
  424. else
  425. echo "*** Removing ../*_source.changes because KEEP_SOURCE_CHANGES is not set ***"
  426. # get rid of the *_source.changes files generated by dpkg-buildpackage,
  427. # to avoid failures in a later stage when copying *all* files around
  428. rm -f ../*_source.changes
  429. fi
  430. # revert to original debian/changelog to avoid merge conflicts
  431. git checkout -- $(readlink -f debian/changelog)
  432. git checkout -f ${GIT_BRANCH} # switch back to previous "branch" before removing the tmp branch
  433. git branch -D "$random_branch"
  434. # vim:foldmethod=marker ts=2 ft=sh ai expandtab sw=2