From 6e34eda9afc516b18eb19bcafb8f164a19062458 Mon Sep 17 00:00:00 2001 From: afsu Date: Fri, 6 Dec 2024 02:26:20 +0000 Subject: [PATCH 1/2] build: set chinese font for matplotlib --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index b80c1b5..b991507 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,9 @@ COPY requirements.txt . RUN python -m pip install --no-cache-dir -r requirements.txt RUN mplfonts init +# set chinese font for matplotlib +RUN MATPLOTLIBRC=$(python -c "import matplotlib; print(matplotlib.matplotlib_fname())") && \ + sed -i 's/\s*font.family\s*:\s*sans-serif\s*/font.family: Noto Serif CJK SC, sans-serif/' $MATPLOTLIBRC USER $NB_UID RUN mkdir -p /home/jovyan/.ipython/profile_default/startup/ From 8f070a89048886dd0cd59c647be62f13fc21b837 Mon Sep 17 00:00:00 2001 From: afsu Date: Fri, 6 Dec 2024 02:26:29 +0000 Subject: [PATCH 2/2] chore: add font check workflow --- .github/workflows/font-check.yml | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/font-check.yml diff --git a/.github/workflows/font-check.yml b/.github/workflows/font-check.yml new file mode 100644 index 0000000..59dd288 --- /dev/null +++ b/.github/workflows/font-check.yml @@ -0,0 +1,58 @@ +name: Docker Image Font Check + +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: # Allows to trigger the workflow manually in GitHub UI + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-test-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: read + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5.6.1 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{version}} + type=sha,priority=850,prefix= + + - name: Build the Docker image + id: build + run: | + docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} . + + - name: Run font check script + run: | + echo ' + import matplotlib + font_family = matplotlib.rcParams["font.family"] + if "Noto Serif CJK SC" in font_family: + print("Font is correctly set to Noto Serif CJK SC") + exit(0) + else: + print("Font is not correctly set") + exit(1) + ' > check_font.py + + docker run --rm -v $(pwd)/check_font.py:/check_font.py ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} python /check_font.py + + - name: Clean up Docker images + run: | + docker rmi ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}