GitHub Actions Workflow Generator · Tutorial
How to run tests on every pull request with GitHub Actions
8 min readbeginnerUpdated
You want every pull request to show a green tick only when the tests pass. You will generate a CI workflow for a Node.js project, add it to the repository and make it required before merging.
What you need
- The GitHub Actions Generator
- A GitHub repository with
lint,testandbuildscripts in package.json
Steps
Generate the workflow
Load the example: Node.js 22 and 24, runs on pushes to main and on pull requests, with npm ci, lint, test and build steps. Remove any command your project doesn’t have.
Add the file
Save it as
.github/workflows/ci.yml, commit and push.mkdir -p .github/workflows mv ~/Downloads/ci.yml .github/workflows/ci.yml git add .github/workflows/ci.yml git commit -m "Add CI workflow" git pushWatch it run
Open the Actions tab. You see two jobs, one per Node.js version. Click one to follow each step’s output.
Require it before merging
In Settings › Branches, add a rule for main and tick Require status checks to pass, then choose the build jobs. Pull requests can only be merged when they pass.
Try it yourself
Opens the GitHub Actions Workflow Generator with this tutorial's sample loaded.
Common mistakes
- Missing lock file
npm ciand the npm cache need package-lock.json. Commit it.- Tests that need a database or secrets
- Add the values under Settings › Secrets and variables › Actions and pass them to the step with
env:. Secrets aren’t available to pull requests from forks.
Next steps
Go back to the GitHub Actions Workflow Generator, or keep going with one of these:
FAQ
Does this cost money?
Public repositories get Actions minutes for free. Private repositories include a monthly allowance that depends on your plan.