Skip to content

Commit

Permalink
[Tidy] Pull material icons on a monthly basis (#973)
Browse files Browse the repository at this point in the history
  • Loading branch information
huong-li-nguyen authored Jan 31, 2025
1 parent 87e7653 commit 41865a6
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/update-icons.yml
Original file line number Diff line number Diff line change
@@ -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 "[email protected]"
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 }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Highlights ✨
- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Removed
- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Added
- A bullet item for the Added category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Changed
- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Deprecated
- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Fixed
- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Security
- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
1 change: 1 addition & 0 deletions vizro-core/hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ test-unit-coverage = [
"- coverage combine",
"coverage report"
]
update-icons = ["python tools/update_material_icons.py"]

[envs.docs]
dependencies = [
Expand Down
31 changes: 31 additions & 0 deletions vizro-core/tools/update_material_icons.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 41865a6

Please sign in to comment.