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

trigger_copr 3.7KB

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