Duplicate trigger on the same commit - push and pull_request

Hi,

Scenario:

 - create branch in my repo, push some commit  - action is triggered on push event - it is ok I want to verify work on branch

 - create PR from branch in repo, so action is triggered twice on push and on pull_request event

Is it possible on push event detect that PR is opened and active so I can skip build on push event in this situation.

Or other propositions to prevent duplicate build on the same code in this scenario.

Hi @slawekjaranowski

First, I want to explain that the workflow run on pull_request event and on push event do not build the same code.The two builds are not duplicated.

For more detail explanation, you could check my reply in this ticket:https://github.community/t5/GitHub-Actions/Duplicate-checks-on-quot-push-quot-and-quot-pull-request-quot/m-p/52339/highlight/true#M8490

>>Is it possible on push event detect that PR is opened and active so I can skip build on push event in this situation.

There is an action to find the PR associated with the current commit: https://github.com/jwalton/gh-find-current-pr#gh-find-current-pr 

And you could try to cancel the workflow run which triggered on push event using this action.  Because the cancel action will need sometime to complete, so adding a run step to make the workflow run sleep for 5s would be great.  

There is an example workflow: 

on:
  push:
  pull_request:
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: jwalton/gh-find-current-pr@v1
      if: github.event_name == 'push'
      id: findPr
      with:
        github-token: ${{ secrets.GITHUB_TOKEN }}
    # This will cancel current push triggered workflow run, or be skipped if there is no current PR.
    - name: cancelling
      if: github.event_name == 'push' && steps.findPr.outputs.number
      uses: andymckay/cancel-action@0.2
    - run: sleep 5s
      if: github.event_name == 'push' && steps.findPr.outputs.number
    - uses: actions/checkout@v2
    - run: echo hello

I published “skip-duplicate-actions” to solve this problem: https://github.com/fkirc/skip-duplicate-actions/
Other than skipping duplicate triggers, it also prevents similar duplicates like tag-pushes right after commit-pushes.
You could give it a try if this is still an issue.