name: Update assets

on:
  push:
    branches: [ master ]
    paths:
      - icons.tsv
      - vectors/*
  workflow_dispatch:

jobs:
  update_assets:
    runs-on: ubuntu-latest
    steps:
      - name: Fetch repo
        uses: actions/checkout@v4

      - name: Fetch dependencies
        run: |
          sudo apt update -y -q
          sudo apt install jq nodejs wkhtmltopdf -y -q
          npm install nunjucks

      # Ubuntu 20.04 has only fontforge release 2020, but there are some vital bugfixes in the 2023 release
      # This can be replaced with the ordinary apt package when Ubuntu updates, probably with 23.10
      # On the other hand ... why not be on the latest release always?
      - name: Fetch FontForge
        run: |
          sudo apt install fuse -y -q
          curl -L "https://github.com/fontforge/fontforge/releases/download/20230101/FontForge-2023-01-01-a1dad3e-x86_64.AppImage" \
            --output fontforge
          chmod u+x fontforge
          echo Try appimage
          ./fontforge --version
          export PATH=`pwd`:$PATH
          echo "PATH=$PATH" >> $GITHUB_ENV
          echo Try appimage with path
          fontforge --version

      - name: Create the assets
        run: |
          make

      - name: Commit preview image back to repo
        uses: EndBug/add-and-commit@v9
        with:
          add: 'assets/readme-header.png'
          message: "[ci] Update preview image"
          committer_name: GitHub Actions
          committer_email: 41898282+github-actions[bot]@users.noreply.github.com

      - name: Deploy assets to gh-pages
        uses: JamesIves/github-pages-deploy-action@v4
        with:
          folder: assets
          target-folder: assets
          commit-message: "[ci] Update assets"
          git-config-name: GitHub Actions
          git-config-email: 41898282+github-actions[bot]@users.noreply.github.com
          clean: false