-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakesurefile
257 lines (208 loc) · 6.09 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
# vim: syntax=bash
@options timing
@define NEXT_VERSION '0.2.1'
@define TUSH_REPO 'https://github.com/adolfopa/tush'
@define GOAWK_VERSION '1.29.1' # https://github.com/benhoyt/goawk/releases
@define GOAWK "./soft/goawk$GOAWK_VERSION"
@goal soft_folder_created @private
@reached_if [[ -d "soft" ]]
mkdir soft
@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 tush_installed @private
@depends_on soft_folder_created
@reached_if [[ -f "soft/tush/bin/tush-check" ]]
@use_lib dl
echo
echo "Fetching tush..."
echo
cd "soft"
if download "$TUSH_REPO/archive/master.tar.gz" ./tush.tar.gz
then
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 default
@doc 'same as tested_by_default_awk'
@depends_on tested_by_default_awk
@goal testall
@doc 'runs test suite'
@depends_on tested_by_default_awk
@depends_on tested_by_bwk
@depends_on tested_by_gawk
@depends_on tested_by @args 'tush' 'mawk -f ./fhtagn.awk'
@depends_on tested_by @args 'fhtagn' 'mawk -f ./fhtagn.awk'
@depends_on tested_by_busybox_awk
@depends_on tested_by_goawk
@goal tested_by_bwk
@depends_on installed_bwk
@depends_on tested_by @args 'tush' './soft/bwk -f ./fhtagn.awk'
@depends_on tested_by @args 'fhtagn' './soft/bwk -f ./fhtagn.awk'
@goal tested_by_gawk
@depends_on tested_by @args 'tush' 'gawk -f ./fhtagn.awk'
@depends_on tested_by @args 'fhtagn' 'gawk -f ./fhtagn.awk'
@goal tested_by_default_awk
@depends_on tested_by @args 'tush' './fhtagn.awk'
@depends_on tested_by @args 'fhtagn' './fhtagn.awk'
@goal tested_by_busybox_awk
@depends_on installed_busybox
@depends_on tested_by @args 'tush' './soft/busybox awk -f ./fhtagn.awk'
@depends_on tested_by @args 'fhtagn' './soft/busybox awk -f ./fhtagn.awk'
@goal tested_by_goawk
@depends_on installed_goawk
@depends_on tested_by @args 'tush' "$GOAWK -f ./fhtagn.awk"
@depends_on tested_by @args 'fhtagn' "$GOAWK -f ./fhtagn.awk"
@goal tested_by @params TOOL FHTAGN
@depends_on tush_installed
f=tests/fhtagn.tush
echo "Testing with $TOOL ($FHTAGN)..."
export FHTAGN
calc_temp_files() {
local tmp_count=$(find /tmp -maxdepth 1 -type f -name 'fhtagn.*' | wc -l)
local cnt
(( cnt = tmp_count ))
if [[ -d "/dev/shm" ]]
then
local shm_count=$(find /dev/shm -maxdepth 1 -type f -name 'fhtagn.*' | wc -l)
(( cnt += shm_count ))
fi
echo $cnt
}
test_file() {
if [[ $TOOL == "tush" ]]
then
export PATH="$PATH:$MYDIR/soft/tush/bin"
DIFF="diff --strip-trailing-cr" tush-check "$f"
else
local before_count=$(calc_temp_files)
./fhtagn.awk "$f"
local after_count=$(calc_temp_files)
if (( before_count != after_count ))
then
echo >&2 "!!! temp file not deleted !!!"
exit 1
fi
fi
}
if test_file
then
echo "TESTS PASSED : $f"
else
echo >&2 "!!! TESTS FAILED !!! : $f"
exit 1
fi
@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_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 $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"
"./goawk$GOAWK_VERSION" --version
@goal update_readme
@doc 'updates the README.md with the current output of the tool'
awk '
!Off
Examples {
if (/^\$/) { Off=1; system(substr($0,2)) }
else if (/^```$/ && Off) { Off=0; print }
}
/## Usage/ { Examples=1 }
' README.md > README.md.1
mv README.md.1 README.md
@define COVERPROFILE "/tmp/cov_fhtagn.txt"
@goal _cover_profile_deleted @private
rm -f "$COVERPROFILE"
@goal _cover_profile_prepared @private
@depends_on _cover_profile_deleted
@depends_on tested_by @args 'fhtagn' "$GOAWK -covermode=set -coverprofile=$COVERPROFILE -coverappend -f ./fhtagn.awk"
@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 '/fhtagn\.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 release_prepated
@doc 'prepares coverage badge & README'
@depends_on coverage_badge_updated
@depends_on update_readme
@goal gh_release
@doc 'publish Github release (draft)'
fail () {
echo >&2 "$@"
exit 1
}
releaseTag="v$NEXT_VERSION"
echo
echo "Will publish a draft release for $releaseTag ..."
echo
notesStr="[Issues included](https://github.com/xonixx/fhtagn/issues?q=is%3Aclosed+milestone%3A${NEXT_VERSION})"
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!"