name: text.json → l10n-anytype-ts

on:
  push:
    paths:
      - 'src/json/text.json'
    branches:
      - main
  workflow_dispatch:

jobs:
  mirror-text-json:
    if: ${{ github.repository_owner == 'anyproto' }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout text.json
        uses: actions/checkout@v3
        with:
          repository: anyproto/anytype-ts
          sparse-checkout: |
            src/json/text.json
          sparse-checkout-cone-mode: false
          path: anytype-ts

      - name: Checkout l10n-anytype-ts
        uses: actions/checkout@v3
        with:
          repository: anyproto/l10n-anytype-ts
          path: l10n-anytype-ts
          token: ${{ secrets.ANY_CLA_TOKEN }}

      - name: Copy files
        run: |
          cp -f anytype-ts/src/json/text.json l10n-anytype-ts/text.json
          cp -f anytype-ts/src/json/text.json l10n-anytype-ts/locales/en-US.json
      
      - name: Commit and push changes to l10n-anytype-ts
        run: |
          cd l10n-anytype-ts
          git config --global user.email "association@anytype.io"
          git config --global user.name "Any Association"
          git add .
          git commit -m "Update source file"
          git push origin main

      - name: Send message to Slack
        id: slack
        uses: slackapi/slack-github-action@v1.24.0
        with:
          payload: |
            {
              "diff_link": "${{ github.event.compare }}"
            }
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
