name: Update POT file

on:
  push:
    branches:
      - master
  workflow_dispatch:

jobs:
  check_new_string:
    name: Linux x64_64 (check)
    runs-on: ubuntu-latest

    outputs:
      output1: ${{ steps.step1.outputs.check_ret }}

    steps:
    - uses: actions/checkout@v5
      with:
        fetch-depth: '0'

    - id: step1
      name: Check if POT file needs to be regenerated
      run: echo "check_ret=$(bash ./scripts/check_new_strings.sh)" >> $GITHUB_OUTPUT

  update_pot_file:
    name: Linux x64_64 (L10n)
    runs-on: ubuntu-latest
    needs: check_new_string
    if: ${{ needs.check_new_string.outputs.output1 == 'REGEN' }}

    steps:
    - uses: actions/checkout@v5

    - uses: abbbi/github-actions-tune@v1

    - name: Install packages
      run: sudo apt-get install -y -qq cmake ninja-build gettext

    - name: Disable all options in CMakeLists.txt
      run: sed -i 's/ ON)$/ OFF)/g' "$GITHUB_WORKSPACE/CMakeLists.txt"

    - name: Generate files for build system
      run: cmake -S "$GITHUB_WORKSPACE" -B build -GNinja -DWITH_GETTEXT=1

    - name: Generate new POT file
      run: ninja -C build genpot

    - uses: EndBug/add-and-commit@v9
      with:
        add: 'po'
        message: 'Regen POT file'
        pull: '--ff-only'
        push: true
