-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makesurefile
562 lines (462 loc) · 15 KB
/
Makesurefile
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
558
559
560
561
562
# vim: syntax=bash
@options timing
@define NEXT_VERSION '0.9.23'
@define GOAWK_VERSION '1.29.1' # https://github.com/benhoyt/goawk/releases
@define JUST_VERSION '1.3.0' # https://github.com/casey/just/releases
@define FHTAGN_VERSION 'v0.2.1' # https://github.com/xonixx/fhtagn/releases
@define MDBOOK_VERSION 'v0.4.37' # https://github.com/rust-lang/mdBook/releases
@define MDBOOK_LINKCHECK_VERSION 'v0.7.7' # https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases
@define MDBOOKER_VERSION '11572b1' # https://github.com/xonixx/mdbooker/releases
@define GOAWK "goawk$GOAWK_VERSION"
@define JUST "just$JUST_VERSION"
@define REPO 'xonixx/makesure'
@define AWK "${AWK:-awk}"
@lib dl
download() {
local url="$1"
local file="$2"
if command -v wget >/dev/null
then
wget "$url" -O"$file"
elif command -v curl >/dev/null
then
curl -L "$url" -o "$file"
else
false
fi
}
@goal soft_folder_created @private
@reached_if [[ -d "soft" ]]
mkdir soft
@define FHTAGN_URL "https://github.com/xonixx/fhtagn/raw/$FHTAGN_VERSION/fhtagn.awk"
@define FHTAGN "./soft/fhtagn$FHTAGN_VERSION.awk"
@goal fhtagn_installed @private
@depends_on soft_folder_created
@reached_if [[ -x "$FHTAGN" ]]
@use_lib dl
download "$FHTAGN_URL" "$FHTAGN"
chmod +x "$FHTAGN"
@goal cleaned_soft
@doc 'rm soft folder'
@reached_if [[ ! -d "soft" ]]
rm -r "soft"
@lib awk_ver
awk_ver() {
local key="$1"
local value="$2"
local AWK="${value:-awk}"
printf "[%12s] %s: " "$key" "$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
}
@goal debug @private
@doc 'shows software versions'
@use_lib awk_ver
awk_ver 'AWK' "$AWK"
awk_ver 'MAKESURE_AWK' "$MAKESURE_AWK"
bash --version| head -n 1
@goal debug_pg @params AWK MAKESURE_AWK @private
@doc 'shows software versions'
@use_lib awk_ver
awk_ver 'AWK' "$AWK"
awk_ver 'MAKESURE_AWK' "$MAKESURE_AWK"
bash --version| head -n 1
@goal prepared4tests @private
@depends_on fhtagn_installed debug
@lib testing
run_tush_file() {
local f="$1"
[[ "$OSTYPE" == "linux-gnu"* ]] && [[ -d /dev/shm ]] && export TMPDIR="/dev/shm"
if [[ "$f" == *"[wget]"* ]] && ! command -v wget >/dev/null
then
echo "TESTS SKIPPED: $f"
elif "$FHTAGN" "$f"
then
echo "TESTS PASSED : $f"
else
echo >&2 "!!! TESTS FAILED !!! : $f"
exit 1
fi
}
@goal fhtagn @params EXE_NAME
@doc 'runs all *.tush tests'
@depends_on fhtagn_installed
@use_lib awk_ver
if [[ $EXE_NAME == 'awk' ]]
then
MAKESURE_AWK="/usr/bin/awk"
elif [[ $EXE_NAME == '/'* ]]
then
MAKESURE_AWK="$EXE_NAME"
else
MAKESURE_AWK="$(pwd)/soft/${EXE_NAME}"
fi
export MAKESURE_AWK
# [[ ! -e $MAKESURE_AWK ]] && echo "not found: $MAKESURE_AWK" && exit 1
awk_ver 'MAKESURE_AWK' "$MAKESURE_AWK"
[[ $EXE_NAME == "gawk"* ]] && export MAKESURE_AWKLIBPATH="$(pwd)/soft/${EXE_NAME}_libs"
[[ "$OSTYPE" == "linux-gnu"* ]] && [[ -d /dev/shm ]] && export TMPDIR="/dev/shm"
MAKESURE=makesure_dev ALL=1 "$FHTAGN" tests/*.tush
# The idea of having this here (not using a named glob goal) is to be able
# to run `./makesure tests/test.tush` instead of `./makesure tested@tests/test.tush`
@goal tested
@doc 'runs all *.tush tests (stop at 1st error)'
@depends_on 'tests/*.tush' @args '' ''
@goal @glob 'tests/*.tush' @params MAKESURE_AWK MAKESURE_AWK_OPTS @private
@depends_on fhtagn_installed
@depends_on debug_pg @args "$AWK" MAKESURE_AWK
@use_lib testing
[[ -n $MAKESURE_AWK ]] && MAKESURE_AWK="$(realpath $MAKESURE_AWK)"
export MAKESURE_AWK
export MAKESURE_AWK_OPTS
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
MAKESURE=makesure_candidate \
run_tush_file "$ITEM"
@define COVERPROFILE '/tmp/cov.txt'
@goal file_removed @params F @private
rm -f "$F"
@goal _cover_profile_prepared @private
@depends_on file_removed @args COVERPROFILE
@depends_on 'tests/*.tush' @args "./soft/$GOAWK" "-covermode=set -coverprofile=$COVERPROFILE -coverappend"
@goal coverage
@doc 'prepares code coverage report'
@depends_on _cover_profile_prepared
go tool cover -html="$COVERPROFILE"
@goal coverage_badge_updated
@doc 'updates code coverage badge'
@depends_on _cover_profile_prepared
html='/tmp/cov.html'
go tool cover -html="$COVERPROFILE" -o "$html"
coverage="$($AWK '/makesure\.awk/ { if (match($0,/\(.+\)/)) print substr($0,RSTART+1,RLENGTH-2) }' "$html")"
echo "coverage: $coverage"
$AWK -v coverage="$coverage" '{ gsub(/\$COVERAGE/,coverage) } 1' coverage.tpl.svg > coverage.svg
rm "$html"
@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 checkREADME.md
@depends_on coverage_badge_updated
# @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 -v NEXT_VERSION="$NEXT_VERSION" '
{
gsub(/raw\.githubusercontent\.com\/xonixx\/makesure\/[^\/]+\//, "raw.githubusercontent.com/xonixx/makesure/v" NEXT_VERSION "/")
}
/^\$ \.\/makesure -h$/ { print; stop=1; system("./makesure -h") }
/^```$/ { stop=0 }
!stop' README.md > README.md.1
mv README.md.1 README.md
@goal checkREADME.md
@doc 'check all samples in README.md are correct'
awk -f check_samples_in_README.awk 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 -f minify.awk 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 fhtagn @args 'awk'
@depends_on tested_bwk
@depends_on tested_mawk133
@depends_on tested_mawk134
@depends_on tested_all_gawks
@depends_on tested_goawk
@depends_on tested_busybox
@goal tested_bwk @private
@depends_on installed_bwk
@depends_on fhtagn @args 'bwk'
@goal tested_mawk133 @private
@depends_on installed_mawk @args '1.3.3' 'mawk-1.3.3-20090920.tgz'
@depends_on fhtagn @args 'mawk1.3.3'
@goal tested_mawk134 @private
@depends_on installed_mawk @args '1.3.4' 'mawk-1.3.4-20200120.tgz'
@depends_on fhtagn @args 'mawk1.3.4'
@goal tested_all_gawks
@doc 'tests with all Gawk-s'
@depends_on tested_gawk @args '5.1.1' 'gawk511'
@depends_on tested_gawk @args '5.2.2' 'gawk522'
@depends_on tested_gawk @args '5.3.0' 'gawk530'
@goal tested_gawk @params VERSION EXE_NAME @private
@depends_on installed_gawk @args VERSION EXE_NAME
@depends_on fhtagn @args EXE_NAME
@goal tested_goawk @private
@depends_on installed_goawk
@depends_on fhtagn @args "$GOAWK"
@goal tested_busybox @private
@reached_if [[ "$OSTYPE" != "linux-gnu"* ]] # only test busybox awk on linux
@depends_on installed_busybox
@depends_on fhtagn @args 'busybox awk'
@goal tested_wak @private
#@depends_on installed_busybox TODO
@depends_on fhtagn @args '/home/xonix/soft/wak/exe/wak'
@goal installed_bwk @private
@reached_if [[ -f soft/bwk ]]
@depends_on soft_folder_created
@use_lib dl
echo
echo "Fetching BWK..."
echo
cd "soft"
download https://github.com/onetrueawk/awk/archive/refs/heads/master.tar.gz bwk.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
@goal installed_mawk @params VERSION TGZ @private
@reached_if [[ -f "soft/mawk$VERSION" ]]
@depends_on soft_folder_created
@use_lib dl
echo
echo "Fetching Mawk $VERSION..."
echo
cd "soft"
download "https://invisible-island.net/archives/mawk/$TGZ" "$TGZ"
tar xzvf "$TGZ"
rm "$TGZ"
echo
echo "Compile Mawk $VERSION..."
echo
cd mawk-"$VERSION"-*
./configure && make
exeName="mawk$VERSION"
mv mawk ../$exeName
cd ..
./$exeName -W version
rm -r mawk-"$VERSION"-*
@goal installed_gawk @params VERSION EXE_NAME @private
@reached_if [[ -f soft/"$EXE_NAME" ]]
@depends_on soft_folder_created
@use_lib dl
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
download "$dlUrl" "$G"
tar "${tarOpts:-xzvf}" "$G"
rm "$G"
echo
echo "Compile Gawk-$VERSION..."
echo
cd "$dlFolder"
./configure
make
# make check
mv gawk ../$EXE_NAME
mkdir ../${EXE_NAME}_libs
mv extension/.libs/*.so ../"${EXE_NAME}"_libs # for AWKLIBPATH
cd ..
./$EXE_NAME --version
rm -r "$dlFolder"
@goal installed_busybox @private
@reached_if [[ -x ./soft/busybox ]]
@use_lib dl
download 'https://busybox.net/downloads/binaries/1.31.0-i686-uclibc/busybox' ./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
@use_lib dl
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
download "https://github.com/benhoyt/goawk/releases/download/v$GOAWK_VERSION/$F" "$F"
tar xzvf "$F" goawk
rm "$F"
mv goawk $GOAWK
"./$GOAWK" --version
@define GOAWK_BRANCH 'length-array'
@define GOAWK_BRANCH_EXE "goawk_$GOAWK_BRANCH"
@goal tested_goawk_branch @private
@depends_on installed_goawk_branch
@depends_on fhtagn @args "$GOAWK_BRANCH_EXE"
@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
@use_lib dl
echo
echo "Fetching Just $JUST_VERSION ..."
echo
cd "soft"
F=just-$JUST_VERSION-x86_64-unknown-linux-musl.tar.gz
download "https://github.com/casey/just/releases/download/$JUST_VERSION/$F" "$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
# === Documentation site ===
@goal deploy_site
HOST='[email protected]'
DEST="$HOST":/var/www/makesure
rsync -aP build/ "$DEST/"
@goal site_compile
@depends_on site_soft_installed
rm -rf book; mkdir book; awk -f "$MDBOOKER" README.md
"$MDBOOK" build
"$MDBOOK_LINKCHECK" -s # check broken links
@goal site_soft_installed @private
@depends_on mdbook_installed
@depends_on mdbook-linkcheck_installed
@depends_on mdbooker_installed
@define MDBOOKER "./soft/mdbooker_$MDBOOKER_VERSION.awk"
@define MDBOOK "./soft/mdbook_$MDBOOK_VERSION"
@define MDBOOK_LINKCHECK "./soft/mdbook-linkcheck_$MDBOOK_LINKCHECK_VERSION"
@define MDBOOKER_URL "https://github.com/xonixx/mdbooker/raw/$MDBOOKER_VERSION/mdbooker.awk"
@goal mdbooker_installed @private
@depends_on soft_folder_created
@reached_if [[ -x "$MDBOOKER" ]]
@use_lib dl
download "$MDBOOKER_URL" "$MDBOOKER"
chmod +x "$MDBOOKER"
@goal mdbook_installed @private
@reached_if [[ -x "$MDBOOK" ]]
@use_lib dl
F="mdbook-$MDBOOK_VERSION-x86_64-unknown-linux-musl.tar.gz"
URL="https://github.com/rust-lang/mdBook/releases/download/$MDBOOK_VERSION/$F"
( cd /tmp
download "$URL" "$F"
tar -xzvf "$F" mdbook )
mv /tmp/mdbook "$MDBOOK"
"$MDBOOK" --version
rm "/tmp/$F"
@goal mdbook-linkcheck_installed @private
@reached_if [[ -x "$MDBOOK_LINKCHECK" ]]
@use_lib dl
F="mdbook-linkcheck.x86_64-unknown-linux-gnu.zip"
URL="https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases/download/$MDBOOK_LINKCHECK_VERSION/$F"
( cd /tmp
download "$URL" "$F"
unzip -p "$F" mdbook-linkcheck >mdbook-linkcheck )
mv /tmp/mdbook-linkcheck "$MDBOOK_LINKCHECK"
chmod +x "$MDBOOK_LINKCHECK"
"$MDBOOK_LINKCHECK" --version
rm "/tmp/$F"