Repository navigation
Expand file tree
/
Copy pathMakesurefile
More file actions
557 lines (458 loc) · 13.5 KB
/
Copy pathMakesurefile
File metadata and controls
557 lines (458 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
# vim: syntax=bash
@options timing
@define NEXT_VERSION='0.9.20'
@define GOAWK_VERSION='1.21.0'
@define JUST_VERSION='1.3.0'
@define GOAWK="goawk$GOAWK_VERSION"
@define JUST="just$JUST_VERSION"
@define TUSH_REPO='https://github.com/adolfopa/tush'
@define REPO='xonixx/makesure'
@goal soft_folder_created @private
@reached_if [[ -d "soft" ]]
mkdir soft
@goal tush_installed @private
@depends_on soft_folder_created
@reached_if [[ -f "soft/tush/bin/tush-check" ]]
echo
echo "Fetching tush..."
echo
cd "soft"
if command -v wget >/dev/null
then
wget $TUSH_REPO/archive/master.tar.gz -O./tush.tar.gz
tar xzvf ./tush.tar.gz
rm ./tush.tar.gz
mv tush-master tush
elif command -v curl >/dev/null
then
curl -L $TUSH_REPO/archive/master.tar.gz -o ./tush.tar.gz
tar xzvf ./tush.tar.gz
rm ./tush.tar.gz
mv tush-master tush
else
git clone --depth 1 $TUSH_REPO.git
rm -r tush/.git
fi
@goal soft_installed @private
@depends_on tush_installed
@goal cleaned @private
@goal cleaned_soft @private
@reached_if [[ ! -d "soft" ]]
rm -r "soft"
@goal cleaned_all @private
@depends_on cleaned cleaned_soft
@goal debug @private
@doc shows software versions
AWK="${AWK:-awk}"
printf "%s: " "$AWK"
case "$AWK" in
*busybox*) $AWK --help 2>&1 | head -n 1
;;
*mawk*) "$AWK" -W version 2>&1 | head -n 1
;;
*) "$AWK" --version | head -n 1
;;
esac
bash --version| head -n 1
@goal prepared4tests @private
@depends_on tush_installed debug
@lib testing_tush
function run_tush_file() {
local f="$1"
# before_count=$(calc_temp_files)
export PATH="$PATH:$MYDIR/soft/tush/bin"
export NEXT_VERSION
if DIFF="diff --strip-trailing-cr" tush-check "$f"
then
echo "TESTS PASSED : $f"
else
echo >&2 "!!! TESTS FAILED !!! : $f"
exit 1
fi
# after_count=$(calc_temp_files)
# if (( before_count != after_count ))
# then
# echo >&2 "!!! temp file not deleted !!!"
# exit 1
# fi
}
function calc_temp_files {
local tmp_count=$(find /tmp -maxdepth 1 -type f -name 'makesure.*' | wc -l)
local cnt
(( cnt = tmp_count ))
if [[ -d "/dev/shm" ]]
then
local shm_count=$(find /dev/shm -maxdepth 1 -type f -name 'makesure.*' | wc -l)
(( cnt += shm_count ))
fi
echo $cnt
}
@goal tested
@doc runs all *.tush tests
@depends_on tests/*.tush
@goal @glob tests/*.tush @private
@depends_on prepared4tests
@use_lib testing_tush
MAKESURE=makesure_dev \
run_tush_file "$ITEM"
@goal tested_candidate @glob tests/*.tush @private
@depends_on tested
@depends_on candidate_version_prepared
@use_lib testing_tush
MAKESURE=makesure_candidate \
run_tush_file "$ITEM"
@goal coverage
@doc 'prepares code coverage report'
COVERPROFILE="/tmp/cov.txt"
rm -f "$COVERPROFILE"
AWK="$(pwd)/soft/$GOAWK" \
AWK_OPTS="-covermode=set -coverprofile=$COVERPROFILE -coverappend" \
MAKESURE=makesure_dev \
./makesure tested
go tool cover -html="$COVERPROFILE"
@goal candidate
@doc compiles makesure_candidate
@depends_on tested_candidate
@goal release
@doc $'creates release version of \'makesure\' + updates README.md'
@depends_on candidate
@depends_on release_makesure
@depends_on README.md
# @depends_on gh_release TODO we can't just do it since we need to commit first
@goal release_makesure @private
cp makesure_candidate makesure
@goal README.md @private
@doc compiles release version of README.md
awk '
/^\$ \.\/makesure -h$/ { print; stop=1; system("./makesure -h") }
/^```$/ { stop=0 }
!stop' README.md > README.md.1
mv README.md.1 README.md
@goal candidate_version_prepared @private
F=makesure_candidate
{
echo '#!/bin/sh'
# We use `makesure_awk`, not `AWK` because otherwise it clashes with `AWK` set for tests.
# The same we can't just use `A` because it can clash with external config variable that user might want to use.
# Since in Posix sh there is no way to declare local var, let's just make names more specific.
echo "if command -v gawk >/dev/null;then makesure_awk='gawk -ltime -v Gawk=1';makesure_pre='';else makesure_awk=awk;makesure_pre='function gettimeofday(){}';fi"
echo 'exec $makesure_awk -v "Version='$NEXT_VERSION'" -v "Prog=$0" "$makesure_pre"'\'
awk -v Q=\' '
function trim(s) { sub(/^[ \t\r\n]+/, "", s); sub(/[ \t\r\n]+$/, "", s); return s }
/^BEGIN/ { in_begin=1 }
in_begin && /^}/ { in_begin=0 }
in_begin && $1 ~ /^delete/{ next }
{ if (!/"#"/ && !/\*#\// && !/\*\(#/) gsub("\\s*#.*$", "")
gsub(/ == /, "==")
gsub(/ = /, "=")
gsub(/ != /, "!=")
gsub(/ >= /, ">=")
gsub(/ <= /, "<=")
gsub(/; +/, ";")
gsub(/, +/, ",")
gsub(/ ~ /, "~")
gsub(/ > /, ">")
gsub(/ < /, "<")
gsub(/ \/ /, "/")
gsub(/ \* /, "*")
gsub(/ \+ /, "+")
##gsub(/ - /, "-")
gsub(/ \|\| /, "||")
gsub(/ \| /, "|")
if (/ \? /) gsub(/ : /, ":")
gsub(/ \? /, "?")
gsub(/if \(/, "if(")
gsub(/for \(/, "for(")
gsub(/while \(/, "while(")
gsub(/ && /, "\\&\\&")
gsub(/) {/, "){")
gsub(/\( +/, "(")
gsub(/{ +/, "{")
gsub(/} +/, "}")
gsub(/) +/, ")")
##gsub(/] +/, "]")
if (!/^ +}/) gsub(/ +}/, "}")
##gsub(/" in/, "\"in")
gsub(Q, Q "\\" Q Q)
if (l=trim($0)) { printf "%s", (l=="}" ? l : (NR==1 ? "" : "\n") $0) }
}' makesure.awk
echo \'' Makesurefile "$@"'
} > "$F"
chmod +x "$F"
@goal default
@doc $'calls \'tested\' goal'
@depends_on tested
@goal tested_awks
@doc tests with all awks
@depends_on tested
@depends_on tested_bwk
@depends_on tested_mawk133
@depends_on tested_mawk134
@depends_on tested_gawk51
@depends_on tested_gawk511
@depends_on tested_goawk
@depends_on tested_busybox
@goal tested_bwk @private
@depends_on installed_bwk
AWK="$(pwd)/soft/bwk" ./makesure tested
@goal tested_mawk133 @private
@depends_on installed_mawk133
AWK="$(pwd)/soft/mawk133" ./makesure tested
@goal tested_mawk134 @private
@depends_on installed_mawk134
AWK="$(pwd)/soft/mawk134" ./makesure tested
@goal tested_gawk51 @private
@depends_on installed_gawk51
MAKESURE_AWKLIBPATH="$(pwd)/soft/gawk51_libs" AWK="$(pwd)/soft/gawk51" ./makesure tested
@goal tested_gawk511 @private
@depends_on installed_gawk511
MAKESURE_AWKLIBPATH="$(pwd)/soft/gawk511_libs" AWK="$(pwd)/soft/gawk511" ./makesure tested
@goal tested_gawk521 @private
@depends_on installed_gawk521
MAKESURE_AWKLIBPATH="$(pwd)/soft/gawk521_libs" AWK="$(pwd)/soft/gawk521" ./makesure tested
@goal tested_gawk52 @private
@depends_on installed_gawk52
MAKESURE_AWKLIBPATH="$(pwd)/soft/gawk52_libs" AWK="$(pwd)/soft/gawk52" ./makesure tested
@goal tested_goawk @private
@depends_on installed_goawk
AWK="$(pwd)/soft/$GOAWK" ./makesure tested
@goal tested_goawk_branch @private
@depends_on installed_goawk_branch
AWK="$(pwd)/soft/$GOAWK_BRANCH_EXE" ./makesure tested
@goal tested_busybox @private
@reached_if [[ "$OSTYPE" != "linux-gnu"* ]] # only test busybox awk on linux
@depends_on installed_busybox
AWK="$(pwd)/soft/busybox awk" ./makesure tested
@goal installed_awks
@doc installs all awks into ./soft
@depends_on installed_bwk
@depends_on installed_gawk51
@depends_on installed_gawk511
@depends_on installed_mawk133
@depends_on installed_mawk134
@depends_on installed_goawk
@goal installed_bwk @private
@reached_if [[ -f soft/bwk ]]
@depends_on soft_folder_created
echo
echo "Fetching BWK..."
echo
cd "soft"
wget https://github.com/onetrueawk/awk/archive/refs/heads/master.tar.gz -Obwk.tar.gz
tar xzvf bwk.tar.gz
rm bwk.tar.gz
echo
echo "Compile BWK..."
echo
cd "awk-master"
make
mv a.out ../bwk
cd ..
./bwk --version
rm -r awk-master
@lib mawk
install_mawk() {
local version="$1"
local tgz="$2"
local exeName="mawk${version//./}"
echo
echo "Fetching Mawk $version..."
echo
cd "soft"
wget "https://invisible-island.net/archives/mawk/$tgz"
tar xzvf "$tgz"
rm "$tgz"
echo
echo "Compile Mawk $version..."
echo
cd mawk-"$version"-*
./configure && make
mv mawk ../$exeName
cd ..
./$exeName -W version
rm -r mawk-"$version"-*
}
@lib gawk
install_gawk() {
local version="$1"
local exeName="$2"
echo
echo "Fetching Gawk-$version..."
echo
cd "soft"
G=gawk-$version.tar.gz
dlUrl="http://git.savannah.gnu.org/cgit/gawk.git/snapshot/$G"
dlFolder="gawk-$version"
# if [[ $version == '5.1.1' ]]
# then
# G='master.tar.gz'
# dlUrl="https://github.com/gnu-mirror-unofficial/gawk/archive/refs/heads/$G"
# dlFolder='gawk-master'
# G="gawk-$version.tar.xz"
# dlUrl="https://fossies.org/linux/misc/$G"
# dlFolder="gawk-$version"
# tarOpts="xvf"
# fi
wget "$dlUrl"
tar "${tarOpts:-xzvf}" "$G"
rm "$G"
echo
echo "Compile Gawk-$version..."
echo
cd "$dlFolder"
./configure
make
# make check
mv gawk ../$exeName
mkdir ../${exeName}_libs
mv extension/.libs/*.so ../"${exeName}"_libs # for AWKLIBPATH
cd ..
./$exeName --version
rm -r "$dlFolder"
}
@goal installed_gawk51 @private
@reached_if [[ -f soft/gawk51 ]]
@depends_on soft_folder_created
@use_lib gawk
install_gawk 5.1.0 gawk51
@goal installed_gawk511 @private
@reached_if [[ -f soft/gawk511 ]]
@depends_on soft_folder_created
@use_lib gawk
install_gawk 5.1.1 gawk511
@goal installed_gawk521 @private
@reached_if [[ -f soft/gawk521 ]]
@depends_on soft_folder_created
@use_lib gawk
install_gawk 5.2.1 gawk521
@goal installed_gawk52 @private
@reached_if [[ -f soft/gawk52 ]]
@depends_on soft_folder_created
@use_lib gawk
install_gawk 5.2-stable gawk52
@goal installed_mawk133 @private
@reached_if [[ -f soft/mawk133 ]]
@depends_on soft_folder_created
@use_lib mawk
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
install_mawk 1.3.3 'mawk-1.3.3-20080909.tgz' # this one doesn't compile on macos
elif [[ "$OSTYPE" == "darwin"* ]]; then
install_mawk 1.3.3 'mawk-1.3.3-20090920.tgz'
else
>&2 echo "Unknown OS"
exit 1
fi
@goal installed_mawk134 @private
@reached_if [[ -f soft/mawk134 ]]
@depends_on soft_folder_created
@use_lib mawk
install_mawk 1.3.4 'mawk-1.3.4-20200120.tgz'
@goal installed_busybox @private
@reached_if [[ -x ./soft/busybox ]]
wget 'https://busybox.net/downloads/binaries/1.31.0-i686-uclibc/busybox' -O ./soft/busybox
chmod +x ./soft/busybox
echo "Installed: $(./soft/busybox | head -n 1)"
@goal installed_goawk @private
@reached_if [[ -f soft/$GOAWK ]]
@depends_on soft_folder_created
echo
echo "Fetching GoAWK $GOAWK_VERSION ..."
echo
cd "soft"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
os="linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
os="darwin"
else
>&2 echo "Unknown OS"
exit 1
fi
F=goawk_v${GOAWK_VERSION}_${os}_amd64.tar.gz
wget "https://github.com/benhoyt/goawk/releases/download/v$GOAWK_VERSION/$F"
tar xzvf "$F" goawk
rm "$F"
mv goawk $GOAWK
"./$GOAWK" --version
@define GOAWK_BRANCH='bytecode'
@define GOAWK_BRANCH_EXE="goawk_$GOAWK_BRANCH"
@goal installed_goawk_branch @private
@reached_if [[ -f soft/$GOAWK_BRANCH_EXE ]]
@depends_on soft_folder_created
echo
echo "Installing GoAWK branch=$GOAWK_BRANCH ..."
echo
cd "soft"
zip="https://github.com/benhoyt/goawk/archive/refs/heads/$GOAWK_BRANCH.zip"
curl -L "$zip" -o "$GOAWK_BRANCH.zip"
yes | unzip "$GOAWK_BRANCH.zip"
cd "goawk-$GOAWK_BRANCH"
go build
mv goawk ../"$GOAWK_BRANCH_EXE"
cd ..
./"$GOAWK_BRANCH_EXE" --version
rm -r "goawk-$GOAWK_BRANCH" "$GOAWK_BRANCH.zip"
@goal installed_just @private
@reached_if [[ -f "soft/$JUST" ]]
@depends_on soft_folder_created
echo
echo "Fetching Just $JUST_VERSION ..."
echo
cd "soft"
F=just-$JUST_VERSION-x86_64-unknown-linux-musl.tar.gz
wget "https://github.com/casey/just/releases/download/$JUST_VERSION/$F"
tar xzvf "$F" just
mv just "$JUST"
rm "$F"
"./$JUST" --version
@goal gh_release
@doc 'publish Github release (draft)'
fail () {
echo >&2 "$@"
exit 1
}
prodVersion="$(./makesure -v)"
if [[ "$prodVersion" != "$NEXT_VERSION" ]]
then
fail "$prodVersion in ./makesure, must be $NEXT_VERSION. Please run './makesure release' and commit first."
fi
releaseTag="v$NEXT_VERSION"
echo
echo "Will publish a draft release for $releaseTag ..."
echo
milestoneId=$(gh api -X GET "repos/xonixx/makesure/milestones" --jq '.[] | select(.title=="'$NEXT_VERSION'").number')
if [[ -z $milestoneId ]]
then
fail "Unable to determine milestoneId by release version"
fi
echo "Milestone ID : $milestoneId"
# Let's take for notes the latest record from change log (in CHANGELOG.md)
# Let's make sure the version there is correct
notesStr=$(awk -v NEXT_VERSION="$NEXT_VERSION" -v REPO="$REPO" -v milestoneId="$milestoneId" '
Started && /##/ { exit }
/##/ {
if (Started=index($0,NEXT_VERSION)>0) {
print "v" NEXT_VERSION " <a href=\"https://github.com/" REPO "/milestone/" milestoneId "?closed=1\">GitHub issues</a>"
next
} else exit
}
Started
' CHANGELOG.md)
if [ -z "$notesStr" ]
then
fail "Make sure you did not forget to add latest change log (for $NEXT_VERSION)!"
fi
echo "Notes: $notesStr"
gh release create "$releaseTag" \
--title "$releaseTag" \
--notes "$notesStr" \
--draft
echo "Please don't forget to open the release draft, edit it as needed and PUBLISH!"
@goal prepareCHANGELOG @private
@doc prepares initial version of CHANGELOG.md
for v in $(gh release list | awk '{ print $1 }')
do
echo "## $v"
gh release view "$v" | gawk '/--/ { Started=1; next } Started && !/\/milestone\// {
print gensub(/#([0-9]+)/,"[\\0](https://github.com/xonixx/makesure/issues/\\1)", "g")
}'
done