GitHub: Skipping Workflow on Issues Update via API

Viewed 27

Maybe this is out of the box, maybe not. But I can't find this in any of the documentation.

I know you can skip workflows on Push and Pull_Requests. However, I need to skip workflows when updating Issues via the REST API.

My current workflow yaml looks like the following:

on:
  schedule:
    - cron: '10/15 * * * *'
  issues:
    types: [opened, closed, deleted, reopened, edited, labeled, unlabeled, assigned, unassigned]
  issue_comment:
    types: [created]

The schedule job does some clean-up on issues via a custom action that leverages the GitHub/Octokit REST API.

Is there a way that I can prevent the workflow from running if the issue is updated via the API?

1 Answers

As @GuiFalourd points out in the comments, I think you will need to use Workflow Expressions. To differentiate between a GitHub API call or a user interaction call I'm not sure if there is an official way to do so, I would open an issue in GitHub Community. I'm sure they will help you with that.

A couple of workarounds coming to my mind is to use a special 'Issue label' to mark when the GitHub API is used, this way you can filter accordingly (not a fan of this solution).

Also, if you are using a certain GitHub user to do API requests, you can use github.actor and github.triggering_actor from GitHub context to identify which user is triggering the event.

Here's a draft on how my approach would look like:

steps:
  - uses: actions/hello-world-javascript-action@v1.1
    if: ${{ contains(fromJson('["push", "pull_request"]'), github.event_name) && github.actor == <your_actor_name> }}
Related