-
Notifications
You must be signed in to change notification settings - Fork 0
/
report-one.sh
executable file
·178 lines (155 loc) · 4.79 KB
/
report-one.sh
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
#! /bin/bash
for cmd in curl jq gh; do
if ! which $cmd >/dev/null; then
echo "ERROR: $cmd not found"
exit 1
fi
done
sleep=0
show=false
dryrun=false
while [ $# -gt 0 ]; do
case "$1" in
--show)
show=true
;;
--sleep)
sleep=1
;;
--dry-run)
dryrun=true
;;
*)
break
;;
esac
shift
done
our_repo=https://github.com/behdad/google-fonts-ofl-interpolatable-results
dirname=$(dirname "$1")
basename=$(basename "$1" .metadata)
echo "Processing $basename"
# Check that basename ends in ttf
metadata=$"$dirname/$basename.metadata"
if [ ! -f "$metadata" ]; then
echo "ERROR: No metadata file found: $basename.metadata"
exit 1
fi
reportfile="$dirname/$basename.txt"
if [ ! -f "$reportfile" ]; then
echo "ERROR: No report file found: $basename.txt"
exit 1
fi
if [ ! -f "$dirname/$basename.pdf" ]; then
echo "ERROR: No PDF file found: $basename.pdf"
exit 1
fi
archive_url=$(cat $metadata | grep '^archive_url:' | tail -n 1 | cut -d' ' -f2 | sed -e 's/"//g')
if [ "x$archive_url" = xarchive_url: ]; then
archive_url=""
fi
if [ "x$archive_url" = x ]; then
archive_url=$(cat "$metadata" | grep '^archive:' | tail -n 1 | cut -d' ' -f2)
if [ "x$archive_url" = xarchive: ]; then
archive_url=""
fi
fi
repository_url=$(cat "$metadata" | grep '^repository_url:' | tail -n 1 | cut -d' ' -f2 | sed -e 's/"//g')
if [ "x$repository_url" = xrepository_url: ]; then
repository_url=""
fi
if [ "x$repository_url" = x ]; then
repository_url=$(cat "$metadata" | grep '^contribution_url:' | tail -n 1 | cut -d' ' -f2 | sed -e 's/"//g')
if [ "x$repository_url" = xrepository_url: ]; then
repository_url=""
fi
fi
if [ "x$repository_url" = x ]; then
# If archive_url is github, extract the repo URL from it
# For example, if archive_url is https://github.com/googlefonts/roboto-flex/releases/download/3.100/roboto-flex-fonts.zip
# then we just want https://github.com/googlefonts/roboto-flex
repository_url=$(echo "$archive_url" | sed -e 's/\/releases\/download\/.*//')
if [ "x$repository_url" = "x$archive_url" ]; then
# If archive_url is not github, then we don't know how to get the repo URL
repository_url=""
fi
fi
if [ "x$repository_url" = x ]; then
# Bail
echo "WARNING: Could not determine repository URL"
exit 1
fi
# Check that we have a repository URL that starts with https://github.com/
if [ x"$repository_url" = "${repository_url%https://github.com/}" ]; then
echo "INFO: Repository URL does not point to GitHub: $repository_url"
exit 1
fi
report="$(cat "$reportfile")"
if [ "x$report" = x ]; then
echo "INFO: No problems found in the report: $basename.txt"
exit 1
fi
# Get our own git revision
git_rev=$(git rev-parse HEAD)
# URL-encode it using jq!
basename_encoded=$(echo -n "$basename" | jq -sRr @uri)
pdf_url="$our_repo/raw/$git_rev/reports/$basename_encoded.pdf"
pdfviewer_url="$our_repo/blob/$git_rev/reports/$basename_encoded.pdf"
# Finally! Assemble the text.
title="Interpolation problems in \`$basename\`"
body="
Hello!
This is an automatically-generated report about possible interpolation problems in \`$basename\`, as found in the Google Fonts catalog.
"
if [ x"$archive_url" != x ]; then
archive_basename=$(echo "$archive_url" | sed 's@.*/releases/download/@@')
body="$body
The particular version of the font that was tested was [$archive_basename]($archive_url).
"
fi
body="$body
To download a PDF version of this report with helpful visuals of the problems, click [here]($pdf_url); Or to view it on the GitHub website, click [here]($pdfviewer_url).
"
body="$body
The report follows:
\`\`\`
$report
\`\`\`
"
body="$body
This report was generated using the \`fonttools varLib.interpolatable\` tool. We understand that sometimes the tool generates false-positives. Particularly for more complicated font designs. If you did not find this report useful, please accept our apologies and ignore / close it.
To give feedback about this report, please file an issue or open a discussion at [fonttools](https://github.com/fonttools/fonttools).
Please note that I am doing this as a community service and do not represent Google Fonts.
"
if $show; then
echo "Title: $title"
echo ""
echo "$body"
exit 0
fi
if [ -f "$dirname/$basename.issue" ]; then
echo "INFO: Issue already filed: $(cat "$dirname/$basename.issue")"
exit 1
fi
echo "Filing issue at $repository_url"
if [ x$dryrun = xtrue ]; then
exit 0
fi
# Double-check that the file exists
curl -I "$pdf_url" 2>/dev/null | head -n 1 | grep -q '^HTTP/.* [23]0[0-9]'
if [ $? -ne 0 ]; then
echo "ERROR: Could not find PDF report at $pdf_url; did you push?"
exit 1
fi
# Okay! File it!
issue_url=$(gh issue create \
--title "$title" \
--body "$body" \
--repo "$repository_url" | tail -n 1)
if [ -x"$issue_url" = -x ]; then
echo "ERROR: Could not file issue at $repository_url"
exit 1
fi
echo "$issue_url" | tee "$dirname/$basename.issue"
# Done! Sleep time!
sleep $sleep