From 76268ab0c9b4e4d030b2d16272bfbdcad5172aad Mon Sep 17 00:00:00 2001
From: Richard Si <63936253+ichard26@users.noreply.github.com>
Date: Sun, 14 Feb 2021 10:23:47 -0500
Subject: [PATCH] Fix duplication of checks on internal PRs (#1986)

Internal PRs (that come from branches of psf/black) match both the push
and pull_request events. This leads to a duplication of test, lint, etc.
checks on such PRs. Not only is it a waste of resources, it makes the
Status Checks UI more frustrating to go through.

Patch taken from:
https://github.community/t/duplicate-checks-on-push-and-pull-request-simultaneous-event/18012
---
 .github/workflows/doc.yml    | 8 +++++++-
 .github/workflows/fuzz.yml   | 7 +++++++
 .github/workflows/lint.yml   | 7 +++++++
 .github/workflows/primer.yml | 7 +++++++
 .github/workflows/test.yml   | 7 +++++++
 5 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml
index d266e55..930b6d4 100644
--- a/.github/workflows/doc.yml
+++ b/.github/workflows/doc.yml
@@ -16,8 +16,14 @@ on:
 
 jobs:
   build:
-    runs-on: ubuntu-latest
+    # We want to run on external PRs, but not on our own internal PRs as they'll be run
+    # by the push to the branch. Without this if check, checks are duplicated since
+    # internal PRs match both the push and pull_request events.
+    if:
+      github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
+      github.repository
 
+    runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v2
 
diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml
index 0153767..f3b688f 100644
--- a/.github/workflows/fuzz.yml
+++ b/.github/workflows/fuzz.yml
@@ -4,6 +4,13 @@ on: [push, pull_request]
 
 jobs:
   build:
+    # We want to run on external PRs, but not on our own internal PRs as they'll be run
+    # by the push to the branch. Without this if check, checks are duplicated since
+    # internal PRs match both the push and pull_request events.
+    if:
+      github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
+      github.repository
+
     runs-on: ubuntu-latest
     strategy:
       fail-fast: false
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index fa7286e..e01e9ad 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -4,6 +4,13 @@ on: [push, pull_request]
 
 jobs:
   build:
+    # We want to run on external PRs, but not on our own internal PRs as they'll be run
+    # by the push to the branch. Without this if check, checks are duplicated since
+    # internal PRs match both the push and pull_request events.
+    if:
+      github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
+      github.repository
+
     runs-on: ubuntu-latest
     strategy:
       matrix:
diff --git a/.github/workflows/primer.yml b/.github/workflows/primer.yml
index b623b93..4c5751a 100644
--- a/.github/workflows/primer.yml
+++ b/.github/workflows/primer.yml
@@ -4,6 +4,13 @@ on: [push, pull_request]
 
 jobs:
   build:
+    # We want to run on external PRs, but not on our own internal PRs as they'll be run
+    # by the push to the branch. Without this if check, checks are duplicated since
+    # internal PRs match both the push and pull_request events.
+    if:
+      github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
+      github.repository
+
     runs-on: ${{ matrix.os }}
     strategy:
       fail-fast: false
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 8dd4e4f..bec7690 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -4,6 +4,13 @@ on: [push, pull_request]
 
 jobs:
   build:
+    # We want to run on external PRs, but not on our own internal PRs as they'll be run
+    # by the push to the branch. Without this if check, checks are duplicated since
+    # internal PRs match both the push and pull_request events.
+    if:
+      github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
+      github.repository
+
     runs-on: ${{ matrix.os }}
     strategy:
       fail-fast: false
-- 
2.39.5