name: Add New Terraform Casks
on:
  schedule:
    # Daily at 04:20 UTC
    - cron:  '20 4 * * *'
  workflow_dispatch: {}
jobs:
  add_new_casks:
    name: Add New Terraform Casks
    # Only run on the main repo
    if: github.repository == 'Yleisradio/homebrew-terraforms'
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository
        uses: actions/checkout@v2

      - name: Configure git
        run: |
          git config user.name github-actions
          git config user.email github-actions@github.com

      - name: Find and add new Casks
        shell: bash
        run: |
          ./scripts/add_new_terraform_casks | while read version; do
            echo "Adding v$version"
            git add "Casks/terraform-$version.rb"
            git commit -m "Add Terraform v$version"
          done

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v3
        with:
          branch: new-terraform-versions
          title: Add new Terraform versions
          body: |
            Generated by "${{ github.workflow }}" GitHub Action
          delete-branch: true
          author: github-actions <github-actions@github.com>
          committer: github-actions <github-actions@github.com>

Add automation for adding missing Terraform versions
Add automation for adding missing Terraform versions

Add a GihHub Action Workflow for create a PR for adding Casks for all
missing Terraform versions. The job is run daily, and canalso be
triggered manually. To avoid unnecessary PRs in forked repositories,
it will by default only run on the main (upstream) repository.
