How to Fix CI Not Running for Pull Requests from Forked Repositories

Introduction

Recently, I’ve been fortunate to receive multiple contributions to my personal Chrome extension project, TabTabTab. To ensure smooth collaboration, I decided to properly configure GitHub branch protection rules, as well as checklists and restrictions for pre-merge processes.

However, I encountered an issue where workflows weren’t running for pull requests from forked repositories. Without the workflows running, merging these PRs was impossible. Despite carefully reading the official documentation and correctly configuring the Approval for running fork pull request workflows from contributors setting, I couldn’t get it to work. The documentation mentioned a “Approve and run workflows” button, but it never appeared.

After much trial and error, I finally resolved the issue, and I’m documenting the solution here.

Cause and Solution

The root cause was a trivial one: the workflow trigger was configured for push events only.

on: push

This makes sense in hindsight. Pull requests from forked repositories don’t count as pushes to the upstream repository, so this workflow wasn’t triggered. I had been using this setup for a while and assumed it was standard practice, which delayed my realization of the issue.

To fix this, I added the pull_request trigger to the workflow configuration as shown below:

on:
  push:
    branches:
      - main
      - develop
  pull_request:

With this configuration, whenever someone submits a new pull request, the “Approve and run workflows” button appeared as described in the documentation. Clicking this button successfully triggered the workflow.

Approve and run workflows

Conclusion

This oversight was simple, but it stumped me for longer than it should have. Surprisingly, I couldn’t find this solution through online searches, which suggests that others might not make the same mistake as often. Hopefully, this article helps anyone who encounters a similar issue.

References

Related Posts