From 40adedcb96c3ce15b1c49b802f994c5de31686c3 Mon Sep 17 00:00:00 2001
From: Lukas Wirth <lukastw97@gmail.com>
Date: Thu, 30 Mar 2023 09:59:08 +0200
Subject: [PATCH] internal: Only run typescript CI when VSCode files change

---
 .github/workflows/ci.yaml | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index bb77324378a..d7a4b8f8195 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -18,6 +18,21 @@ env:
   RUSTUP_MAX_RETRIES: 10
 
 jobs:
+  changes:
+    runs-on: ubuntu-latest
+    permissions:
+      pull-requests: read
+    outputs:
+      typescript: ${{ steps.filter.outputs.typescript }}
+    steps:
+      - uses: actions/checkout@v3
+      - uses: dorny/paths-filter@v2
+        id: filter
+        with:
+          filters: |
+            typescript:
+              - 'editors/code/**'
+
   rust:
     if: github.repository == 'rust-lang/rust-analyzer'
     name: Rust
@@ -102,6 +117,7 @@ jobs:
           done
 
   typescript:
+    needs: changes
     if: github.repository == 'rust-lang/rust-analyzer'
     name: TypeScript
     strategy:
@@ -114,18 +130,21 @@ jobs:
     steps:
       - name: Checkout repository
         uses: actions/checkout@v3
+        if: needs.changes.outputs.typescript == 'true'
 
       - name: Install Nodejs
         uses: actions/setup-node@v3
         with:
           node-version: 16
+        if: needs.changes.outputs.typescript == 'true'
 
       - name: Install xvfb
-        if: matrix.os == 'ubuntu-latest'
+        if: matrix.os == 'ubuntu-latest' && needs.changes.outputs.typescript == 'true'
         run: sudo apt-get install -y xvfb
 
       - run: npm ci
         working-directory: ./editors/code
+        if: needs.changes.outputs.typescript == 'true'
 
       #    - run: npm audit || { sleep 10 && npm audit; } || { sleep 30 && npm audit; }
       #      if: runner.os == 'Linux'
@@ -133,16 +152,17 @@ jobs:
 
       - run: npm run lint
         working-directory: ./editors/code
+        if: needs.changes.outputs.typescript == 'true'
 
       - name: Run VS Code tests (Linux)
-        if: matrix.os == 'ubuntu-latest'
+        if: matrix.os == 'ubuntu-latest' && needs.changes.outputs.typescript == 'true'
         env:
           VSCODE_CLI: 1
         run: xvfb-run npm test
         working-directory: ./editors/code
 
       - name: Run VS Code tests (Windows)
-        if: matrix.os == 'windows-latest'
+        if: matrix.os == 'windows-latest' && needs.changes.outputs.typescript == 'true'
         env:
           VSCODE_CLI: 1
         run: npm test
@@ -150,9 +170,11 @@ jobs:
 
       - run: npm run pretest
         working-directory: ./editors/code
+        if: needs.changes.outputs.typescript == 'true'
 
       - run: npm run package --scripts-prepend-node-path
         working-directory: ./editors/code
+        if: needs.changes.outputs.typescript == 'true'
 
   end-success:
     name: bors build finished
@@ -165,7 +187,7 @@ jobs:
 
   end-failure:
     name: bors build finished
-    if: github.event.pusher.name == 'bors' && (failure() || cancelled())
+    if: github.event.pusher.name == 'bors' && !success()
     runs-on: ubuntu-latest
     needs: [rust, rust-cross, typescript]
     steps: