Multilanguage badges (#25244)
* Test badge * fix? * Test * debug * debug * debug * debug * debug * debug * debug * try this * need to build * a minute for what * download and commit test badge * get dynamically * fix * Add to readme * force push * should work * one step * Update badge * draft * clean up * remove these * one line is fine * Adding badges will have to be manual, but that should be fine * cause error * continue on error * hope this doesn't delete the badges * ugh, allow-failures would be so nice * whoops * yep need this * do this * now try a push * clean up * rm line * need this * see if this works * orange * does this work? * ? * do dis * needs to be global? * cool, this works cool, this works * run only on master * add back workflows * remove that * sorting * sorting * print badge markdown * it is bytes though? * run once more * revert * looks nicer * strange * no decimals * run again run once more * nice workflow_dispatch * only run on a schedule and remove error handling * make links absolute * adjust badge textpull/25261/head
parent
3117c069d8
commit
9ab1c492dd
3 changed files with 100 additions and 0 deletions
@ -0,0 +1,53 @@ |
||||
name: badges |
||||
on: |
||||
schedule: |
||||
- cron: '0 * * * *' |
||||
workflow_dispatch: |
||||
|
||||
env: |
||||
BASE_IMAGE: openpilot-base |
||||
DOCKER_REGISTRY: ghcr.io/commaai |
||||
|
||||
BUILD: | |
||||
docker pull $(grep -iohP '(?<=^from)\s+\S+' Dockerfile.openpilot_base) || true |
||||
docker pull $DOCKER_REGISTRY/$BASE_IMAGE:latest || true |
||||
docker build --cache-from $DOCKER_REGISTRY/$BASE_IMAGE:latest -t $DOCKER_REGISTRY/$BASE_IMAGE:latest -t $BASE_IMAGE:latest -f Dockerfile.openpilot_base . |
||||
RUN: docker run --shm-size 1G -v $PWD:/tmp/openpilot -w /tmp/openpilot -e PYTHONPATH=/tmp/openpilot -e NUM_JOBS -e JOB_ID -e GITHUB_ACTION -e GITHUB_REF -e GITHUB_HEAD_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_RUN_ID -v /tmp/scons_cache:/tmp/scons_cache -v /tmp/comma_download_cache:/tmp/comma_download_cache -v /tmp/openpilot_cache:/tmp/openpilot_cache $BASE_IMAGE /bin/sh -c |
||||
|
||||
jobs: |
||||
badges: |
||||
name: create badges |
||||
runs-on: ubuntu-latest |
||||
steps: |
||||
- uses: actions/checkout@v3 |
||||
with: |
||||
submodules: true |
||||
|
||||
- name: Cache scons |
||||
id: scons-cache |
||||
# TODO: Change the version to the released version when https://github.com/actions/cache/pull/489 (or 571) is merged. |
||||
uses: actions/cache@03e00da99d75a2204924908e1cca7902cafce66b |
||||
env: |
||||
CACHE_SKIP_SAVE: true |
||||
with: |
||||
path: /tmp/scons_cache |
||||
key: scons-${{ hashFiles('.github/workflows/selfdrive_tests.yaml') }}- |
||||
restore-keys: | |
||||
scons-${{ hashFiles('.github/workflows/selfdrive_tests.yaml') }}- |
||||
scons- |
||||
|
||||
- name: Build Docker image |
||||
run: eval "$BUILD" |
||||
|
||||
- name: Push badges |
||||
run: | |
||||
${{ env.RUN }} "scons -j$(nproc) && python selfdrive/ui/translations/create_badges.py" |
||||
|
||||
git checkout --orphan badges |
||||
git rm -rf --cached . |
||||
git config user.email "badge-researcher@comma.ai" |
||||
git config user.name "Badge Researcher" |
||||
|
||||
git add translation_badge_*.svg |
||||
git commit -m "Add/Update badges" |
||||
git push -f origin HEAD |
@ -0,0 +1,43 @@ |
||||
#!/usr/bin/env python3 |
||||
import json |
||||
import os |
||||
import requests |
||||
|
||||
from common.basedir import BASEDIR |
||||
from selfdrive.ui.update_translations import LANGUAGES_FILE, TRANSLATIONS_DIR |
||||
|
||||
TRANSLATION_TAG = "<translation" |
||||
UNFINISHED_TRANSLATION_TAG = "<translation type=\"unfinished\"" |
||||
TRANSLATION_BADGE = "translation_badge_{}.svg" |
||||
TRANSLATION_LINK = "https://github.com/commaai/openpilot/blob/master/selfdrive/ui/translations/{}" |
||||
|
||||
if __name__ == "__main__": |
||||
with open(LANGUAGES_FILE, "r") as f: |
||||
translation_files = json.load(f) |
||||
|
||||
print("Copy into selfdrive/ui/translations/README.md:\n") |
||||
for name, file in translation_files.items(): |
||||
if not len(file): |
||||
continue |
||||
|
||||
with open(os.path.join(TRANSLATIONS_DIR, f"{file}.ts"), "r") as tr_f: |
||||
tr_file = tr_f.read() |
||||
|
||||
print(f"[})]({TRANSLATION_LINK.format(file)}.ts)") |
||||
|
||||
total_translations = 0 |
||||
unfinished_translations = 0 |
||||
for line in tr_file.splitlines(): |
||||
if TRANSLATION_TAG in line: |
||||
total_translations += 1 |
||||
if UNFINISHED_TRANSLATION_TAG in line: |
||||
unfinished_translations += 1 |
||||
|
||||
percent_finished = int(100 - (unfinished_translations / total_translations * 100.)) |
||||
color = "green" if percent_finished == 100 else "orange" if percent_finished >= 70 else "red" |
||||
|
||||
r = requests.get(f"https://img.shields.io/badge/LANGUAGE {name}-{percent_finished}%25 complete-{color}") |
||||
assert r.status_code == 200, "Error downloading badge" |
||||
|
||||
with open(os.path.join(BASEDIR, TRANSLATION_BADGE.format(file)), "wb") as badge_f: |
||||
badge_f.write(r.content) |
Loading…
Reference in new issue