Browse Source

Update mkit from fastfoo v0.6.3

Alois Mahdal 10 years ago
parent
commit
9052f30d23
7 changed files with 117 additions and 44 deletions
  1. 10
    0
      Makefile
  2. 2
    1
      config.mk
  3. 2
    1
      mkit/config.ini
  4. 27
    20
      mkit/include/build.sh
  5. 1
    18
      mkit/include/ini.sh
  6. 13
    4
      mkit/include/mkit.sh
  7. 62
    0
      mkit/include/release.sh

+ 10
- 0
Makefile View File

8
 options:
8
 options:
9
 	@echo saturnin build options:
9
 	@echo saturnin build options:
10
 	@echo "VERSION  = ${VERSION}"
10
 	@echo "VERSION  = ${VERSION}"
11
+	@echo "PRERELEASE = ${PRERELEASE}"
11
 	@echo "PREFIX   = ${PREFIX}"
12
 	@echo "PREFIX   = ${PREFIX}"
12
 
13
 
13
 build:
14
 build:
25
 install: all
26
 install: all
26
 	@mkit/make install
27
 	@mkit/make install
27
 
28
 
29
+release_x:
30
+	@mkit/make release_x
31
+
32
+release_y:
33
+	@mkit/make release_y
34
+
35
+release_z:
36
+	@mkit/make release_z
37
+
28
 uninstall:
38
 uninstall:
29
 	@mkit/make uninstall
39
 	@mkit/make uninstall
30
 
40
 

+ 2
- 1
config.mk View File

1
 VERSION = 0.0.15
1
 VERSION = 0.0.15
2
-STAGE = devel
2
+RELSRC = master
3
+RELDST = last
3
 PREFIX=/usr/local
4
 PREFIX=/usr/local

+ 2
- 1
mkit/config.ini View File

1
 
1
 
2
 [ENV]
2
 [ENV]
3
 
3
 
4
-    PROJNAME = saturnin
4
+    PKGNAME = saturnin
5
+    PROJNAME = Saturnin
5
     PREFIX = /usr
6
     PREFIX = /usr
6
 
7
 
7
 [lists]
8
 [lists]

+ 27
- 20
mkit/include/build.sh View File

66
     # Create distributable tarball
66
     # Create distributable tarball
67
     #
67
     #
68
     local version=$(get_version)
68
     local version=$(get_version)
69
-    local dirname=$MKIT_PROJNAME-$version
69
+    local dirname=$MKIT_PKGNAME-$version
70
     mkdir -p $dirname
70
     mkdir -p $dirname
71
     local item
71
     local item
72
     cp -R $(ini values "lists:dist") $dirname
72
     cp -R $(ini values "lists:dist") $dirname
128
     #
128
     #
129
     #  1. use VERSION (from config.mk)
129
     #  1. use VERSION (from config.mk)
130
     #  2. if we are in git, override the version with last tag
130
     #  2. if we are in git, override the version with last tag
131
-    #  3. if set, add STAGE (from config.mk) as pre-release ID
131
+    #  3. if set, add PRERELEASE (from config.mk) as pre-release ID
132
     #     (afer dash)
132
     #     (afer dash)
133
-    #  4. if we are at a later commit than the last tag, add commit
134
-    #     sha1 to build metadata (after plus sign)
133
+    #  4. if we are at a later commit than the last tag, add branch
134
+    #     name and commit sha1 to build metadata (after plus sign)
135
     #  5. if the tree is "dirty", i.e. has uncommited changes,
135
     #  5. if the tree is "dirty", i.e. has uncommited changes,
136
     #     add "dirty" to build metadata
136
     #     add "dirty" to build metadata
137
     #
137
     #
140
     # Examples:
140
     # Examples:
141
     #
141
     #
142
     #     myprog v1.0.7                         # all clear
142
     #     myprog v1.0.7                         # all clear
143
-    #     myprog v1.0.7-alpha                   # STAGE="alpha"
144
-    #     myprog v1.0.7-alpha+g1aef811          # ^^ + some commits after
145
-    #     myprog v1.0.7-alpha+g1aef811.dirty    # ^^ + tree edited
143
+    #     myprog v1.0.7-alpha                   # PRERELEASE="alpha"
144
+    #     myprog v1.0.7-alpha+g1aef811.master   # ^^ + some commits after
145
+    #     myprog v1.0.7-alpha+gf14fc4f.api2     # ^^ + on a feature branch
146
+    #     myprog v1.0.7-alpha+gf14fc4f.api2.dirty  # ^^ + tree edited
146
     #     myprog v1.0.7-alpha+dirty             # tag OK but tree edited
147
     #     myprog v1.0.7-alpha+dirty             # tag OK but tree edited
147
-    #     myprog v1.0.7+dirty                   # ^^ but no stage
148
+    #     myprog v1.0.7+dirty                   # ^^ but no pre-release id
148
     #
149
     #
149
     # Note that versions with "dirty" should be perceived as kind of
150
     # Note that versions with "dirty" should be perceived as kind of
150
     # dangerous outside developer's own machine.  Versions with sha1 are
151
     # dangerous outside developer's own machine.  Versions with sha1 are
164
     #         from tags" fails if we are in shallow clone made from
165
     #         from tags" fails if we are in shallow clone made from
165
     #         other than a tagged commit.
166
     #         other than a tagged commit.
166
     #
167
     #
168
+    # FIXME:  Using PRERELEASE for release IDs may not be compatible with
169
+    #         release strategy implemented in release.sh
170
+    #
167
     local version=$VERSION
171
     local version=$VERSION
168
-    local stage=$STAGE
172
+    local prerl=$PRERELEASE
173
+    grep ":" <<<"$prerl" && warn "colon in PRERELEASE may corrupt version data: $prerl"
169
     if git rev-parse HEAD >&/dev/null;
174
     if git rev-parse HEAD >&/dev/null;
170
     then    # we are in git repo... so we can get smart
175
     then    # we are in git repo... so we can get smart
171
         local lasttag=$(git tag | grep ^v | sort -V | tail -n1)
176
         local lasttag=$(git tag | grep ^v | sort -V | tail -n1)
172
         if ! git describe --tags --exact-match HEAD >&/dev/null;
177
         if ! git describe --tags --exact-match HEAD >&/dev/null;
173
-        then    # we are not at later commit than the last tag
178
+        then    # we are at a later commit than the last tag
174
             local sha=g$(git log -1 --pretty=format:%h HEAD)
179
             local sha=g$(git log -1 --pretty=format:%h HEAD)
180
+            local curbranch=$(git rev-parse --abbrev-ref HEAD)
181
+            local commit="$curbranch.$sha"
175
         fi
182
         fi
176
         if test "$(git diff --shortstat 2>/dev/null)" != "";
183
         if test "$(git diff --shortstat 2>/dev/null)" != "";
177
-        then    # thr tree is "dirty", i.e. has been edited
184
+        then    # the tree is "dirty", i.e. has been edited
178
             local dirty=dirty
185
             local dirty=dirty
179
         fi
186
         fi
180
         version=${lasttag:1}
187
         version=${lasttag:1}
181
         local suffix=""
188
         local suffix=""
182
-        case $stage:$sha:$dirty in
183
-            ::)         suffix=""                    ;;
184
-            ::dirty)    suffix="+$dirty"             ;;
185
-            :g*:)       suffix="+$sha"               ;;
186
-            :g*:dirty)  suffix="+$sha.dirty"         ;;
187
-            *::)        suffix="-$stage"             ;;
188
-            *::dirty)   suffix="-$stage+$dirty"      ;;
189
-            *:g*:)      suffix="-$stage+$sha"        ;;
190
-            *:g*:dirty) suffix="-$stage+$sha.$dirty" ;;
189
+        case $prerl:$commit:$dirty in
190
+            ::)        suffix=""                       ;;
191
+            ::dirty)   suffix="+$dirty"                ;;
192
+            :*:)       suffix="+$commit"               ;;
193
+            :*:dirty)  suffix="+$commit"               ;;
194
+            *::)       suffix="-$prerl"                ;;
195
+            *::dirty)  suffix="-$prerl+$dirty"         ;;
196
+            *:*:)      suffix="-$prerl+$commit"        ;;
197
+            *:*:dirty) suffix="-$prerl+$commit.$dirty" ;;
191
         esac
198
         esac
192
         version=$version$suffix
199
         version=$version$suffix
193
     fi
200
     fi

+ 1
- 18
mkit/include/ini.sh View File

15
         1value) fn=_ini_greppath; limit="tail -1" ;;
15
         1value) fn=_ini_greppath; limit="tail -1" ;;
16
         *)      die "incorrect use of \`ini()\`"
16
         *)      die "incorrect use of \`ini()\`"
17
     esac
17
     esac
18
-    _ini_cached | $fn $arg | $limit
19
-}
20
-
21
-_ini_cached() {
22
-    #
23
-    # Load ini file to our cache (RAM disk) and cat it
24
-    #
25
-    # User should set MKIT_INI_CACHE to a ram-based file
26
-    # if mktemp cannot be relied upon.
27
-    #
28
-    if test -z "$_MKIT_INI_CACHED";
29
-    then
30
-        MKIT_INI_CACHE=${MKIT_INI_CACHE:-$(mktemp)}
31
-        _MKIT_INI_CACHED=$MKIT_INI_CACHE
32
-        test -r $MKIT_INI || die "cannot read MKIT_INI: $MKIT_INI"
33
-        cp $MKIT_INI $_MKIT_INI_CACHED
34
-    fi
35
-    cat $_MKIT_INI_CACHED
18
+    cat $MKIT_INI | $fn $arg | $limit
36
 }
19
 }
37
 
20
 
38
 _ini_cat() {
21
 _ini_cat() {

+ 13
- 4
mkit/include/mkit.sh View File

1
 #!/bin/bash
1
 #!/bin/bash
2
 
2
 
3
-. mkit/include/build.sh  || die "cannot import ini.sh"
4
-. mkit/include/deploy.sh || die "cannot import ini.sh"
3
+. mkit/include/build.sh  || die "cannot import build.sh"
4
+. mkit/include/deploy.sh || die "cannot import deploy.sh"
5
+. mkit/include/release.sh || die "cannot import release.sh"
5
 . mkit/include/ini.sh    || die "cannot import ini.sh"
6
 . mkit/include/ini.sh    || die "cannot import ini.sh"
6
 
7
 
7
 MKIT_INI=${MKIT_INI:-mkit/config.ini}
8
 MKIT_INI=${MKIT_INI:-mkit/config.ini}
8
 MKIT_INI_EXPAND=2
9
 MKIT_INI_EXPAND=2
10
+MKIT_PKGNAME=$(ini 1value "ENV:PKGNAME")
9
 MKIT_PROJNAME=$(ini 1value "ENV:PROJNAME")
11
 MKIT_PROJNAME=$(ini 1value "ENV:PROJNAME")
10
 
12
 
11
 configure() {
13
 configure() {
23
     #
25
     #
24
     # Exit with message and non-zero exit status
26
     # Exit with message and non-zero exit status
25
     #
27
     #
26
-    echo "$@" >&2
28
+    echo "fatal: $@" >&2
27
     exit 4
29
     exit 4
28
 }
30
 }
29
 
31
 
32
+warn() {
33
+    #
34
+    # Print warning message
35
+    #
36
+    echo "$@" >&2
37
+}
38
+
30
 route() {
39
 route() {
31
     #
40
     #
32
     # Call correct function based on $1
41
     # Call correct function based on $1
33
     #
42
     #
34
     case $1 in
43
     case $1 in
35
-        build|build_manpages|clean|dist|install|uninstall)
44
+        build|build_manpages|clean|dist|install|release_?|uninstall)
36
             $1
45
             $1
37
             ;;
46
             ;;
38
         *)
47
         *)

+ 62
- 0
mkit/include/release.sh View File

1
+#!/bin/bash
2
+
3
+__make_ver() {
4
+    local level=$1
5
+    local old=$2
6
+    local oldx=${old%.*.*}
7
+    local oldz=${old#*.*.}
8
+    local tmpy=${old%.*}
9
+    local oldy=${tmpy#*.}
10
+    case $level in
11
+        x) new="$((oldx+1)).0.0"            ;;
12
+        y) new="$oldx.$((oldy+1)).0"        ;;
13
+        z) new="$oldx.$oldy.$((oldz+1))"    ;;
14
+        *) die "invalid release level: $1"  ;;
15
+    esac
16
+    echo $new
17
+}
18
+
19
+__release() {
20
+    #
21
+    # Prepare release
22
+    #
23
+    # Span release routines: make a signed tag, check branch
24
+    # and update release branch
25
+    #
26
+    local level=$1
27
+    git rev-parse HEAD >&/dev/null || die "cannot release outside git repo"
28
+    local lastfile=$(git diff-tree --no-commit-id --name-only -r HEAD)
29
+    local lasttag=$(git tag | grep ^v | sort -V | tail -n1)
30
+    local changelog="$(git log --oneline $lasttag..HEAD)"
31
+    local curbranch=$(git rev-parse --abbrev-ref HEAD)
32
+    local dirt="$(git diff --shortstat 2>/dev/null)"
33
+
34
+    local newver=$(__make_ver $level ${lasttag#v})
35
+    local newtag=v$newver
36
+    local higher=$(echo -e "$oldtag\n$newtag" | sort -V | tail -n1)
37
+    test "$newtag" = "$higher"     || die "generated tag looks older: $oldtag<$newtag"
38
+
39
+    grep -qw "$newver" config.mk   || die "new version not in config.mk: $newver"
40
+    test -n "$lasttag"             || die "cannot find last tag"
41
+    grep '^....... WIP ' <<<"$changelog" && die "WIP commit since $lasttag"
42
+    grep -qw "$curbranch" <<<"$RELSRC"   || die "you are not on RELSRC branch: $RELSRC"
43
+    test -z "$dirt"                || die "tree is dirty: $dirt"
44
+
45
+    # FIXME: Have user prepare proper message with changelog
46
+
47
+    set -e
48
+    git tag -m "$MKIT_PROJNAME $newtag-$STAGE - $CODENAME" $newtag
49
+    git branch -f $RELDST $newtag
50
+}
51
+
52
+release_x() {
53
+    __release x
54
+}
55
+
56
+release_y() {
57
+    __release y
58
+}
59
+
60
+release_z() {
61
+    __release z
62
+}