Explorar el Código

Rewrite __release blocking condition system

New "functional-like" design makes it simpler to understand, extend,
re-order and re-use blocking conditions.

Also, the "old looks newer" condition was dropped as it's not really
necessary under such simplistic conditions.
Alois Mahdal hace 10 años
padre
commit
fe1646c7e2
Se han modificado 1 ficheros con 81 adiciones y 30 borrados
  1. 81
    30
      src/include/release.sh

+ 81
- 30
src/include/release.sh Ver fichero

@@ -1,5 +1,75 @@
1 1
 #!/bin/bash
2 2
 
3
+__die_if() {
4
+    #
5
+    # Die if blocking condition $1 is detected
6
+    #
7
+    local condition="$1"
8
+    local x
9
+    case "$condition" in
10
+        nogit)
11
+            git rev-parse HEAD >&/dev/null\
12
+             || die "cannot do this outside git repo"
13
+            ;;
14
+        norelbr)
15
+            __git_info curbranch \
16
+              | grep -qFx "$RELSRC" \
17
+             || die "you are not on RELSRC branch: $RELSRC"
18
+            ;;
19
+        dirty)
20
+            git diff --shortstat 2>/dev/null \
21
+              | grep -q . \
22
+             && die "tree is dirty: $dirt"
23
+            ;;
24
+        novertag)
25
+            __git_info lasttag \
26
+              | grep -q . \
27
+             || die "cannot find last tag"
28
+            ;;
29
+        nobump)
30
+            git diff-tree --no-commit-id --name-only -r HEAD \
31
+              | grep -qFx config.mk \
32
+             || die "last change must be version bump in config.mk"
33
+            ;;
34
+        wip)
35
+            __git_info reldiff \
36
+              | grep '^....... WIP ' \
37
+             && die "WIP commit since $(__git_info lasttag)"
38
+            ;;
39
+        old_c)
40
+            x=$(__ver_info nextver_g)
41
+            __ver_info currver_c \
42
+              | grep -qFx "$x" config.mk \
43
+             || die "new version not in config.mk: $x"
44
+            ;;
45
+    esac
46
+}
47
+
48
+__git_info() {
49
+    #
50
+    # Get git info $1
51
+    #
52
+    local info="$1"
53
+    case "$info" in
54
+        lasttag)    git tag | grep ^v | sort -V | tail -n1  ;;
55
+        curbranch)  git rev-parse --abbrev-ref HEAD         ;;
56
+        reldiff)    git log --oneline "$(__git_info lasttag)..HEAD" ;;
57
+    esac
58
+}
59
+
60
+__ver_info() {
61
+    #
62
+    # Get git info $1
63
+    #
64
+    local info="$1"
65
+    case "$info" in
66
+        lastver_g)  __git_info lasttag | sed s/v$// ;;
67
+        nextver_g)  __make_ver "$level" "$(__ver_info lastver_g)" ;;
68
+        currver_c)  grep -m 1 -w VERSION config.mk | cut -d = -f 2 | xargs echo ;;
69
+        nextver_c)  __make_ver "$level" "$(__ver_info currver_c)" ;;
70
+    esac
71
+}
72
+
3 73
 __make_ver() {
4 74
     local level=$1
5 75
     local old=$2
@@ -27,41 +97,22 @@ __release() {
27 97
     #        compatible with this release strategy
28 98
     #
29 99
     local level=$1
30
-    git rev-parse HEAD >&/dev/null || die "cannot release outside git repo"
31
-    local lastfile=$(git diff-tree --no-commit-id --name-only -r HEAD)
32
-    local lasttag=$(git tag | grep ^v | sort -V | tail -n1)
33
-    local changelog="$(git log --oneline "$lasttag..HEAD")"
34
-    local curbranch=$(git rev-parse --abbrev-ref HEAD)
35
-    local dirt="$(git diff --shortstat 2>/dev/null)"
36
-
37
-    local newver=$(__make_ver "$level" "${lasttag#v}")
38
-    local newtag=v$newver
39
-    local higher=$(echo -e "$oldtag\n$newtag" | sort -V | tail -n1)
40
-
41
-    test "$lastfile" = config.mk \
42
-     || die "last change must be version bump in config.mk"
43
-
44
-    test -n "$lasttag" \
45
-     || die "cannot find last tag"
46
-
47
-    test "$newtag" = "$higher" \
48
-     || die "generated tag looks older: $oldtag<$newtag"
49
-
50
-    grep -qw "$newver" config.mk \
51
-     || die "new version not in config.mk: $newver"
52
-
53
-    grep '^....... WIP ' <<<"$changelog" \
54
-     && die "WIP commit since $lasttag"
55
-
56
-    grep -qw "$curbranch" <<<"$RELSRC" \
57
-     || die "you are not on RELSRC branch: $RELSRC"
100
+    local newtag
58 101
 
59
-    test -z "$dirt" \
60
-     || die "tree is dirty: $dirt"
102
+    __die_if nogit
103
+    __die_if norelbr
104
+    __die_if dirty
105
+    __die_if novertag
106
+    __die_if nobump
107
+    __die_if wip
108
+    __die_if old_c
61 109
 
62 110
     # FIXME: Have user prepare proper message with changelog
63 111
 
112
+    newtag=v$(__ver_info nextver_g)
64 113
     set -e
114
+    debug_var newtag
115
+    $MKIT_DRY && return
65 116
     git tag -m "$MKIT_PROJNAME $newtag - $CODENAME" "$newtag"
66 117
     git branch -f "$RELDST" "$newtag"
67 118
 }