Workflows run in check suite regardless of event triggers, running some actions twice

I have a workflow set up to run on pushes to a repository’s default branch. That workflow runs as expected. But when I open a pull request to merge the default branch into the master branch, the checks run again, along with every other workflow, regardless of the event that’s supposed to trigger those workflows.

This is a problem because one of the actions in the workflow publishes our code to npm, and the action (correctly) throws an error if we try to publish the same version twice.

It seems this is related to check suites that are automatically created in the default branch by GitHub Actions, but there’s no documentation on why this happens or how to stop it.

How can I make sure these actions only run on the events that are supposed to trigger them, and not during automatically created “check suites”?

Hi @mgerring ,

@mgerring wrote:
This is a problem because one of the actions in the workflow publishes our code to npm, and the action (correctly) throws an error if we try to publish the same version twice.

So the default branch is not master branch, and during pull_request will push code to default branch, trigger the push event again, is it right?

If it is, in pull request , did you use personal access token to push code ? Please use GITHUB_TOKEN instead, it will prevent the push events to be triggered again. Please refer to official doc for more details. 

Or, as an alternative, in push event yaml , use if expression in job level to exclude the job.

For example, if you’re user A, and push code in pull request with account B. (You can check the push events context, to confirm the event details)

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

Add below checking in push workflow yaml, it will only execute for userA’s commit.

jobs:
  job1:
<font color="#FF0000">if: github.actor == userA</font> runs-on: ubuntu-latest
    steps:....

It’s recommended to share your repo/sample repo for further investigation.

Thanks.

Hi @weide-zhou:

So the default branch is not master branch, and during pull_request will push code to default branch, trigger the push event again, is it right?

No, not quite. If I open a pull request from a feature branch to the default branch, the workflow doesn’t run until after the pull request is closed, and code is pushed to the default branch.

The problem occurs when I open a pull request from the default branch to the master branch. The workflow runs again as part of the pull requests’s check suite.

Hi @mgerring ,

Thanks for your reply. Could you please check github context for each workflow? It will display the trigger event details.

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

And did you have set branch protection rules for the default, master branches? Is any checkrun required? If there’re, please remove them and try again.

Since it’s a little strange for your workflow trigger, it’s recommened to share your repo/sample repo for further investigation.

Thanks.

@weide-zhou wrote:

Hi @mgerring ,

 

Thanks for your reply. Could you please check github context for each workflow? It will display the trigger event details.

 

GITHUB_CONTEXT: {
"token": "***",
"job": "npm-publish",
"ref": "refs/heads/develop",
"sha": "8b484a725df5b02fe6ea1b765c4fccebefd4438b",
"repository": "Genability/genability-js",
"repository_owner": "Genability",
"repositoryUrl": "git://github.com/Genability/genability-js.git",
"run_id": "108479620",
"run_number": "15",
"actor": "mgerring",
"workflow": "npm-publish-develop",
"head_ref": "",
"base_ref": "",
"event_name": "push",
"event": {
"after": "8b484a725df5b02fe6ea1b765c4fccebefd4438b",
"base_ref": null,
"before": "fbb2ffd1b26f38f3f312bc7ac5e8a9576fb8f996",
"commits": [
{
"author": {
"email": "gerring.matthew@gmail.com",
"name": "Matthew Gerring",
"username": "mgerring"
},
"committer": {
"email": "gerring.matthew@gmail.com",
"name": "Matthew Gerring",
"username": "mgerring"
},
"distinct": false,
"id": "12d04f4ec48153c97a6da3c1946f74abd3ff3aaa",
"message": "branches-ignore doesn't effect 2x run on pull request",
"timestamp": "2020-05-14T13:41:19-07:00",
"tree_id": "c87f3ec81ace8ce506eb095f57b5db5ea3f3f2c5",
"url": "https://github.com/Genability/genability-js/commit/12d04f4ec48153c97a6da3c1946f74abd3ff3aaa"
},
{
"author": {
"email": "gerring.matthew@gmail.com",
"name": "Matthew Gerring",
"username": "mgerring"
},
"committer": {
"email": "gerring.matthew@gmail.com",
"name": "Matthew Gerring",
"username": "mgerring"
},
"distinct": false,
"id": "4c23c96ba8d796faeae817f1bc45dc9803183ad3",
"message": "dump context for debugging",
"timestamp": "2020-05-18T11:44:03-07:00",
"tree_id": "81aa1d309fbe11036f6d9249c28619ee394f18a1",
"url": "https://github.com/Genability/genability-js/commit/4c23c96ba8d796faeae817f1bc45dc9803183ad3"
},
{
"author": {
"email": "gerring.matthew@gmail.com",
"name": "Matthew Gerring",
"username": "mgerring"
},
"committer": {
"email": "noreply@github.com",
"name": "GitHub",
"username": "web-flow"
},
"distinct": true,
"id": "8b484a725df5b02fe6ea1b765c4fccebefd4438b",
"message": "Merge pull request #32 from Genability/FB_18_better_versioning\n\nDebugging publish workflow",
"timestamp": "2020-05-18T11:46:45-07:00",
"tree_id": "4d73074e8172437d0970893ec8987f12ce4859dd",
"url": "https://github.com/Genability/genability-js/commit/8b484a725df5b02fe6ea1b765c4fccebefd4438b"
}
],
"compare": "https://github.com/Genability/genability-js/compare/fbb2ffd1b26f...8b484a725df5",
"created": false,
"deleted": false,
"forced": false,
"head_commit": {
"author": {
"email": "gerring.matthew@gmail.com",
"name": "Matthew Gerring",
"username": "mgerring"
},
"committer": {
"email": "noreply@github.com",
"name": "GitHub",
"username": "web-flow"
},
"distinct": true,
"id": "8b484a725df5b02fe6ea1b765c4fccebefd4438b",
"message": "Merge pull request #32 from Genability/FB_18_better_versioning\n\nDebugging publish workflow",
"timestamp": "2020-05-18T11:46:45-07:00",
"tree_id": "4d73074e8172437d0970893ec8987f12ce4859dd",
"url": "https://github.com/Genability/genability-js/commit/8b484a725df5b02fe6ea1b765c4fccebefd4438b"
},
"organization": {
"avatar_url": "https://avatars2.githubusercontent.com/u/726305?v=4",
"description": null,
"events_url": "https://api.github.com/orgs/Genability/events",
"hooks_url": "https://api.github.com/orgs/Genability/hooks",
"id": 726305,
"issues_url": "https://api.github.com/orgs/Genability/issues",
"login": "Genability",
"members_url": "https://api.github.com/orgs/Genability/members{/member}",
"node_id": "MDEyOk9yZ2FuaXphdGlvbjcyNjMwNQ==",
"public_members_url": "https://api.github.com/orgs/Genability/public_members{/member}",
"repos_url": "https://api.github.com/orgs/Genability/repos",
"url": "https://api.github.com/orgs/Genability"
},
"pusher": {
"email": "gerring.matthew@gmail.com",
"name": "mgerring"
},
"ref": "refs/heads/develop",
"repository": {
"archive_url": "https://api.github.com/repos/Genability/genability-js/{archive_format}{/ref}",
"archived": false,
"assignees_url": "https://api.github.com/repos/Genability/genability-js/assignees{/user}",
"blobs_url": "https://api.github.com/repos/Genability/genability-js/git/blobs{/sha}",
"branches_url": "https://api.github.com/repos/Genability/genability-js/branches{/branch}",
"clone_url": "https://github.com/Genability/genability-js.git",
"collaborators_url": "https://api.github.com/repos/Genability/genability-js/collaborators{/collaborator}",
"comments_url": "https://api.github.com/repos/Genability/genability-js/comments{/number}",
"commits_url": "https://api.github.com/repos/Genability/genability-js/commits{/sha}",
"compare_url": "https://api.github.com/repos/Genability/genability-js/compare/{base}...{head}",
"contents_url": "https://api.github.com/repos/Genability/genability-js/contents/{+path}",
"contributors_url": "https://api.github.com/repos/Genability/genability-js/contributors",
"created_at": 1587411820,
"default_branch": "develop",
"deployments_url": "https://api.github.com/repos/Genability/genability-js/deployments",
"description": "Node.js and Browser Javascript SDK for Genability APIs.",
"disabled": false,
"downloads_url": "https://api.github.com/repos/Genability/genability-js/downloads",
"events_url": "https://api.github.com/repos/Genability/genability-js/events",
"fork": false,
"forks": 0,
"forks_count": 0,
"forks_url": "https://api.github.com/repos/Genability/genability-js/forks",
"full_name": "Genability/genability-js",
"git_commits_url": "https://api.github.com/repos/Genability/genability-js/git/commits{/sha}",
"git_refs_url": "https://api.github.com/repos/Genability/genability-js/git/refs{/sha}",
"git_tags_url": "https://api.github.com/repos/Genability/genability-js/git/tags{/sha}",
"git_url": "git://github.com/Genability/genability-js.git",
"has_downloads": true,
"has_issues": true,
"has_pages": false,
"has_projects": true,
"has_wiki": true,
"homepage": null,
"hooks_url": "https://api.github.com/repos/Genability/genability-js/hooks",
"html_url": "https://github.com/Genability/genability-js",
"id": 257386564,
"issue_comment_url": "https://api.github.com/repos/Genability/genability-js/issues/comments{/number}",
"issue_events_url": "https://api.github.com/repos/Genability/genability-js/issues/events{/number}",
"issues_url": "https://api.github.com/repos/Genability/genability-js/issues{/number}",
"keys_url": "https://api.github.com/repos/Genability/genability-js/keys{/key_id}",
"labels_url": "https://api.github.com/repos/Genability/genability-js/labels{/name}",
"language": "TypeScript",
"languages_url": "https://api.github.com/repos/Genability/genability-js/languages",
"license": null,
"master_branch": "develop",
"merges_url": "https://api.github.com/repos/Genability/genability-js/merges",
"milestones_url": "https://api.github.com/repos/Genability/genability-js/milestones{/number}",
"mirror_url": null,
"name": "genability-js",
"node_id": "MDEwOlJlcG9zaXRvcnkyNTczODY1NjQ=",
"notifications_url": "https://api.github.com/repos/Genability/genability-js/notifications{?since,all,participating}",
"open_issues": 13,
"open_issues_count": 13,
"organization": "Genability",
"owner": {
"avatar_url": "https://avatars2.githubusercontent.com/u/726305?v=4",
"email": "support@genability.com",
"events_url": "https://api.github.com/users/Genability/events{/privacy}",
"followers_url": "https://api.github.com/users/Genability/followers",
"following_url": "https://api.github.com/users/Genability/following{/other_user}",
"gists_url": "https://api.github.com/users/Genability/gists{/gist_id}",
"gravatar_id": "",
"html_url": "https://github.com/Genability",
"id": 726305,
"login": "Genability",
"name": "Genability",
"node_id": "MDEyOk9yZ2FuaXphdGlvbjcyNjMwNQ==",
"organizations_url": "https://api.github.com/users/Genability/orgs",
"received_events_url": "https://api.github.com/users/Genability/received_events",
"repos_url": "https://api.github.com/users/Genability/repos",
"site_admin": false,
"starred_url": "https://api.github.com/users/Genability/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/Genability/subscriptions",
"type": "Organization",
"url": "https://api.github.com/users/Genability"
},
"private": true,
"pulls_url": "https://api.github.com/repos/Genability/genability-js/pulls{/number}",
"pushed_at": 1589827607,
"releases_url": "https://api.github.com/repos/Genability/genability-js/releases{/id}",
"size": 253,
"ssh_url": "git@github.com:Genability/genability-js.git",
"stargazers": 0,
"stargazers_count": 0,
"stargazers_url": "https://api.github.com/repos/Genability/genability-js/stargazers",
"statuses_url": "https://api.github.com/repos/Genability/genability-js/statuses/{sha}",
"subscribers_url": "https://api.github.com/repos/Genability/genability-js/subscribers",
"subscription_url": "https://api.github.com/repos/Genability/genability-js/subscription",
"svn_url": "https://github.com/Genability/genability-js",
"tags_url": "https://api.github.com/repos/Genability/genability-js/tags",
"teams_url": "https://api.github.com/repos/Genability/genability-js/teams",
"trees_url": "https://api.github.com/repos/Genability/genability-js/git/trees{/sha}",
"updated_at": "2020-05-15T09:36:02Z",
"url": "https://github.com/Genability/genability-js",
"watchers": 0,
"watchers_count": 0
},
"sender": {
"avatar_url": "https://avatars2.githubusercontent.com/u/287109?v=4",
"events_url": "https://api.github.com/users/mgerring/events{/privacy}",
"followers_url": "https://api.github.com/users/mgerring/followers",
"following_url": "https://api.github.com/users/mgerring/following{/other_user}",
"gists_url": "https://api.github.com/users/mgerring/gists{/gist_id}",
"gravatar_id": "",
"html_url": "https://github.com/mgerring",
"id": 287109,
"login": "mgerring",
"node_id": "MDQ6VXNlcjI4NzEwOQ==",
"organizations_url": "https://api.github.com/users/mgerring/orgs",
"received_events_url": "https://api.github.com/users/mgerring/received_events",
"repos_url": "https://api.github.com/users/mgerring/repos",
"site_admin": false,
"starred_url": "https://api.github.com/users/mgerring/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/mgerring/subscriptions",
"type": "User",
"url": "https://api.github.com/users/mgerring"
}
},
"workspace": "/home/runner/work/genability-js/genability-js",
"action": "run1"
}

And did you have set branch protection rules for the default, master branches? Is any checkrun required? If there’re, please remove them and try again.

 

Since it’s a little strange for your workflow trigger, it’s recommened to share your repo/sample repo for further investigation.

There are no branch protection rules set on any branch in the repository, but checks run automatically on any pull request involving the default branch.

The repo itself is private so I can’t share it, but the context is pasted above.

Hi @mgerring ,

Thanks for your reply. Base on your context, you have pushed code to the default branch during the workflow.

And I notice two ‘distinct: false’ commits, which means they have been pushed before.

How did you push the code? Are they included in your latest commit push? 

12d04f4ec48153c97a6da3c1946f74abd3ff3aaa

4c23c96ba8d796faeae817f1bc45dc9803183ad3

On my side, normally the distinct value is true.

Regards

So the issue here is that this workflow runs at times when I have not pushed anything to the default branch. This workflow is running whenever I open a pull request , with the master branch as the base and the default branch as the comparison branch.

The workflow runs as part of the default branch check suite, but that check suite is being created automatically – we do not have any checks enabled on the repository.

Hi @mgerring ,

Could you please share your yaml files for default branch and master branch?

If you remove push trigger(if exists) on default branch, create a pull_request from default to master, does the push event checkrun still start?