Browse Source

Initial commit

Alois Mahdal 6 years ago
commit
71ea28516c
5 changed files with 282 additions and 0 deletions
  1. 4
    0
      Makefile
  2. 4
    0
      README.md
  3. 221
    0
      trigger_copr
  4. 41
    0
      ydiff.spec.in
  5. 12
    0
      ydiff.trigger

+ 4
- 0
Makefile View File

@@ -0,0 +1,4 @@
1
+#!/usr/bin/make -f
2
+
3
+rpmstuff:
4
+	./trigger_copr -a rpmstuff main

+ 4
- 0
README.md View File

@@ -0,0 +1,4 @@
1
+README
2
+======
3
+
4
+This repo contains script to build `ydiff` at my Fedora COPR.

+ 221
- 0
trigger_copr View File

@@ -0,0 +1,221 @@
1
+#!/bin/bash
2
+
3
+TRIGGER_COPR_CONFIG=${TRIGGER_COPR_CONFIG:-}
4
+TRIGGER_COPR_PKGNAME=${TRIGGER_COPR_PKGNAME:-}
5
+
6
+warn() {
7
+    echo "$1" >&2
8
+}
9
+
10
+die() {
11
+    warn "fatal: $1"
12
+    exit 3
13
+}
14
+
15
+usage() {
16
+    warn "usage: $0 [options] MODE"
17
+    warn ""
18
+    warn "Options:"
19
+    warn ""
20
+    warn "  -b BRN  build from branch BRN (default: last tag)"
21
+    warn "  -c COPR_PROJECT  COPR project name"
22
+    warn "  -C CONF   config file"
23
+    warn "  -n      dry mode, don't do anything (just show"
24
+    warn "          what would be done)"
25
+    warn "  -r REL  use REL as Release number in SPEC file"
26
+    warn "  -v VER  use VER as Version number in SPEC file"
27
+    warn "  -u URL  use URL as base (to get last tag and"
28
+    warn "          compose Source0 in SPEC file)"
29
+    warn ""
30
+    warn "If -b is not used, build is launched from last tag available"
31
+    warn "in the GitHub repo.  In that case, Release is '1' and Version"
32
+    warn "is deduced from the tag by removing the initial 'v'."
33
+    warn ""
34
+    warn "If -b is used, the project repo is temporarily cloned, and"
35
+    warn "both Version and Release are found by consulting git-describe"
36
+    warn "on the specified branch."
37
+    warn ""
38
+    warn "If MODE is 'scratch' (default), Release is pre-fixed by string"
39
+    warn "'0.scratch.' and build is triggered in scratch COPR project."
40
+    exit 2
41
+}
42
+
43
+last_version() {
44
+    git ls-remote --tag "$UrlBase" \
45
+      | grep '/tags/' \
46
+      | cut -d/ -f3 \
47
+      | grep -v '[^0-9a-z.]' \
48
+      | sort -V \
49
+      | tail -1 \
50
+      | sed "s/^v//"
51
+}
52
+
53
+mkspec() {
54
+    local self_version
55
+    local cl_date
56
+    self_version="$(basename "$0") $(git describe --tags)"
57
+    cl_date=$(LC_ALL=C date +"%a %b %d %Y")
58
+    sed -e "
59
+        s|__APP_VERSION__|$Version|
60
+        s|__APP_RELEASE__|$Release|
61
+        s|__APP_URLBASE__|$UrlBase|
62
+        s|__APP_BUILDSCRIPT_VERSION__|$self_version|
63
+        s|__APP_DATE__|$cl_date|
64
+    " <"$PkgName.spec.in"
65
+}
66
+
67
+git_guess() {
68
+    #
69
+    # Print git-guessed $1
70
+    #
71
+    local what=$1   # what we want (ver|rel)
72
+    local describe  # full git-describe output
73
+    local xtra=     # extra part (-N-gHASH)
74
+    local num=0     # num. of commits since tag (N)
75
+    local sha=      # '.g'+sha1 of this commit (gHASH)
76
+    describe=$(git describe --tags --always HEAD)
77
+    case $describe in
78
+        *-*)                        #     v1.2.3-21-g654cba
79
+            tag=${describe%%-*}     # tag=v1.2.3
80
+            xtra=${describe#$tag-}  # xtra=-21-g654cba
81
+            num=${xtra%%-*}         # num=21
82
+            sha=.${xtra#$num-}      # sha=.g654cba
83
+            ;;
84
+        *)
85
+            tag=$describe
86
+            ;;
87
+    esac
88
+    case $what in
89
+        ver)    echo "${tag#v}"         ;;
90
+        rel)    echo "$((num + 1))$sha" ;;
91
+    esac
92
+}
93
+
94
+choose_relpfx() {
95
+    #
96
+    # Choose COPR project based on $Mode
97
+    #
98
+    test "$Mode" == scratch && echo 0.scratch.
99
+    return 0
100
+}
101
+
102
+read_conffile() {
103
+    #
104
+    # Read item T
105
+    #
106
+    local what=$1
107
+    local fieldn
108
+    case $what in
109
+        urlbase) fieldn=2 ;;
110
+        copr)    fieldn=3 ;;
111
+    esac
112
+    grep -v '^[[:blank:]]*#' "$ConfFile" \
113
+      | grep "^ *$Mode\>" \
114
+      | sed 's/  */ /g' \
115
+      | cut -d' ' -f$fieldn
116
+}
117
+
118
+choose_conffile() {
119
+    #
120
+    # Find config file and echo its name
121
+    #
122
+    find . -name '*.trigger' \
123
+      | cut -d/ -f2 \
124
+      | grep .
125
+}
126
+
127
+do_action() {
128
+    local url
129
+    case $Action in
130
+        build)
131
+            copr build "$CoprProject" "$Tmp/$PkgName.spec"
132
+            printf '\a'
133
+            ;;
134
+        demo)
135
+            warn "demo mode active, we would build:"
136
+            warn "    at $CoprProject"
137
+            test -n "$Branch" && warn "    using branch $Branch"
138
+            test -n "$Branch" || warn "    using last tag"
139
+            warn "    from $UrlBase"
140
+            warn "    yielding $PkgName-$Version-$Release.*.rpm"
141
+            warn ""
142
+            warn "===== BEGIN $PkgName.spec ====="
143
+            cat "$Tmp/$PkgName.spec"
144
+            warn "===== END $PkgName.spec ====="
145
+            return 1
146
+            ;;
147
+        mkspec)
148
+            cat "$Tmp/$PkgName.spec"
149
+            ;;
150
+        rpmstuff)
151
+            url=$(
152
+                grep -o 'Source.*:.*http.*' "$Tmp/$PkgName.spec" \
153
+                  | sed "
154
+                        s/.*http/http/
155
+                        s/ *$//
156
+                        s/%{version}/$Version/g
157
+                        s/%{name}/$PkgName/g
158
+                    "
159
+            )
160
+            wget --quiet "$url"
161
+            cat "$Tmp/$PkgName.spec" > "$PkgName.spec"
162
+            ;;
163
+    esac
164
+}
165
+
166
+main() {
167
+    local Version       # Version in SPEC file
168
+    local Release       # Release in SPEC file
169
+    local CoprProject   # COPR project
170
+    local UrlBase       # GitHub URL base
171
+    local Tmp           # our temp
172
+    local Branch        # branch to use, if empty, tags are considered
173
+    local Mode=scratch  # implies COPR project and release prefix
174
+    local Action=build  # what to do
175
+    local ConfFile      # config file to use
176
+    local PkgName       # package name
177
+    local es=0          # exit status
178
+    which copr >/dev/null \
179
+     || die "copr not found, try 'sudo install copr-cli'"
180
+    Tmp=$(mktemp -d)
181
+    while true; do case $1 in
182
+        -C) ConfFile=$2;    shift 2 || usage ;;
183
+        -a) Action=$2;      shift 2 || usage ;;
184
+        -b) Branch=$2;      shift 2 || usage ;;
185
+        -c) CoprProject=$2; shift 2 || usage ;;
186
+        -u) UrlBase=$2;     shift 2 || usage ;;
187
+        -r) Release=$2;     shift 2 || usage ;;
188
+        -v) Version=${2#v}; shift 2 || usage ;;
189
+        -n) Action=demo;    shift ;;
190
+        -*) usage ;;
191
+        *)  break ;;
192
+    esac done
193
+    Mode=${1:-$Mode}
194
+    case $Action in
195
+        build|demo|mkspec|rpmstuff) : ;;
196
+        *) usage ;;
197
+    esac
198
+    test -n "$ConfFile" || ConfFile=$TRIGGER_COPR_CONFIG
199
+    test -n "$ConfFile" || ConfFile=$(choose_conffile)
200
+    test -n "$ConfFile" || die "could not find config file"
201
+    test -r "$ConfFile" || die "could not read config file"
202
+    test -n "$PkgName"  || PkgName=$TRIGGER_COPR_PKGNAME
203
+    test -n "$PkgName"  || PkgName=${ConfFile%.trigger}
204
+    test -n "$CoprProject" || CoprProject=$(read_conffile copr)
205
+    test -n "$UrlBase"     || UrlBase=$(read_conffile urlbase)
206
+    if test -n "$Branch"; then
207
+        die "not implemented"
208
+        test -n "$Version" || Version=$(git_guess ver)
209
+        test -n "$Release" || Release=$(git_guess rel)
210
+    else
211
+        test -n "$Version" || Version=$(last_version)
212
+        test -n "$Release" || Release=1
213
+    fi
214
+    Release=$(choose_relpfx)$Release
215
+    mkspec >"$Tmp/$PkgName.spec"
216
+        do_action
217
+    rm -rf "$Tmp"
218
+    return $es
219
+}
220
+
221
+main "$@"

+ 41
- 0
ydiff.spec.in View File

@@ -0,0 +1,41 @@
1
+Name:       ydiff
2
+Version:    __APP_VERSION__
3
+Release:    __APP_RELEASE__%{?dist}
4
+Summary:    View colored, incremental diff
5
+URL:        https://github.com/ymattw/ydiff
6
+License:    BSD-3
7
+Source0:    __APP_URLBASE__/archive/%{version}/%{name}-%{version}.tar.gz
8
+BuildRequires: python2-devel
9
+
10
+Requires: less
11
+%description
12
+Term based tool to view colored, incremental diff in a Git/Mercurial/Svn
13
+workspace or from stdin, with side by side (similar to diff -y) and auto
14
+pager support.
15
+
16
+%package -n python2-%{name}
17
+Summary: %{summary}
18
+%description -n python2-%{name}
19
+Python library that implements API used by ydiff tool.
20
+
21
+%prep
22
+%setup -q
23
+
24
+%build
25
+%py2_build
26
+
27
+%install
28
+%py2_install
29
+
30
+%files
31
+%{_bindir}/ydiff
32
+
33
+%files -n python2-%{name}
34
+%{python2_sitelib}/%{name}/
35
+%{python2_sitelib}/%{name}-*.egg-info
36
+
37
+%changelog
38
+* __APP_DATE__ Alois Mahdal <netvor+ydiff@vornet.cz> - __APP_VERSION__-__APP_RELEASE__
39
+- Unofficial experimental RPM pseudo-release
40
+
41
+# spec file generated from __APP_BUILDSCRIPT_VERSION__

+ 12
- 0
ydiff.trigger View File

@@ -0,0 +1,12 @@
1
+# list of mode data
2
+#
3
+# Format:
4
+#
5
+#   *  MODE is mode name
6
+#   *  URLBASE is GitHub address to get latest source from
7
+#   *  COPR is COPR project name,
8
+#
9
+#
10
+# MODE   URLBASE                                COPR
11
+scratch  https://gitea.vornet.cz/netvor/ydiff   netvor/ydiff-scratch
12
+main     https://github.com/ymattw/ydiff        netvor/ydiff