GitHub Actions - Trigger Workflow on Pull Request Merge

by
Jeremy Canfield |
Updated: May 15 2025
| GitHub Actions articles
GitHub Actions can be used to do something whenever something happens in one of your GitHub repositories. If you are not familiar with GitHub Actions, check out my article Getting Started with GitHub Actions.
Here is one way to trigger your GitHub Action workflow when a pull request gets merged into the main branch.
name: my-workflow
run-name: ${{ github.workflow }} run by ${{ github.actor }}
on:
pull_request:
types: [closed]
jobs:
my-job:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout branch ${{ github.event.pull_request.head.ref }} (Pull Request ${{ github.event.pull_request.number }})
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Get the list of files that were changed in Pull Request ${{ github.event.pull_request.number }}
id: changed-files
uses: tj-actions/changed-files@v40
- name: List all of the files that were changed in Pull Request ${{ github.event.pull_request.number }}
run: echo '${{ steps.diff.outputs.files }}'
Did you find this article helpful?
If so, consider buying me a coffee over at