View as Markdown

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 workflow

A 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:

.mergify.ymlyaml
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:

.github/workflows/triage-hotfixes.yamlyaml
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.

  • assign: gh pr edit --add-assignee or --remove-assignee.

  • backport: on pull_request closed with github.event.pull_request.merged, cherry-pick the merge commit onto a branch cut from the target and open it with gh pr create, or use a backport action from the GitHub Marketplace.

  • close: gh pr close --comment.

  • comment: gh pr comment --body.

  • copy: the backport steps, 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 --undo converts it to a draft, and gh pr ready marks it ready.

  • github_actions: trigger the workflow from the event itself, as the migration guide shows.

  • label: gh pr edit --add-label or --remove-label; actions/labeler labels 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: a CODEOWNERS file, or gh pr edit --add-reviewer with users and org/team names. A team takes a token that can read the organization, such as a GitHub App installation token: GITHUB_TOKEN cannot.

  • review: gh pr review --approve, --request-changes or --comment, with --body. A workflow approves a pull request with GITHUB_TOKEN only once the repository’s Actions settings allow GitHub Actions to create and approve pull requests.

  • squash: the squash merge method, with gh pr merge --squash or 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?