GitHub Actions have different triggers. You can run an action when pushing code to a repository, or when creating a new tag. When building open source packages, you may receive pull requests from users. Typically, you want to run your test suite against the changed code in the pull request.
This tutorial shows you how to use pull requests as a trigger to run a GitHub Action.
GitHub Actions Series Overview
Run Actions on Pull Requests
When creating a new workflow in GitHub’s action builder the default trigger is the
push event. You want to extend this to push and pull request events.
Search the line
on: [push] in your GitHub Action workflow file. Extend it to
on: [push, pull_request] and you’re done.
Here’s a sample configuration to run your action when pushing code to the repository or on pull requests:
name: Run tests on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - name: …
This workflow configuration runs on every push and every pull request. Even for pull requests on feature branches or against a playground branch.
Refining the Pull Request Trigger
Open source projects receive unlimited GitHub Action minutes. Private repositories include 2,000 minutes each month. You may want to restrict action runs to save minutes.
For example, you can restrict actions on pull requests to only run when created against the
name: Run tests on: push: pull_request: branches: - master jobs: test: runs-on: ubuntu-latest steps: - name: …
This workflow configuration runs the jobs on each push and pull requests against the