Projekt

Allgemein

Profil

Feature #176 » check.sh

Maximilian Seesslen, 11.05.2022 15:27

 
1
#!/bin/bash
2

    
3
set -e -u
4

    
5

    
6
red="\e[91m"
7
default="\e[39m"
8
yellow="\e[93m"
9
green="\e[92m"
10

    
11
log()
12
{
13
    echo -e "${yellow}$1${default}"
14
}
15

    
16
good()
17
{
18
    echo -e "${green}$1${default}"
19
}
20

    
21
warning()
22
{
23
    echo -e "${red}$1${default}"
24
}
25

    
26
prepareVersion()
27
{
28
    log "Preparing new tag: v$major.$minor.$patch_"
29
    sed -i "s|v[0-9]*\.[0-9]*\.[0-9]*|v$major.$minor.$patch_|g" README.md
30

    
31
    sed -i "s|http://.*/file-.*\..*\t |http://ifm10d20174.intra.ifm/mase/test/file-v$major.$minor.$patch_.txt |g" README.md
32

    
33
    if [ ! -z "$(git status -s)" ]; then
34
	git commit -m "prepared for new release tag v$major.$minor.$patch_" README.md
35
    else
36
	warning "Replaced version information but nothing changed. Check if versions are ok."
37
    fi
38
    
39
    git tag "v$major.$minor.$patch_"
40
}
41

    
42
inspectVersion()
43
{
44
    cut=$1
45
    patch_=${cut##*.}
46
    cut=${cut%.*}
47
    minor=${cut##*.}
48
    cut=${cut%.*}
49
    major=${cut##*.}
50
    cut=${cut%.*}
51
}
52

    
53
git describe --tags --dirty --long
54
# Must be empty or something was changed or untracked
55

    
56
if [ ! -z "$(git status -s)" ]; then
57
    echo -e "${red}Something is dirty here;${default}"
58
    git status
59
    exit 22
60
fi
61

    
62
release=$(git describe --tags --dirty --long)
63

    
64
cut=${release#v*}
65
cut=${cut%%-*}
66
last=${release##*-}
67

    
68
if [ "$last" == "dirty" ]; then
69
   echo "   Its dirty"
70
    release=${release%-*}
71
fi
72

    
73
sha=${release##*-}
74
release=${release%-*}
75
distance=${release##*-}
76
release=${release%-*}
77

    
78
inspectVersion $cut
79

    
80
echo "Cut: $cut"
81
echo "Sha: $sha"
82
echo "Distance: $distance"
83
echo "Current/Old Release:   $major . $minor . $patch_"
84
doPrepareVersion=no
85

    
86
if [ "$#" -gt "0" ]; then
87
    echo "Version manually"
88
    inspectVersion ${1#v*}
89
    doPrepareVersion=yes
90
elif [ "$distance" != "0" ]; then
91
    echo "I have to create a new tag"
92
    let patch_+=1
93
    doPrepareVersion=yes
94
fi
95

    
96
if [ "${doPrepareVersion}" == "yes" ]; then
97
    echo "New Release:   $major . $minor . $patch_"
98
    prepareVersion
99
fi
100

    
101
good finished
102

    
103

    
104
#---fin------------------------------------------------------------------------
(1-1/2)