diff --git a/.github/workflows/shared-promote-auto-pr.yaml b/.github/workflows/shared-promote-auto-pr.yaml new file mode 100644 index 00000000..6118fe66 --- /dev/null +++ b/.github/workflows/shared-promote-auto-pr.yaml @@ -0,0 +1,34 @@ +name: Create Deployment Pull Request +on: + workflow_call: +jobs: + create_pr: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Create Pull Request + run: | + echo "branch ${{ github.ref }} was pushed to" + if [ ${{ github.ref }} == "refs/heads/main" ]; then + base="test" + elif [ ${{ github.ref }} == "refs/heads/test" ]; then + base="integ" + elif [ ${{ github.ref }} == "refs/heads/integ" ]; then + base="prod" + else + exit 0 + fi + echo "promotion is to ${base}" + + # Check if a PR already exists + existing_pr=$(gh pr list --base ${base} --head main --state open --json number --jq '.[0].number') + + if [ -z "$existing_pr" ]; then + echo "No existing PR found. Creating a new PR." + gh pr create --base ${base} --head main --title "PR from main to ${base}" --body "Automated PR from main to ${base} branch" + else + echo "PR already exists: #$existing_pr" + fi + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}