tl;dr


      - name: Only if auto-merge is enabled
        if: ${{ github.event.pull_request.auto_merge }}
        run: echo "Auto-merge IS ENABLED"

      - name: Only if auto-merge is NOT enabled
        if: ${{ !github.event.pull_request.auto_merge }}
        run: echo "Auto-merge is NOT enabled"

The use case that I needed was that I have a workflow that does a bunch of things that aren't really critical to test the PR, but they also take a long time. In particular, every pull request deploys a "preview environment" so you get a "staging" site for each pull request. Well, if you know with confidence that you're not going to be clicking around on that preview/staging site, why bother deploying it (again)?

Also, a lot of PRs get the "Auto-merge" enabled because whoever pressed that button knows that as long as it builds OK, it's ready to merge in.

What's cool about the if: statements above is that they will work in all of these cases too:


on:
  workflow_dispatch:
  pull_request:
  push:
     branches:
       - main

I.e. if this runs because it was a push to main the line ${{ !github.event.pull_request.auto_merge }} will resolve to truthy. Same if you use the workflow dispatch from workflow_dispatch.

Comments

Your email will never ever be published.

Previous:
Auto-merge GitHub pull requests based on "partial required checks" May 3, 2022 GitHub
Next:
Comparing compression commands with hyperfine July 6, 2022 Linux, Bash, macOS
Related by category:
How to run a GitHub Action workflow step if a file exists April 24, 2023 GitHub
Useful GitHub.com trick I learned today: l March 19, 2025 GitHub
How I built an index of my blog posts on my GitHub profile page December 13, 2024 GitHub
Search GitHub issues by title, only May 31, 2024 GitHub
Related by keyword:
How to run a GitHub Action workflow step if a file exists April 24, 2023 GitHub
Programmatically control the matrix in a GitHub Action workflow November 30, 2022 GitHub
How MDN's site-search works February 26, 2021 Python, Web development, Django, MDN, Elasticsearch
GitHub PR triage across multiple projects April 28, 2014 Web development, Mozilla, JavaScript