Переглянути джерело

test: only lint when php files changed otherwise pass

Cat 3 роки тому
батько
коміт
ccf0715e44
1 змінених файлів з 22 додано та 4 видалено
  1. 22 4
      .github/workflows/lint.yml

+ 22 - 4
.github/workflows/lint.yml

@@ -1,16 +1,34 @@
 name: Lint code
 on:
   push:
-    paths:
-      - "**.php"
   pull_request:
-    paths:
-      - "**.php"
     types: [opened, reopened, synchronize]
 
 jobs:
+  check_php_files:
+    runs-on: ubuntu-latest
+    outputs:
+      php_changed: ${{ steps.check_file_changed.outputs.php_file_changed }}
+    steps:
+    - uses: actions/checkout@v2
+      with:
+        fetch-depth: 2
+    - shell: pwsh
+      id: check_php_file_changed
+      run: |
+        # Diff HEAD with the previous commit
+        $diff = git diff --name-only HEAD^ HEAD
+
+        # Check if a file under docs/ or with the .md extension has changed (added, modified, deleted)
+        $SourceDiff = $diff | Where-Object { $_ -match '.php$' }
+        $HasDiff = $SourceDiff.Length -gt 0
+
+        # Set the output named "docs_changed"
+        Write-Host "::set-output name=php_file_changed::$HasDiff"
   lint:
     runs-on: ubuntu-latest
+    needs: [ check_php_files ]
+    if: needs.check_php_files.outputs.php_file_changed == 'True'
     steps:
       - uses: actions/checkout@v2
         with: