name: Update Cucumber

on:
  schedule:
    -   cron: '0 7 * * *'

jobs:
  cucumber-update:
    runs-on: ubuntu-latest
    name: Upstream cucumber update
    steps:
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 7.4
          coverage: none

      - uses: actions/checkout@v2

      - name: Install dependencies
        run: composer update

      - name: Update cucumber tag
        id: cucumber
        run: bin/update_cucumber

      - name: Re-install dependencies
        run: composer update
        if: steps.cucumber.outputs.cucumber_version

      - name: Update translations
        run: bin/update_i18n
        if: steps.cucumber.outputs.cucumber_version

      - name: Find changelog
        id: changelog
        run: bin/cucumber_changelog ${{ steps.cucumber.outputs.cucumber_version }}
        if: steps.cucumber.outputs.cucumber_version

      - name: Open a PR
        uses: peter-evans/create-pull-request@v3
        if: steps.cucumber.outputs.cucumber_version
        with:
          commit-message: Automatic Cucumber tag update to ${{ steps.cucumber.outputs.cucumber_version }}
          branch: cucumber-update-${{ steps.cucumber.outputs.cucumber_version }}
          delete-branch: true
          title: Cucumber update ${{ steps.cucumber.outputs.cucumber_version }}
          body: ${{ steps.changelog.outputs.changelog }}
          base: 'master'
