Skip to content

Commit 4978384

Browse files
committed
Add option for automerger workflow to create non-draft PRs
Add an option to the GitHub automerger workflow to optionally create a PR as non-draft. When this is the case, the tests will be demanded by commenting `@swift-ci please test` on the created PR.
1 parent 736dbca commit 4978384

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

.github/workflows/create_automerge_pr.yml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,24 @@ name: Create automerge PR
3030
# pull-requests: write
3131
# with:
3232
# base_branch: release/6.2
33+
# # Optional: Set to false to automatically trigger tests via "@swift-ci please test" comment
34+
# # create_as_draft: false
3335
# ```
3436
#
3537
# PRs created by GitHub Actions don't kick off further actions (https://github.com/peter-evans/create-pull-request/blob/d57e551ebc1a16dee0b8c9ea6d24dba7627a6e35/docs/concepts-guidelines.md#triggering-further-workflow-runs).
36-
# As a workaround, we mark automerge PRs that are created by GitHub actions as draft and trigger the GitHub actions by marking the PR as ready for review. `ready_for_review` must be added to the PR types for this purpose, eg.
37-
# ```
38-
# on:
39-
# pull_request:
40-
# types: [..., ready_for_review]
41-
# ```
42-
# Unfortunately this will also re-trigger testing evenon a normal user's PR (which may have already been tested), but skipping them causes the checks to reset so this is the best we can do for now.
38+
# This workflow provides two approaches to trigger testing on automerge PRs:
39+
#
40+
# 1. **Draft PR approach (default)**: PRs are created as drafts and testing is triggered by marking the PR as ready for review.
41+
# For this approach, `ready_for_review` must be added to the PR types, eg.
42+
# ```
43+
# on:
44+
# pull_request:
45+
# types: [..., ready_for_review]
46+
# ```
47+
# Unfortunately this will also re-trigger testing even on a normal user's PR (which may have already been tested), but skipping them causes the checks to reset so this is the best we can do for now.
48+
#
49+
# 2. **Auto-trigger approach**: When `create_as_draft` is set to `false`, the workflow will only trigger Swift CI tests by commenting "@swift-ci please test" on the created PR. This does not trigger any GitHub actions.
50+
# This requires the repository to have the github-actions bot configured to respond to such comments.
4351

4452
permissions:
4553
contents: read
@@ -59,6 +67,10 @@ on:
5967
type: string
6068
description: The message that should be included in the PR created by this job
6169
default: This PR was automatically opened by a GitHub action. Review the changes included in this PR and determine if they should be included in the release branch. If yes, merge the PR. Otherwise revert changes that should not be included on this branch.
70+
create_as_draft:
71+
type: boolean
72+
description: Whether to create the PR as a draft
73+
default: true
6274

6375
jobs:
6476
create_merge_pr:
@@ -93,6 +105,10 @@ jobs:
93105
env:
94106
GH_TOKEN: ${{ github.token }}
95107
run: |
108+
# Define variables based on workflow input
109+
if [[ "${{ inputs.create_as_draft }} == "true" ]] ; then
110+
DRAFT_FLAG="--draft"
111+
fi
96112
# Create a branch for the PR instead of opening a PR that merges head_branch directly so that we have a fixed
97113
# target in the PR and don't modify the PR as new commits are put on the head branch.
98114
PR_BRANCH="automerge/merge-main-$(date +%Y-%m-%d_%H-%M)"
@@ -102,7 +118,13 @@ jobs:
102118
103119
gh pr create \
104120
--base "${{ inputs.base_branch }}" \
105-
--head "$PR_BRANCH" \
121+
--head "$PR_BRANCH" ${DRAFT_FLAG} \
106122
--title 'Merge `${{ inputs.head_branch }}` into `${{ inputs.base_branch }}`' \
107-
--body '${{ inputs.pr_message }}' \
108-
--draft
123+
--body '${{ inputs.pr_message }}'
124+
125+
# Trigger tests is requested
126+
if [[ "${{ inputs.create_as_draft }}" != "true" ]] ; then
127+
PR_URL=$(gh pr view "${PR_BRANCH}" --json url | jq -r '.url')
128+
129+
gh pr comment "$PR_URL" --body "@swift-ci please test"
130+
fi

0 commit comments

Comments
 (0)