commit-msg 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/bin/bash
  2. # git-packaging-hooks - git hooks to semi-automate releases and distro packaging
  3. #
  4. # Copyright 2017 bill-auger <https://github.com/bill-auger/git-packaging-hooks/issues>
  5. #
  6. # git-packaging-hooks is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License version 3 as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # git-packaging-hooks is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License version 3
  17. # along with git-packaging-hooks. If not, see <http://www.gnu.org/licenses/>.
  18. readonly HOOKS_PATH=$(git config --local core.hooksPath)
  19. readonly COMMON_DEFS_FILE=$HOOKS_PATH/common.sh.inc
  20. source $COMMON_DEFS_FILE
  21. [ ! -f $COMMON_DEFS_FILE ] && TraceError "missing $COMMON_DEFS_FILE - aborting commit" && exit 1
  22. if (($IS_STAGING_BRANCH))
  23. then (($IS_EMPTY_COMMIT_MSG)) && TraceError "empty commit message - aborting commit" && exit 1
  24. TraceStage "running staging-specific pre-commit hooks"
  25. # prune existing minor version tag on HEAD and store for the post stage
  26. orphaned_tags=$(git tag --points-at HEAD)
  27. if (($IS_AMEND_COMMIT)) && [ "$MINOR_VERSION_REF" == "$HEAD_REF" ]
  28. then TraceStep "preserving orphaned tags: $orphaned_tags"
  29. git tag --delete $orphaned_tags
  30. echo "$MINOR_VERSION_TAG $VERSION_STRING $orphaned_tags" | tr " " "\n" > $TAGS_FILE
  31. fi
  32. # inject version string into build files
  33. TraceStep "upgrading version to '$VERSION_STRING'"
  34. ac_init_params="[$UPSTREAM_NAME], [$VERSION], [${BUG_URL//\//\\\/}]"
  35. sed --in-place "s/^AC_INIT(.*$/AC_INIT($ac_init_params)/" $VERSION_FILE
  36. TraceStage "completed staging-specific pre-commit hooks"
  37. elif (($IS_PACKAGING_BRANCH))
  38. then # assert that the packaging branch is properly rebased atop the greatest version tag
  39. if [ "$LAST_REVISION_TAG" != "$HIGHEST_REV_TAG" ]
  40. then TraceError "aborting commit" \
  41. " The greatest revision tag '$HIGHEST_REV_TAG' is not reachable." \
  42. " The greatest reachable revision tag is '$LAST_REVISION_TAG'." \
  43. " Did you forget to rebase?"
  44. exit 1
  45. elif (($IS_AMEND_COMMIT)) && [ "$LAST_REVISION_REF" == "$HEAD_REF" ]
  46. then TraceError "aborting amend commit" \
  47. " This commit would detach the packaging branch from" \
  48. " the greatest reachable revision tag '$LAST_REVISION_TAG'." \
  49. " Did you forget to rebase?"
  50. exit 1
  51. else (($IS_AMEND_COMMIT)) && exit 0
  52. fi
  53. TraceStage "running packaging-specific pre-commit hooks"
  54. # cleanup any transient files
  55. TraceStep "preparing the packaging environment"
  56. rm $TARBALL_FILE 2> /dev/null
  57. for remote_file in ${CLEANUP_FILES[@]} ; do rm $remote_file 2> /dev/null ; done ;
  58. # inject version string into packaging files
  59. TraceStep "updating packaging files to latest version"
  60. for template_file in ${TEMPLATE_FILES[@]} ; do cp ${template_file}.in $template_file ; done ;
  61. sed --in-place "s/\"path\">.*</\"path\">$OBS_TARBALL_PATH</" $SERVICE_FILE
  62. sed --in-place "s/^Version:.*$/Version: $VERSION/" $SPEC_FILE
  63. echo "%changelog" >> $SPEC_FILE
  64. echo "* $(date '+%a %b %d %Y') $GIT_USER" >> $SPEC_FILE
  65. echo "- $VERSION_STRING" >> $SPEC_FILE
  66. for dsc_file in ${DSC_FILES[@]}
  67. do sed --in-place "s/^Version:.*$/Version: $VERSION-1/" $dsc_file
  68. done
  69. sed --in-place "s/^pkgver=.*$/pkgver=$VERSION/" $PKGBUILD_FILE
  70. # sed --in-place "s/^validpgpkeys=.*$/validpgpkeys=('$GPG_KEY')/" $PKGBUILD_FILE
  71. TraceStep "validating packaging environment"
  72. # ensure valid changelog entry exists
  73. if ! grep "(${VERSION}-1)" debian/changelog > /dev/null
  74. then dch --package $DEBIAN_NAME --newversion ${VERSION}-1 $CHANGELOG_MESSAGE 2> /dev/null
  75. (($?)) && TraceError "debian/changelog version conflict" && exit 1
  76. fi
  77. # mirror debian-specific obs files in obs directory
  78. for debian_file in ${DEBIAN_FILES[@]}
  79. do cp debian/$(basename debian_file) $OBS_DIR/debian.$(basename debian_file) &> /dev/null
  80. done
  81. # validations
  82. for debian_file in ${DEBIAN_FILES[@]} ; do [ -f $debian_file ] || exit 1 ; done ;
  83. for obs_file in ${OBS_FILES[@]} ; do [ -f $obs_file ] || exit 1 ; done ;
  84. (($IS_EMPTY_COMMIT_MSG)) && echo "[EMPTY COMMIT MSG]" > $GIT_COMMIT_MSG_FILE
  85. git add --all
  86. TraceStage "completed packaging-specific pre-commit hooks"
  87. fi