-
Notifications
You must be signed in to change notification settings - Fork 4
/
tasks.toml
245 lines (206 loc) · 6.26 KB
/
tasks.toml
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
[[task]]
id = "prerelease"
description = """
- run the tests
- generate the docs
- generate the screenshots
"""
type = "short"
dependencies = ["screenshots", "generate-docs", "validate"]
[[task]]
id = "install"
type = "short"
dependencies = ["generate"]
cmd = "go install ./cmd/run"
[[task]]
id = "generate"
type = "short"
cmd = "go generate ./..."
[[task]]
id = "validate"
type = "short"
dependencies = ["generate", "test", "vulncheck", "staticcheck", "snapshot-cli", "shellcheck"]
[[task]]
id = "test"
type = "short"
cmd = "go test ./..."
[[task]]
id = "vulncheck"
type = "short"
cmd = "go run golang.org/x/vuln/cmd/govulncheck ./..."
[[task]]
id = "staticcheck"
type = "short"
cmd = "go run honnef.co/go/tools/cmd/staticcheck ./..."
[[task]]
id = "shellcheck"
type = "short"
cmd = "shellcheck $(git ls-files | grep 'sh$')"
[[task]]
id = "screenshots"
type = "short"
dependencies = [
"screenshot-tui",
"screenshot-printer",
"screenshot-nontty",
]
cmd = """
echo Cleaning up...
rm example/build.log
"""
[[task]]
id = "screenshot-tui"
type = "short"
dependencies = ["install", "screenshots-deps"]
cmd = """
cd example
go run github.com/charmbracelet/vhs ../screenshots/tui.tape
mv tui.gif ../screenshots/
"""
[[task]]
id = "screenshot-printer"
type = "short"
dependencies = ["install", "screenshots-deps"]
cmd = """
cd example
go run github.com/charmbracelet/vhs ../screenshots/printer.tape
mv printer.gif ../screenshots/
"""
[[task]]
id = "screenshot-nontty"
type = "short"
dependencies = ["install", "screenshots-deps"]
cmd = """
cd example
go run github.com/charmbracelet/vhs ../screenshots/nontty.tape
mv nontty.gif ../screenshots/
"""
[[task]]
id = "screenshots-deps"
type = "short"
cmd = """
if ! which ttyd ; then
echo "ttyd must be installed to generate screenshots"
exit 1
fi
if ! which ffmpeg ; then
echo "ffmpeg must be installed to generate screenshots"
exit 1
fi
"""
[[task]]
id = "reset-snapshot-failures"
type = "short"
cmd = """
cd pkg/run/testdata/snapshots
for d in * ; do
if test -f $d/fail.log ; then
echo removing $d
rm $d/fail.log
fi
done
"""
[[task]]
id = "overwrite-snapshots"
type = "short"
cmd = """
cd pkg/run/testdata/snapshots
for d in * ; do
if test -f $d/fail.log ; then
echo overwriting $d
mv $d/fail.log $d/out.log
fi
done
"""
[[task]]
id = "generate-docs"
type = "short"
cmd = """
godoc -http=0.0.0.0:3335 &
godocpid=$!
function kill_godoc() {
kill $godocpid
}
trap kill_godoc SIGINT
sha=$(git rev-parse --short HEAD)
for (( ; ; )); do
sleep 0.5
if [[ $(curl -so /dev/null -w '%{http_code}' "http://localhost:3335/pkg/github.com/amonks/run/pkg/run/") -eq 200 ]]; then
break
fi
done
wget --quiet --mirror --page-requisites --no-parent http://localhost:3335/pkg/github.com/amonks/run/pkg/run
kill_godoc
trap - SIGINT
cd localhost:3335
mv pkg/github.com/amonks/run/pkg/run index.html
rm -r pkg
# Make links outside the module use pkg.go.dev.
sd '"/pkg' '"https://pkg.go.dev/pkg' index.html
# Correct for putting run at the server root.
sd '"/lib' '"/run/lib' index.html
# Make source code links point to github.
sd '"/src/github.com/amonks/run/' '"https://github.com/amonks/run/blob/main/' index.html
# Try to convert the selection anchors on github links. Puzzlingly, godoc's
# line anchors are 10 less than you'd expect: eg #L100 highlights line 110.
grep '?s=\\d\\+:\\d\\+#L' index.html | while read -r old_line ; do
old_lineno="$(echo $old_line | sd '^.*\\?s=\\d+:\\d+#L(\\d+).*$' '$1')"
new_lineno="$(($old_lineno + 10))"
new_line="$(echo $old_line | sd '\\?s=\\d+:\\d+#L'$old_lineno '#L'$new_lineno)"
sd -s "$old_line" "$new_line" index.html
done
# Remove the topbar and footer entirely.
sed -i -e '/topbar/,+11d' index.html
sed -i -e '/footer/,+8d' index.html
# Remove the link to the subdirectories section.
sed -i -e '/#pkg-subdirectories/,+1d' index.html
# Remove the subdirectories section. This is insanely brittle. The
# subdirectories section is only 51 lines because we have exactly three
# subdirectories.
sed -i -e '/"pkg-subdirectories/,+51d' index.html
rm index.html-e
cd ..
if test -d docs ; then
rm -r docs
fi
mv localhost:3335 docs
"""
[[task]]
id = "generate-readme-usage"
type = "short"
cmd = """
README_USAGE_SECTION=$(sed -n '/<!-- usage-start -->/,/<!-- usage-end -->/p' README.md | sed '/<!-- usage-start -->\\|<!-- usage-end -->\\|```/d')
RUN_COMMAND_USAGE=$(go run ./cmd/run/... | sed -n '/USAGE/,/VERSION/p' | sed '/VERSION/d')
# Compare and update if necessary
if ! diff <(echo "$README_USAGE_SECTION") <(echo "$RUN_COMMAND_USAGE") > /dev/null; then
echo "The README section does not match the usage output. Updating the README section..."
# Remove the old usage section, keep markers
sed -i '/<!-- usage-start -->/,/<!-- usage-end -->/{//!d}' README.md
# Insert the new help output into README.md
TMP_FILE=$(mktemp)
echo '```' > "$TMP_FILE"
echo "$RUN_COMMAND_USAGE" >> "$TMP_FILE"
echo '```' >> "$TMP_FILE"
sed -i '/<!-- usage-start -->/r '"$TMP_FILE" README.md
rm "$TMP_FILE"
echo "README usage section has been updated."
else
echo "The README section matches the usage output."
fi
"""
[[task]]
id = "snapshot-cli"
type = "short"
dependencies = ["generate"]
cmd = """
mkdir -p testdata/cli_snapshots
CLICOLOR_FORCE=true go run ./cmd/run -version &> testdata/cli_snapshots/version
CLICOLOR_FORCE=true go run ./cmd/run -help &> testdata/cli_snapshots/help
CLICOLOR_FORCE=true go run ./cmd/run -credits &> testdata/cli_snapshots/credits
CLICOLOR_FORCE=true go run ./cmd/run -contributors &> testdata/cli_snapshots/contributors
CLICOLOR_FORCE=true go run ./cmd/run -license &> testdata/cli_snapshots/license
CLICOLOR_FORCE=true go run ./cmd/run -list &> testdata/cli_snapshots/list
if ! git diff --exit-code -- testdata/cli_snapshots ; then
exit 1
fi
"""