From 5ec5150d049b3e0930475027eba105c54ec24f5d Mon Sep 17 00:00:00 2001
From: Alex Freska <alex.freska@gmail.com>
Date: Fri, 3 May 2024 14:12:41 -0400
Subject: [PATCH] ci: pr action cancel previous runs

---
 .github/workflows/pr.yml | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml
index df4c161..a3f2a06 100644
--- a/.github/workflows/pr.yml
+++ b/.github/workflows/pr.yml
@@ -2,9 +2,16 @@ name: PR
 
 on:
   pull_request:
+    types: [opened, synchronize, reopened, closed]
+
+# Cancel previous runs when the PR is updated.
+concurrency:
+  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
+  cancel-in-progress: true
 
 jobs:
   mac:
+    if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
     strategy:
       matrix:
         app: [hostd, renterd]
@@ -57,6 +64,7 @@ jobs:
         run: yarn workspace ${{ matrix.app }} make --arch=arm64,x64
         shell: bash
   linux:
+    if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
     strategy:
       matrix:
         app: [hostd, renterd]
@@ -74,6 +82,7 @@ jobs:
         run: yarn workspace ${{ matrix.app }} make --arch=arm64,x64
         shell: bash
   windows:
+    if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
     strategy:
       matrix:
         app: [hostd, renterd]