From 41865a6e88960be324278c491d5fb4dc95dae587 Mon Sep 17 00:00:00 2001 From: Li Nguyen <90609403+huong-li-nguyen@users.noreply.github.com> Date: Fri, 31 Jan 2025 11:12:23 +0100 Subject: [PATCH] [Tidy] Pull material icons on a monthly basis (#973) --- .github/workflows/update-icons.yml | 59 +++++++++++++++++++ ...817_huong_li_nguyen_update_icons_script.md | 48 +++++++++++++++ vizro-core/hatch.toml | 1 + vizro-core/tools/update_material_icons.py | 31 ++++++++++ 4 files changed, 139 insertions(+) create mode 100644 .github/workflows/update-icons.yml create mode 100644 vizro-core/changelog.d/20250130_110817_huong_li_nguyen_update_icons_script.md create mode 100644 vizro-core/tools/update_material_icons.py diff --git a/.github/workflows/update-icons.yml b/.github/workflows/update-icons.yml new file mode 100644 index 000000000..1c9b8c558 --- /dev/null +++ b/.github/workflows/update-icons.yml @@ -0,0 +1,59 @@ +name: Update Material Icons + +on: + schedule: + - cron: "0 0 1 * *" # Runs at midnight on the 1st of every month + +defaults: + run: + working-directory: vizro-core + +env: + PYTHON_VERSION: "3.12" + +jobs: + check-update: + runs-on: ubuntu-latest + steps: + - name: Checkout main branch + uses: actions/checkout@v4 + with: + ref: main + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + - name: Install Hatch + run: pip install hatch + - name: Update Material font + run: | + hatch run update-icons + - name: Check for changes + run: | + git config user.email "145135826+vizro-svc@users.noreply.github.com" + git config user.name "Vizro Team" + git diff --exit-code || echo "has_changes=true" >> $GITHUB_ENV + + update-icons: + runs-on: ubuntu-latest + needs: [check-update] + if: | + env.has_changes == 'true' + steps: + - name: Delete old branch if exists + run: | + git push origin --delete bot/update-material-icons || true + - name: Create and push changes + run: | + git checkout -b bot/update-material-icons + hatch run changelog:add + git add -A + git commit -m "Update Material Icons" + git push --set-upstream origin bot/update-material-icons + - name: Install GitHub CLI + run: sudo apt-get install -y gh + - name: Create Pull Request + run: | + gh pr create -B main -H bot/update-material-icons --title "[Bot] Update Material Icons" --body "Automated update of Material Icons" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/vizro-core/changelog.d/20250130_110817_huong_li_nguyen_update_icons_script.md b/vizro-core/changelog.d/20250130_110817_huong_li_nguyen_update_icons_script.md new file mode 100644 index 000000000..7c0d58d4f --- /dev/null +++ b/vizro-core/changelog.d/20250130_110817_huong_li_nguyen_update_icons_script.md @@ -0,0 +1,48 @@ + + + + + + + + + diff --git a/vizro-core/hatch.toml b/vizro-core/hatch.toml index 3e863b4d3..b843ab4de 100644 --- a/vizro-core/hatch.toml +++ b/vizro-core/hatch.toml @@ -72,6 +72,7 @@ test-unit-coverage = [ "- coverage combine", "coverage report" ] +update-icons = ["python tools/update_material_icons.py"] [envs.docs] dependencies = [ diff --git a/vizro-core/tools/update_material_icons.py b/vizro-core/tools/update_material_icons.py new file mode 100644 index 000000000..543c66851 --- /dev/null +++ b/vizro-core/tools/update_material_icons.py @@ -0,0 +1,31 @@ +"""Script to update the Google Material Design Icons font in the static folder.""" + +import logging +from pathlib import Path + +import requests + +FONT_URL = "https://github.com/google/material-design-icons/raw/refs/heads/master/variablefont/MaterialSymbolsOutlined%5BFILL,GRAD,opsz,wght%5D.woff2" +LOCAL_PATH = Path(__file__).parent.parent / "src/vizro/static/css/fonts/material-symbols-outlined.woff2" +STATUS_OK = 200 +TIMEOUT = 10 # seconds + +logging.basicConfig(level=logging.INFO, format="%(message)s") +logger = logging.getLogger(__name__) + + +def download_font(url, path): + """Downloads the Material Design Icons font from Google Fonts and saves it to the local static folder.""" + try: + response = requests.get(url, timeout=TIMEOUT) + if response.status_code == STATUS_OK: + path.write_bytes(response.content) + logger.info(f"✍️ Material font downloaded and saved to {path}") + else: + logger.error(f"❌ Failed to download Material font. Status code: {response.status_code}") + except requests.RequestException as e: + logger.error(f"❌ Failed to download Material font due to an unexpected error: {e}") + + +if __name__ == "__main__": + download_font(FONT_URL, LOCAL_PATH)