Projekt

Allgemein

Profil

Feature #497 » generate.sh

Maximilian Seesslen, 26.02.2024 18:26

 
1
#!/bin/bash
2

    
3

    
4
set -e -u
5

    
6
S="/home/deseessm/wp/src/canio"
7
opwd=$PWD
8

    
9

    
10
splitCode()
11
{
12
    V="${1#v*}"
13
    MAJOR="${V%%.*}"
14
    V="${V#*.}"
15
    MINOR="${V%%.*}"
16
    V="${V#*.}"
17
    PATCH="${V%%-*}"
18
    V="${V#*-}"
19

    
20
}
21

    
22
getVersionCode()
23
{
24
    let code="( $1 * 1000000 ) + ( $2 * 1000 ) + $3"
25
    echo $code
26
}
27

    
28
getChangelogRange()
29
{
30
    echo "### Get ranged changelog for $1: $2 ... $3"
31

    
32
    echo "### Ranged Chagelog for $(basename $1): $2 ... $3" >> $opwd/subliments.txt
33
    splitCode $2
34
    echo "   Major: $MAJOR; Minor: $MINOR; Patch: $PATCH"
35
    startCode=$(getVersionCode $MAJOR $MINOR $PATCH)
36
    
37
    splitCode $3
38
    echo "   Major: $MAJOR; Minor: $MINOR; Patch: $PATCH"
39
    endCode=$(getVersionCode $MAJOR $MINOR $PATCH)
40

    
41
    echo "Start code: $startCode"
42
    echo "end code: $endCode"
43
    cd $opwd
44
    mkdir -p $(basename $1)
45
    cd $(basename $1)
46

    
47
    csplit $1/CHANGELOG.md "/# Changes/" '{*}' -f "cl_"
48

    
49
    rm cl_00
50
    cnt=0
51

    
52
    for f in cl_*; do
53
	l1=$(head -n 1 $f)
54
	echo "$f: $l1"
55
	l2=$(echo "$l1" | grep -oe "v[0-9]*\.[0-9]*\.[0-9]*$")
56
	TAG="$l2"
57

    
58
	if [ "$cnt" == "0" ]; then
59
	    CURRENT=$l2
60
        fi
61
	if [ "$cnt" == "1" ]; then
62
	    PREVIOUS=$l2
63
        fi
64

    
65
	splitCode $TAG
66
	thisCode=$(getVersionCode $MAJOR $MINOR $PATCH)
67

    
68
	if [ "$thisCode" -ge "$startCode" ] && [ "$thisCode" -le "$endCode" ]; then
69
	    echo "### GOAL"
70
	    cat $f >> $opwd/subliments.txt
71
	fi
72

    
73
        echo "   Major: $MAJOR; Minor: $MINOR; Patch: $PATCH"
74
	let cnt+=1
75
    # sed -e " v.*\..*\..*\.$"
76
    done
77

    
78
}
79

    
80
parseSubmodule()
81
{
82
    cd $S
83
    # cd $submodule
84
    echo "### Parsing $submodule [2]"
85
    sta=0
86
    git diff $PREVIOUS $CURRENT $submodule > $opwd/$submodule.diff | sta=1
87
    cd $opwd
88

    
89
    if [ -s "${submodule}.diff" ]; then
90
	echo "A1 $sta"
91
	end=$(tail -n2 ${submodule}.diff | grep -e "+Subproject commit " | grep -oe " [0-9|a-f]*$")
92
	start=$(tail -n2 ${submodule}.diff | grep -e "-Subproject commit " | grep -oe " [0-9|a-f]*$")
93
	echo "   $submodule: START: $start"
94
	echo "   $submodule: END: $end"
95

    
96
	cd $S/$submodule
97

    
98
	startTag=$(git describe --tags --match 'v[0-9]*.[0-9]*.[0-9]*' $start)
99
	endTag=$(git describe --tags --match 'v[0-9]*.[0-9]*.[0-9]*' $end)
100
	
101
	getChangelogRange $S/$submodule $startTag $endTag
102

    
103
	echo "   $submodule: range $startTag ... $endTag"
104
    else
105
	echo "ignoding no change"
106
    fi
107
}
108

    
109

    
110
csplit CHANGELOG.md "/# Changes/" '{*}' -f "cl_"
111
opwd=$PWD
112

    
113
rm -f $opwd/subliments.txt
114
rm cl_00
115
cnt=0
116

    
117
for f in cl_*; do
118
    l1=$(head -n 1 $f)
119
    echo "$f: $l1"
120
    l2=$(echo "$l1" | grep -oe "v[0-9]*\.[0-9]*\.[0-9]*$")
121
    TAG="$l2"
122

    
123
    if [ "$cnt" == "0" ]; then
124
	CURRENT=$l2
125
    fi
126
    if [ "$cnt" == "1" ]; then
127
	PREVIOUS=$l2
128
    fi
129

    
130
    V="${TAG#v*}"
131
    MAJOR="${V%%.*}"
132
    V="${V#*.}"
133
    MINOR="${V%%.*}"
134
    V="${V#*.}"
135
    PATCH="${V%%-*}"
136
    V="${V#*-}"
137

    
138
    echo "   Major: $MAJOR; Minor: $MINOR; Patch: $PATCH"
139
    let cnt+=1
140

    
141
    # sed -e " v.*\..*\..*\.$"
142
done
143

    
144
echo 
145
echo "CURRENT: $CURRENT"
146
echo "PREVIOUS: $PREVIOUS"
147

    
148
# CURRENT=v0.3.3
149
# PREVIOUS=v0.3.2
150

    
151
mainCurrent="$CURRENT"
152
mainPrevious="$PREVIOUS"
153

    
154
# git describe --tags --match 'v[0-9]*.[0-9]*.[0-9]*' d0847bb7f9fb259a52a314a82aaab857d4096707
155
# git diff v0.3.6 v0.3.7 libbiwak 
156
cd $S
157

    
158
submodules=$(git submodule foreach --quiet 'basename $PWD')
159

    
160
echo "Submodules: $submodules"
161

    
162
for submodule in $submodules; do
163
    echo "Parsing $submodule"
164
    CURRENT=$mainCurrent
165
    PREVIOUS=$mainPrevious
166
    parseSubmodule
167
done
168

    
169
echo "[$0] fin."
170

    
171
#---fin------------------------------------------------------------------------
    (1-1/1)