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

trigger_copr 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. mkspec() {
  40. local self_version
  41. local cl_date
  42. self_version="slop-build-copr $(git describe --tags)"
  43. cl_date=$(LC_ALL=C date +"%a %b %d %Y")
  44. sed -e "
  45. s|__SLOP_VERSION__|$Version|
  46. s|__SLOP_RELEASE__|$Release|
  47. s|__SLOP_URLBASE__|$UrlBase|
  48. s|__SLOP_BUILDSCRIPT_VERSION__|$self_version|
  49. s|__SLOP_DATE__|$cl_date|
  50. " <slop.spec.in
  51. }
  52. git_guess() {
  53. #
  54. # Print git-guessed $1
  55. #
  56. local what=$1 # what we want (ver|rel)
  57. local describe # full git-describe output
  58. local xtra= # extra part (-N-gHASH)
  59. local num=0 # num. of commits since tag (N)
  60. local sha= # '.g'+sha1 of this commit (gHASH)
  61. describe=$(git describe --tags --always HEAD)
  62. case $describe in
  63. *-*) # v1.2.3-21-g654cba
  64. tag=${describe%%-*} # tag=v1.2.3
  65. xtra=${describe#$tag-} # xtra=-21-g654cba
  66. num=${xtra%%-*} # num=21
  67. sha=.${xtra#$num-} # sha=.g654cba
  68. ;;
  69. *)
  70. tag=$describe
  71. ;;
  72. esac
  73. case $what in
  74. ver) echo "${tag#v}" ;;
  75. rel) echo "$((num + 1))$sha" ;;
  76. esac
  77. }
  78. main() {
  79. local Version # Version in SPEC file
  80. local Release # Release in SPEC file
  81. local CoprProject # COPR project
  82. local UrlBase # GitHub URL base
  83. local Tmp # our temp
  84. local Branch # branch to use, if empty, tags are considered
  85. local DryRun=false # do not do anything
  86. UrlBase=https://github.com/AloisMahdal/slop
  87. Tmp=$(mktemp -d)
  88. while true; do case $1 in
  89. -b) Branch=$2; shift 2 || usage ;;
  90. -u) UrlBase=$2; shift 2 || usage ;;
  91. -r) Release=$2; shift 2 || usage ;;
  92. -v) Version=${2#v}; shift 2 || usage ;;
  93. -n) DryRun=true; shift ;;
  94. -*) usage ;;
  95. *) break ;;
  96. esac done
  97. CoprProject=$1
  98. test -n "$CoprProject" || usage
  99. which copr >/dev/null \
  100. || die "copr not found, try 'sudo install python-copr'"
  101. if test -n "$Branch"; then
  102. die "not implemented"
  103. test -n "$Version" || Version=$(git_guess ver)
  104. test -n "$Release" || Release=$(git_guess rel)
  105. else
  106. test -n "$Version" || Version=$(last_version)
  107. test -n "$Release" || Release=1
  108. fi
  109. mkspec >"$Tmp/slop.spec"
  110. $DryRun && {
  111. warn "dry mode active, we would build:"
  112. warn " at $CoprProject"
  113. test -n "$Branch" && warn " using branch $Branch"
  114. test -n "$Branch" || warn " using last tag"
  115. warn " from $UrlBase"
  116. warn " yielding slop-$Version-$Release.*.rpm"
  117. warn ""
  118. warn "===== BEGIN slop.spec ====="
  119. cat "$Tmp/slop.spec"
  120. warn "===== END slop.spec ====="
  121. exit 1
  122. }
  123. copr build --nowait "$CoprProject" "$Tmp/slop.spec"
  124. rm -rf "$Tmp"
  125. }
  126. main "$@"