name: Check Missing Translations

permissions:
  contents: read

on:
  workflow_dispatch:
  pull_request_target:
    types: [opened, synchronize, reopened]

jobs:
  check-missing-translations:
    runs-on: ubuntu-latest
    steps:
      - name: Harden the runner (Audit all outbound calls)
        uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
        with:
          egress-policy: audit

      - name: Checkout repository
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
        with:
          ref: ${{ github.event.pull_request.base.ref }}

      - name: Checkout PR
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
        with:
          ref: ${{ github.event.pull_request.head.sha }}

      - name: Setup Node.js
        uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
        with:
          node-version: 18

      - name: Install Tolgee CLI
        run: npm install -g @tolgee/cli

      - name: Compare Tolgee Keys
        id: compare
        run: |
          tolgee compare --api-key ${{ secrets.TOLGEE_API_KEY }} > compare_output.txt
          cat compare_output.txt

      - name: Check for Missing Translations
        run: |
          if grep -q "new key found" compare_output.txt; then
            echo "New keys found that may require translations:"
            exit 1
          else
            echo "No new keys found."
          fi
