---
name: Open Pull Request when an `auto-pr` is pushed for go-azure-sdk

on:
  push:
    branches:
      - 'auto-deps-pr/updating-go-azure-sdk-to-**'

jobs:
  open-pull-request:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1

      - name: "open a pull request"
        id: open-pr
        run: |
          version="$(echo $GH_REF | sed "s/auto-deps-pr\/updating-go-azure-sdk-to-//")"
          title="dependencies: updating \`hashicorp/go-azure-sdk\` to \`${version}\`"
          body="This PR updates \`hashicorp/go-azure-sdk\` to \`${version}\` - further details can be found in a comment."
          
          # this runs everytime the PR gets pushed too, whilst you can only create a PR a single time
          # so we should be smarter, but piping this to /dev/null is a fine workaround for MVP
          gh pr create --title "$title" --body "$body" -B "$PR_TARGET" > /dev/null

        env:
          PR_TARGET: "main"
          GH_TOKEN: ${{ secrets.SERVICE_ACCOUNT_TERRAFORM_TOKEN }}
          GH_REF: ${{ github.ref_name }}
