From 934f2443e44600a4342078c5efb3deaea5989494 Mon Sep 17 00:00:00 2001
From: chris48s <chris48s@users.noreply.github.com>
Date: Fri, 21 Oct 2022 09:13:02 +0100
Subject: [PATCH] fixes for integration test rate limit issues (#8538)

* constrain auto-close and enforce-dependency-review triggers

we don't need to run these on PR close or when we apply labels, for example

* skip workflows on push to dependabot branch

* use PAT if available else fall back to workflow token

* further constrain pull_request triggers

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
---
 .github/workflows/auto-close.yml                |  4 +++-
 .github/workflows/enforce-dependency-review.yml |  4 +++-
 .github/workflows/test-integration-17.yml       | 13 ++++++++++++-
 .github/workflows/test-integration.yml          | 13 ++++++++++++-
 .github/workflows/test-lint.yml                 |  2 ++
 .github/workflows/test-main-17.yml              |  2 ++
 .github/workflows/test-main.yml                 |  2 ++
 .github/workflows/test-package-cli.yml          |  2 ++
 .github/workflows/test-package-lib.yml          |  2 ++
 9 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/auto-close.yml b/.github/workflows/auto-close.yml
index 5206ce4df5..dfdc561b2d 100644
--- a/.github/workflows/auto-close.yml
+++ b/.github/workflows/auto-close.yml
@@ -1,5 +1,7 @@
 name: Auto close
-on: pull_request_target
+on:
+  pull_request_target:
+    types: [opened]
 
 permissions:
   pull-requests: write
diff --git a/.github/workflows/enforce-dependency-review.yml b/.github/workflows/enforce-dependency-review.yml
index bd1797d642..b57b1f4a14 100644
--- a/.github/workflows/enforce-dependency-review.yml
+++ b/.github/workflows/enforce-dependency-review.yml
@@ -1,5 +1,7 @@
 name: 'Dependency Review'
-on: [pull_request]
+on:
+  pull_request:
+    types: [opened, edited, reopened, synchronize]
 
 jobs:
   enforce-dependency-review:
diff --git a/.github/workflows/test-integration-17.yml b/.github/workflows/test-integration-17.yml
index 96683ee0d0..2ae38c7de8 100644
--- a/.github/workflows/test-integration-17.yml
+++ b/.github/workflows/test-integration-17.yml
@@ -1,13 +1,17 @@
 name: Integration@node 17
 on:
   pull_request:
+    types: [opened, edited, reopened, synchronize]
   push:
     branches-ignore:
       - 'gh-pages'
+      - 'dependabot/**'
 
 jobs:
   test-integration-17:
     runs-on: ubuntu-latest
+    env:
+      PAT_EXISTS: ${{ secrets.GH_PAT != '' }}
 
     services:
       redis:
@@ -31,7 +35,14 @@ jobs:
         env:
           NPM_CONFIG_ENGINE_STRICT: 'false'
 
-      - name: Integration Tests
+      - name: Integration Tests (with PAT)
+        if: ${{ env.PAT_EXISTS == 'true' }}
+        uses: ./.github/actions/integration-tests
+        with:
+          github-token: '${{ secrets.GH_PAT }}'
+
+      - name: Integration Tests (with workflow token)
+        if: ${{ env.PAT_EXISTS == 'false' }}
         uses: ./.github/actions/integration-tests
         with:
           github-token: '${{ secrets.GITHUB_TOKEN }}'
diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml
index 7052239ce1..1a5d98cfbd 100644
--- a/.github/workflows/test-integration.yml
+++ b/.github/workflows/test-integration.yml
@@ -1,13 +1,17 @@
 name: Integration
 on:
   pull_request:
+    types: [opened, edited, reopened, synchronize]
   push:
     branches-ignore:
       - 'gh-pages'
+      - 'dependabot/**'
 
 jobs:
   test-integration:
     runs-on: ubuntu-latest
+    env:
+      PAT_EXISTS: ${{ secrets.GH_PAT != '' }}
 
     services:
       redis:
@@ -29,7 +33,14 @@ jobs:
         with:
           node-version: 16
 
-      - name: Integration Tests
+      - name: Integration Tests (with PAT)
+        if: ${{ env.PAT_EXISTS == 'true' }}
+        uses: ./.github/actions/integration-tests
+        with:
+          github-token: '${{ secrets.GH_PAT }}'
+
+      - name: Integration Tests (with workflow token)
+        if: ${{ env.PAT_EXISTS == 'false' }}
         uses: ./.github/actions/integration-tests
         with:
           github-token: '${{ secrets.GITHUB_TOKEN }}'
diff --git a/.github/workflows/test-lint.yml b/.github/workflows/test-lint.yml
index b05c8f8b34..6bbfccc2b9 100644
--- a/.github/workflows/test-lint.yml
+++ b/.github/workflows/test-lint.yml
@@ -1,9 +1,11 @@
 name: Lint
 on:
   pull_request:
+    types: [opened, edited, reopened, synchronize]
   push:
     branches-ignore:
       - 'gh-pages'
+      - 'dependabot/**'
 
 jobs:
   test-lint:
diff --git a/.github/workflows/test-main-17.yml b/.github/workflows/test-main-17.yml
index daabb51cc1..af7890827b 100644
--- a/.github/workflows/test-main-17.yml
+++ b/.github/workflows/test-main-17.yml
@@ -1,9 +1,11 @@
 name: Main@node 17
 on:
   pull_request:
+    types: [opened, edited, reopened, synchronize]
   push:
     branches-ignore:
       - 'gh-pages'
+      - 'dependabot/**'
 
 jobs:
   test-main-17:
diff --git a/.github/workflows/test-main.yml b/.github/workflows/test-main.yml
index e57fdc59a0..2e079cd816 100644
--- a/.github/workflows/test-main.yml
+++ b/.github/workflows/test-main.yml
@@ -1,9 +1,11 @@
 name: Main
 on:
   pull_request:
+    types: [opened, edited, reopened, synchronize]
   push:
     branches-ignore:
       - 'gh-pages'
+      - 'dependabot/**'
 
 jobs:
   test-main:
diff --git a/.github/workflows/test-package-cli.yml b/.github/workflows/test-package-cli.yml
index 02a128c1ef..2d54b1c0a4 100644
--- a/.github/workflows/test-package-cli.yml
+++ b/.github/workflows/test-package-cli.yml
@@ -1,9 +1,11 @@
 name: Package CLI
 on:
   pull_request:
+    types: [opened, edited, reopened, synchronize]
   push:
     branches-ignore:
       - 'gh-pages'
+      - 'dependabot/**'
 
 # Smoke test (render a badge with the CLI) with only the package
 # dependencies installed.
diff --git a/.github/workflows/test-package-lib.yml b/.github/workflows/test-package-lib.yml
index aa733eb233..a0d3ec7210 100644
--- a/.github/workflows/test-package-lib.yml
+++ b/.github/workflows/test-package-lib.yml
@@ -1,9 +1,11 @@
 name: Package Library
 on:
   pull_request:
+    types: [opened, edited, reopened, synchronize]
   push:
     branches-ignore:
       - 'gh-pages'
+      - 'dependabot/**'
 
 jobs:
   test-package-lib:
-- 
GitLab