Script to trigger re-build of slop - https://github.com/naelstrof/slop

trigger_copr 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/bin/bash
  2. warn() {
  3. echo "$1" >&2
  4. }
  5. die() {
  6. warn "fatal: $1"
  7. exit 3
  8. }
  9. usage() {
  10. warn "usage: $0 [options] COPR_PROJECT"
  11. warn ""
  12. warn "Options:"
  13. warn ""
  14. warn " -n dry mode, don't do anything (just show"
  15. warn " what would be done)"
  16. warn " -r REL use REL as Release number in SPEC file"
  17. warn " -v VER use VER as Version number in SPEC file"
  18. warn " -u URL use URL as base (to get last tag and"
  19. warn " compose Source0 in SPEC file)"
  20. warn ""
  21. warn "If -r or -v are not specified, git-describe master"
  22. warn "is consulted."
  23. exit 2
  24. }
  25. last_version() {
  26. git ls-remote --tag "$UrlBase" \
  27. | grep '/tags/' \
  28. | cut -d/ -f3 \
  29. | sort -V \
  30. | tail -1 \
  31. | sed "s/^v//"
  32. }
  33. trigger() {
  34. sed -e "
  35. /^Version/ s|__SLOP_VERSION__|$Version|
  36. /^Release/ s|__SLOP_RELEASE__|$Release|
  37. /^Source0/ s|__SLOP_URLBASE__|$UrlBase|
  38. " <slop.spec.in >"$Tmp/slop.spec"
  39. copr build --nowait "$CoprProject" "$Tmp/slop.spec"
  40. }
  41. git_guess() {
  42. #
  43. # Print git-guessed $1
  44. #
  45. local what=$1 # what we want (ver|rel)
  46. local describe # full git-describe output
  47. local xtra= # extra part (-N-gHASH)
  48. local num=0 # num. of commits since tag (N)
  49. local sha= # '.g'+sha1 of this commit (gHASH)
  50. describe=$(git describe --tags --always HEAD)
  51. case $describe in
  52. *-*) # v1.2.3-21-g654cba
  53. tag=${describe%%-*} # tag=v1.2.3
  54. xtra=${describe#$tag-} # xtra=-21-g654cba
  55. num=${xtra%%-*} # num=21
  56. sha=.${xtra#$num-} # sha=.g654cba
  57. ;;
  58. *)
  59. tag=$describe
  60. ;;
  61. esac
  62. case $what in
  63. ver) echo "${tag#v}" ;;
  64. rel) echo "$((num + 1))$sha" ;;
  65. esac
  66. }
  67. main() {
  68. local Version # Version in SPEC file
  69. local Release # Release in SPEC file
  70. local CoprProject # COPR project
  71. local UrlBase # GitHub URL base
  72. local Tmp # our temp
  73. local Branch # branch to use, if empty, tags are considered
  74. local DryRun=false # do not do anything
  75. UrlBase=https://github.com/AloisMahdal/slop
  76. Tmp=$(mktemp -d)
  77. while true; do case $1 in
  78. -b) Branch=$2; shift 2 || usage ;;
  79. -u) UrlBase=$2; shift 2 || usage ;;
  80. -r) Release=$2; shift 2 || usage ;;
  81. -v) Version=${2#v}; shift 2 || usage ;;
  82. -n) DryRun=true; shift ;;
  83. -*) usage ;;
  84. *) break ;;
  85. esac done
  86. CoprProject=$1
  87. test -n "$CoprProject" || usage
  88. which copr >/dev/null \
  89. || die "copr not found, try 'sudo install python-copr'"
  90. if test -n "$Branch"; then
  91. die "not implemented"
  92. test -n "$Version" || Version=$(git_guess ver)
  93. test -n "$Release" || Release=$(git_guess rel)
  94. else
  95. test -n "$Version" || Version=$(last_version)
  96. test -n "$Release" || Release=1
  97. fi
  98. $DryRun && {
  99. warn "dry mode active, we would build:"
  100. warn " at $CoprProject"
  101. test -n "$Branch" && warn " using branch $Branch"
  102. test -n "$Branch" || warn " using last tag"
  103. warn " from $UrlBase"
  104. warn " yielding slop-$Version-$Release.*.rpm"
  105. exit 1
  106. }
  107. trigger
  108. rm -rf "$Tmp"
  109. }
  110. main "$@"