From bcbf8463e61157b7a30a2cf6e77607b962723217 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Fri, 22 Jul 2022 14:07:54 -0700 Subject: [PATCH] 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 text old-commit-hash: 9ab1c492dd051276a422fbac38f754c4e6633f32 --- .github/workflows/badges.yaml | 53 ++++++++++++++++++++++ selfdrive/ui/translations/README.md | 4 ++ selfdrive/ui/translations/create_badges.py | 43 ++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 .github/workflows/badges.yaml create mode 100755 selfdrive/ui/translations/create_badges.py diff --git a/.github/workflows/badges.yaml b/.github/workflows/badges.yaml new file mode 100644 index 0000000000..68a13398f6 --- /dev/null +++ b/.github/workflows/badges.yaml @@ -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 diff --git a/selfdrive/ui/translations/README.md b/selfdrive/ui/translations/README.md index 96d251c953..1ed73a0484 100644 --- a/selfdrive/ui/translations/README.md +++ b/selfdrive/ui/translations/README.md @@ -1,5 +1,9 @@ # Multilanguage +[![language](https://raw.githubusercontent.com/commaai/openpilot/badges/translation_badge_main_zh-CHT.svg)](https://github.com/commaai/openpilot/blob/master/selfdrive/ui/translations/main_zh-CHT.ts) +[![language](https://raw.githubusercontent.com/commaai/openpilot/badges/translation_badge_main_zh-CHS.svg)](https://github.com/commaai/openpilot/blob/master/selfdrive/ui/translations/main_zh-CHS.ts) +[![language](https://raw.githubusercontent.com/commaai/openpilot/badges/translation_badge_main_ko.svg)](https://github.com/commaai/openpilot/blob/master/selfdrive/ui/translations/main_ko.ts) + ## Contributing Before getting started, make sure you have set up the openpilot Ubuntu development environment by reading the [tools README.md](/tools/README.md). diff --git a/selfdrive/ui/translations/create_badges.py b/selfdrive/ui/translations/create_badges.py new file mode 100755 index 0000000000..58b587462f --- /dev/null +++ b/selfdrive/ui/translations/create_badges.py @@ -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 = "= 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)