name: Font update check

# **What it does**: Checks that the font cachebuster parameter has been updated if the font file has changed
# **Why we have it**: To make sure that browser font caching is invalidated and the updated font is used
# **Who does it impact**: Any PR which changes the font file

on:
  pull_request:
    types: [synchronize, opened]
    paths:
      - 'plugins/Morpheus/fonts/matomo.*'

permissions:
  actions: read
  checks: read
  contents: read
  deployments: none
  issues: read
  packages: none
  pull-requests: read
  repository-projects: none
  security-events: none
  statuses: read

jobs:
  check:
    runs-on: ubuntu-24.04
    steps:
     - uses: actions/checkout@v6
     - name: Compare stylesheet to base branch
       run: |
         if [[ $(wget -O - -o /dev/null https://raw.githubusercontent.com/matomo-org/matomo/$GITHUB_BASE_REF/plugins/Morpheus/stylesheets/base/icons.css | grep -m1  -- "format('woff2')") == $(grep -m1  -- "format('woff2')" plugins/Morpheus/stylesheets/base/icons.css) ]]
         then
           line=$(grep -n "format('woff2')" plugins/Morpheus/stylesheets/base/icons.css | cut -f1 -d:)
           echo "::error file=plugins/Morpheus/stylesheets/base/icons.css,line=$line::Font cachebuster parameter not updated. See https://developer.matomo.org/guides/matomo-font"
           exit 1
         else
           exit 0
         fi
