Skip to content

Commit

Permalink
Anybadge is cool, but shields.io saves us 8 megabytes...
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed Oct 16, 2023
1 parent f2e25db commit 9504c00
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 20 deletions.
32 changes: 17 additions & 15 deletions dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import time
from pathlib import Path
from collections import Counter, defaultdict
from urllib.parse import quote

import anybadge
import fontbakery
import htmlmin
from packaging.version import parse as parse_version
from shaperglot.languages import Languages
from gflanguages import LoadScripts
Expand All @@ -22,6 +23,8 @@

FONTBAKERY_BLACKLISTED = ["handjet", "adobeblank"]

BASE_URL = "https://simoncozens.github.io/gf-dashboard/"

TESTING = False

langs = Languages()
Expand Down Expand Up @@ -123,14 +126,8 @@ def fontbakery_badges(basedir):
for badge in glob.glob(f"docs/fontbakery-reports/{basedir}/*.json"):
if "Shaping" in badge:
continue
result = json.load(open(badge))
color = result["color"].replace("bright", "light")
try:
anybadge.Color[color.upper()]
except KeyError:
color = "lightgrey"
badge = anybadge.Badge(result["label"], result["message"], default_color=color)
fb_badges.append(badge)
url = BASE_URL + "fontbakery-reports/" + basedir + "/" + os.path.basename(badge)
fb_badges.append(f"https://img.shields.io/endpoint?url="+quote(url, safe=""))
return fb_badges


Expand Down Expand Up @@ -229,24 +226,28 @@ def rearrange_languages(languages):
gf.fontbakery_report = os.path.basename(directory) + "-report.html"
gf.fb_badges = fontbakery_badges(os.path.basename(directory))
gf.fb_fails = fontbakery_fails(os.path.basename(directory))
gf.version_badges = [anybadge.Badge("google/fonts", tidy_version(gf.dev_version))]
gf.version_badges = [
f"https://img.shields.io/badge/google/fonts-{tidy_version(gf.dev_version)}-green"
]
color = "green"
last_version = tidy_version(gf.dev_version)
for s in servers:
if gf.server_versions.get(s.name):
version = tidy_version(gf.server_versions[s.name])
if str(version) < str(gf.version_badges[-1].value).strip():
if str(version) < str(last_version).strip():
color = "orange"
gf.version_badges.append(
anybadge.Badge(s.name, version, default_color=color)
f"https://img.shields.io/badge/{s.name}-{version}-{color}"
)
last_version = version
gf.build_badges = []
if gf.seems_gfr:
workflows = list(gf.upstream_gh.get_workflows())
for workflow in workflows or []:
runs = list(workflow.get_runs())
if runs and len(runs) > 0:
gf.build_badges.append(
anybadge.Badge(workflow.name, runs[0].conclusion)
f"https://img.shields.io/badge/{workflow.name}-{runs[0].conclusion}"
)

gf.languages = rearrange_languages(gf.supported_languages)
Expand All @@ -266,7 +267,6 @@ def rearrange_languages(languages):
classes.append("inpipeline")
gf.classes = " ".join(classes)
# Downstream versions if noto
# Version history
fonts.append(gf)
if TESTING and len(fonts) > 15:
break
Expand All @@ -283,5 +283,7 @@ def ago(dt):
env = Environment(loader=FileSystemLoader("templates"), autoescape=select_autoescape())
env.filters["ago"] = ago
template = env.get_template("index.html")
html = template.render(fonts=fonts, BASE_URL=BASE_URL)
html = htmlmin.minify(html)
with open("docs/index.html", "w") as f:
f.write(template.render(fonts=fonts))
f.write(html)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ gflanguages
PyGithub
tqdm
Jinja2
anybadge
humanize
github3api
certifi
packaging
shaperglot @ git+https://github.com/googlefonts/shaperglot
htmlmin
4 changes: 2 additions & 2 deletions templates/fontbakery.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ <h6>Failing tests</h6>
{% endif %}
<div class="fontbakery-badges">
{% for badge in font.fb_badges %}
{{badge |safe}}
<img src="{{badge |safe}}">
{% endfor %}
</div>
{% if font.fontbakery_report %}
<li><a href="fontbakery-reports/{{font.fontbakery_report}}">Full Fontbakery report</a></li>
{% endif %}
</div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion templates/render_font.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ <h2 class="mb-4 mt-4"> {{ font.metadata.name }}
<a href=" https://fonts.google.com/specimen/{{font.metadata.name | urlencode}}"><span class="material-symbols-outlined">link</span></a>
<span class="version-badges">
{% for badge in font.version_badges %}
{{badge |safe}}
<img src="{{badge |safe}}" />
{% endfor %}
</span>
</h2>
Expand Down
2 changes: 1 addition & 1 deletion templates/upstream.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h6>Latest releases</h6>
<!-- build badges -->
<div class="build-badges">
{% for badge in font.build_badges %}
{{badge |safe}}
<img src="{{badge |safe}}" />
{% endfor %}
</div>
</div>
Expand Down

0 comments on commit 9504c00

Please sign in to comment.