Execute job for all commits in pull request

I am looking for a way to execute a job in a GitHub-Actions workflow for every commit in a pull-request. Currently, jobs only run on the last commit.

My workflow looks something like this:

name: my-workflow

on:
  pull_request:
    branches: [ my-branch ]

jobs:
  build:
    runs-on: self-hosted

    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - name: Test
      run: ./my-test

Is there any solution?

1 Like

Hi @segeljakt,

Glad to see you in Github community Forum!

For pull request event, the GITHUB_REF is fake merge branch refs/pull/:prNumber/merge, and the GITHUB_SHA is Last merge commit on the GITHUB_REF branch, not the last commit. It only shows status check on the last commit, but actually in the workflow, it contains all the commits comparing between the target branch and base branch.

If you export the github context with below code:

      - name: Dump GitHub context
        env:
          GITHUB_CONTEXT: ${{ toJson(github) }}
        run: echo "$GITHUB_CONTEXT"

Check the commit_url, you could find multiple commits. Please refer to my workflow for an example(“changed_files”: 2).

It’s not supported to run workflow for each commit.

If you’d like to check for every commit, you have to merge the branch after each commit, and create a new pull request workflow for the new commit.

Hope it’s clear and helpful.

2 Likes