-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makesurefile
476 lines (385 loc) · 11.9 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
# vim: syntax=bash
@options timing
@define NEXT_VERSION '0.9.20'
@define GOAWK_VERSION '1.23.1'
@define JUST_VERSION '1.3.0'
@define FHTAGN_VERSION 'v0.1.0'
@define GOAWK "goawk$GOAWK_VERSION"
@define JUST "just$JUST_VERSION"
@define FHTAGN_URL "https://github.com/xonixx/fhtagn/raw/$FHTAGN_VERSION/fhtagn.awk"
@define REPO 'xonixx/makesure'
@define AWK "${AWK:-awk}"
@goal soft_folder_created @private
@reached_if [[ -d "soft" ]]
mkdir soft
@define FHTAGN "soft/fhtagn.awk"
@goal fhtagn_installed @private
@depends_on soft_folder_created
@reached_if [[ -x "$FHTAGN" ]]
if command -v wget >/dev/null
then
wget "$FHTAGN_URL" -O"$FHTAGN"
elif command -v curl >/dev/null
then
curl -L "$FHTAGN_URL" -o "$FHTAGN"
else
echo "can't dl fhtagn"
exit 2
fi
chmod +x "$FHTAGN"
@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_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
}
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"
export NEXT_VERSION
if ./soft/fhtagn.awk "$f"
then
echo "TESTS PASSED : $f"
else
echo >&2 "!!! TESTS FAILED !!! : $f"
exit 1
fi
}
@goal tested
@doc 'runs all *.tush tests'
@depends_on 'tests/*.tush'
@goal fhtagn
@doc 'runs all *.tush tests (fail at end)'
@depends_on prepared4tests
MAKESURE=makesure_dev ALL=1 ./soft/fhtagn.awk tests/*.tush
@goal @glob 'tests/*.tush' @private
@depends_on prepared4tests
@use_lib testing
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 _cover_profile_prepared @private
rm -f "$COVERPROFILE"
MAKESURE_AWK="$(pwd)/soft/$GOAWK" \
MAKESURE_AWK_OPTS="-covermode=set -coverprofile=$COVERPROFILE -coverappend" \
MAKESURE=makesure_dev \
./makesure tested
@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 '
/^\$ \.\/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
@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
./makesure -D MAKESURE_AWK="$(pwd)/soft/bwk" fhtagn
@goal tested_mawk133 @private
@depends_on installed_mawk133
./makesure -D MAKESURE_AWK="$(pwd)/soft/mawk133" fhtagn
@goal tested_mawk134 @private
@depends_on installed_mawk134
./makesure -D MAKESURE_AWK="$(pwd)/soft/mawk134" fhtagn
@goal tested_all_gawks
@doc 'tests with all Gawk-s'
@depends_on tested_gawk @args '5.1.0' 'gawk51'
@depends_on tested_gawk @args '5.1.1' 'gawk511'
@depends_on tested_gawk @args '5.2.2' 'gawk522'
@depends_on tested_gawk @args '5.2-stable' 'gawk52'
@goal tested_gawk @params VERSION EXE_NAME @private
@depends_on installed_gawk @args VERSION EXE_NAME
./makesure -D MAKESURE_AWKLIBPATH="$(pwd)/soft/${EXE_NAME}_libs" -D MAKESURE_AWK="$(pwd)/soft/${EXE_NAME}" fhtagn
@goal tested_goawk @private
@depends_on installed_goawk
./makesure -D MAKESURE_AWK="$(pwd)/soft/$GOAWK" fhtagn
@goal tested_goawk_branch @private
@depends_on installed_goawk_branch
./makesure -D MAKESURE_AWK="$(pwd)/soft/$GOAWK_BRANCH_EXE" tested
@goal tested_busybox @private
@reached_if [[ "$OSTYPE" != "linux-gnu"* ]] # only test busybox awk on linux
@depends_on installed_busybox
./makesure -D MAKESURE_AWK="$(pwd)/soft/busybox awk" fhtagn
@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"-*
}
@goal installed_gawk @params VERSION EXE_NAME @private
@reached_if [[ -f soft/"$EXE_NAME" ]]
@depends_on soft_folder_created
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 ../$EXE_NAME
mkdir ../${EXE_NAME}_libs
mv extension/.libs/*.so ../"${EXE_NAME}"_libs # for AWKLIBPATH
cd ..
./$EXE_NAME --version
rm -r "$dlFolder"
@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