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

Steps

  1. 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.

  2. 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 push
  3. Watch it run

    Open the Actions tab. You see two jobs, one per Node.js version. Click one to follow each step’s output.

  4. 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.

Try it now

Common mistakes

Missing lock file
npm ci and 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.