name: R generate configure

on:
  repository_dispatch:
    types: [gha_run_r_configure]

jobs:
  r-configure:
    name: r-configure
    timeout-minutes: 60
    runs-on: ubuntu-latest
    container: "ubuntu:20.04"
    steps:
      - name: Install essential software before checkout
        run: |
          apt-get update
          apt-get install --no-install-recommends -y \
            ca-certificates \
            git
      - name: Checkout repository
        uses: actions/checkout@v2.3.4
        with:
          fetch-depth: 5
          submodules: true
          repository: microsoft/LightGBM
          ref: "refs/heads/${{ fromJSON(github.event.client_payload.pr_branch) }}"
          token: ${{ secrets.WORKFLOW }}
          persist-credentials: true
      - name: Update configure
        shell: bash
        run: ./R-package/recreate-configure.sh || exit -1
      - name: Push changes
        run: |
          git config --global user.name "GitHub Actions Bot"
          git config --global user.email "githubactionsbot@users.noreply.github.com"
          git add "./R-package/configure"
          git commit --allow-empty -m "Auto-update configure"
          git push
