Move Workflow Automation to GitHub Actions
How to do the job of each Workflow Automation action with a GitHub setting or a GitHub Actions workflow.
Workflow Automation is Sunset: nothing in Mergify replaces it. Every job its actions do has a counterpart on GitHub, either a repository setting or a step in a GitHub Actions workflow. This page maps each action to its counterpart.
Turning a rule into a workflow
Section titled Turning a rule into a workflowA rule’s conditions become the workflow’s on: trigger and a job if:, and
its actions become steps, most of them a gh command. The condition
table
of the github_actions migration guide maps the common conditions, and its
behavior differences
apply to every workflow you write this way.
This rule labels a hotfix and comments on it:
pull_request_rules: - name: triage hotfixes conditions: - base = main - head ~= ^hotfix/ actions: label: add: - hotfix comment: message: Thanks @{{ author }}, a maintainer will look at this hotfix first.The same job as a workflow:
name: Triage hotfixes
on: pull_request: types: [opened, reopened] branches: [main]
permissions: issues: write pull-requests: write
jobs: triage: if: startsWith(github.head_ref, 'hotfix/') runs-on: ubuntu-latest env: GH_TOKEN: ${{ github.token }} GH_REPO: ${{ github.repository }} PULL_REQUEST: ${{ github.event.pull_request.number }} AUTHOR: ${{ github.event.pull_request.user.login }} steps: - run: gh pr edit "$PULL_REQUEST" --add-label hotfix - run: gh pr comment "$PULL_REQUEST" --body "Thanks @$AUTHOR, a maintainer will look at this hotfix first."A rule runs comment or close once, when a pull request starts matching it,
and runs label or assign on every evaluation, to hold the pull request in
the state it describes. A workflow runs on every event its trigger lists: pick
the activity types (types:) that mark the moment the rule acted, and add the
ones that undo that state, such as unlabeled, where the rule held it.
Each action on GitHub
Section titled Each action on GitHub-
assign:gh pr edit --add-assigneeor--remove-assignee. -
backport: onpull_requestclosedwithgithub.event.pull_request.merged, cherry-pick the merge commit onto a branch cut from the target and open it withgh pr create, or use a backport action from the GitHub Marketplace. -
close:gh pr close --comment. -
comment:gh pr comment --body. -
copy: thebackportsteps, run without waiting for the merge and cherry-picking the pull request’s commits. -
delete_head_branch: the repository’s “Automatically delete head branches” setting. -
dismiss_reviews: “Dismiss stale pull request approvals when new commits are pushed” in a branch protection rule or a ruleset. -
edit:gh pr ready --undoconverts it to a draft, andgh pr readymarks it ready. -
github_actions: trigger the workflow from the event itself, as the migration guide shows. -
label:gh pr edit --add-labelor--remove-label;actions/labelerlabels from the files changed. -
merge: GitHub auto-merge (gh pr merge --auto) or Mergify’s Merge Queue. -
queue: Auto-Merge queues the pull requests that match its conditions. -
rebase:gh pr update-branch --rebase. -
request_reviews: aCODEOWNERSfile, orgh pr edit --add-reviewerwith users andorg/teamnames. A team takes a token that can read the organization, such as a GitHub App installation token:GITHUB_TOKENcannot. -
review:gh pr review --approve,--request-changesor--comment, with--body. A workflow approves a pull request withGITHUB_TOKENonly once the repository’s Actions settings allow GitHub Actions to create and approve pull requests. -
squash: the squash merge method, withgh pr merge --squashor as the only merge method the repository allows. -
update:gh pr update-branch, or the repository’s “Always suggest updating pull request branches” setting.
The backport and copy commands run
the same steps as their actions: trigger the workflow from a label
(pull_request with types: [labeled]) or from workflow_dispatch instead of
a comment.
Copy the values you set once in defaults.actions into each step that needs them.
Was this page helpful?
Thanks for your feedback!