diff --git a/.github/workflows/open_pull_request.yml b/.github/workflows/open_pull_request.yml index 779734e11..91b1b4411 100644 --- a/.github/workflows/open_pull_request.yml +++ b/.github/workflows/open_pull_request.yml @@ -10,9 +10,6 @@ permissions: pull-requests: write contents: read -env: - MESSAGE: Merge branch `${{ github.head_ref || github.ref_name }}` to `main` - jobs: pull-request: name: Open pull request @@ -22,10 +19,24 @@ jobs: uses: actions/checkout@v7 - name: Open pull request - uses: repo-sync/pull-request@v2 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - destination_branch: 'main' - pr_title: 'chore: ${{ env.MESSAGE }}' - pr_body: 'This pull request will ${{ env.MESSAGE }}.' - pr_draft: true + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SOURCE_BRANCH: ${{ github.ref_name }} + TARGET_BRANCH: main + run: | + # Check if PR already exists (base=main, head=dev) + if gh pr list --base "$TARGET_BRANCH" --head "$SOURCE_BRANCH" --json number | jq -e '. | length > 0' >/dev/null; then + echo "Pull request already exists." + exit 0 + fi + + # Try to create the PR + gh pr create \ + --base "$TARGET_BRANCH" \ + --head "$SOURCE_BRANCH" \ + --title 'chore: Merge branch `dev` to `main`' \ + --body "When dev (pre-release) is ready, then merge this pull request to create a new stable release." \ + || { + echo "::error::Pull request creation failed. Ensure 'Allow GitHub Actions to create and approve pull requests' is enabled in the repo Settings > Actions > General > Workflow permissions" + exit 1 + }