name: "Update pot and po files"
description: Update pot and po files using gotext.
inputs:
  domain:
    description: Domain to attach translation to.
    required: true
  po-directory:
    description: Directory containing pot and po files to update.
    default: "po/"
  entrypoints:
    description: List of comma-separated entry points importing all other package paths to extract translation form.
    required: true

runs:
  using: "composite"
  steps:
    - uses: actions/setup-go@v4
      with:
        go-version-file: go.mod
        check-latest: true
        cache: false
    - name: Generate pot and refresh *.po files
      shell: bash
      run: |
        # Generate pot and refresh *.po files
        set -eux

        # Split all entries in separate args
        entrypoints=""
        OLDIFS="${IFS}"
        IFS=','
        # We need to expand it in the for loop for IFS to be taken into account.
        eps='${{ inputs.entrypoints }}'
        for entry in ${eps} ; do
          if [ -z "${entrypoints}" ]; then
            entrypoints="${entry}"
            continue
          fi
          entrypoints="${entrypoints} ${entry}"
        done
        IFS="${OLDIFS}"

        cd ${{ github.action_path }}
        go build ./cmd/update-po/
        cd -

        ${{ github.action_path }}/update-po "${{ inputs.domain }}" "${{ inputs.po-directory }}" ${entrypoints}
