name: Automation - Release Branch

on:
  push:
    tags:
      # Trigger on beta version tags (0.x.x series) to create release branch
      # This pattern matches: v0.{minor}.{patch} for new releases and bugfix releases
      - 'v0.[0-9]+.[0-9]+'
      - 'v0.[0-9]+.[0-9]+-*' # Also support release candidates if needed

permissions:
  contents: read

jobs:
  release-branch:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          fetch-depth: 0

      - name: Setup Go
        uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
        with:
          go-version: oldstable
          cache: false

      - name: Cache Go
        id: go-cache
        uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
        with:
          path: |
            ~/go/bin
            ~/go/pkg/mod
          key: go-cache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/go.sum') }}

      - name: Setup Git config
        run: |
          git config --global user.name "otelbot"
          git config --global user.email "197425009+otelbot@users.noreply.github.com"

      - name: Run release-branch.sh
        run: |
          ./.github/workflows/scripts/release-branch.sh
        env:
          UPSTREAM_REMOTE_NAME: "origin"
          MAIN_BRANCH_NAME: "main"
          GITHUB_REF: ${{ github.ref }}
