Browse Source

feat(ci): skip redundant tests on PR merge

Tests only run on:
- Pull requests (CI checks)
- Direct pushes to main
- Manual workflow dispatch

PR merges skip tests (already passed) but still trigger version bump.
darrenhinde 8 tháng trước cách đây
mục cha
commit
54f2d98723
1 tập tin đã thay đổi với 62 bổ sung4 xóa
  1. 62 4
      .github/workflows/test-agents.yml

+ 62 - 4
.github/workflows/test-agents.yml

@@ -12,9 +12,57 @@ on:
   workflow_dispatch:
 
 jobs:
+  # Check if this is a PR merge commit (skip tests if so - they already ran on PR)
+  check-trigger:
+    name: Check Trigger Type
+    runs-on: ubuntu-latest
+    outputs:
+      should_test: ${{ steps.check.outputs.should_test }}
+      should_bump: ${{ steps.check.outputs.should_bump }}
+    steps:
+      - name: Determine if tests should run
+        id: check
+        run: |
+          # For PRs, always run tests
+          if [ "${{ github.event_name }}" == "pull_request" ]; then
+            echo "should_test=true" >> $GITHUB_OUTPUT
+            echo "should_bump=false" >> $GITHUB_OUTPUT
+            echo "PR detected - will run tests"
+            exit 0
+          fi
+          
+          # For workflow_dispatch, always run tests
+          if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
+            echo "should_test=true" >> $GITHUB_OUTPUT
+            echo "should_bump=false" >> $GITHUB_OUTPUT
+            echo "Manual trigger - will run tests"
+            exit 0
+          fi
+          
+          # For push events, check if it's a PR merge
+          COMMIT_MSG="${{ github.event.head_commit.message }}"
+          
+          # PR merges have messages like "Merge pull request #123" or contain (#123)
+          if echo "$COMMIT_MSG" | grep -qE "^Merge pull request #|^.*\(#[0-9]+\)$"; then
+            echo "should_test=false" >> $GITHUB_OUTPUT
+            echo "should_bump=true" >> $GITHUB_OUTPUT
+            echo "PR merge detected - skipping tests, will bump version"
+          # Skip version bump commits
+          elif echo "$COMMIT_MSG" | grep -qE "^\[skip ci\]|chore: bump version"; then
+            echo "should_test=false" >> $GITHUB_OUTPUT
+            echo "should_bump=false" >> $GITHUB_OUTPUT
+            echo "Version bump commit - skipping everything"
+          else
+            echo "should_test=true" >> $GITHUB_OUTPUT
+            echo "should_bump=true" >> $GITHUB_OUTPUT
+            echo "Direct push detected - will run tests and bump version"
+          fi
+
   test-openagent:
     name: Test OpenAgent
     runs-on: ubuntu-latest
+    needs: check-trigger
+    if: needs.check-trigger.outputs.should_test == 'true'
     timeout-minutes: 15
     
     steps:
@@ -65,6 +113,8 @@ jobs:
   test-opencoder:
     name: Test OpenCoder
     runs-on: ubuntu-latest
+    needs: check-trigger
+    if: needs.check-trigger.outputs.should_test == 'true'
     timeout-minutes: 15
     
     steps:
@@ -115,8 +165,8 @@ jobs:
   report-results:
     name: Report Test Results
     runs-on: ubuntu-latest
-    needs: [test-openagent, test-opencoder]
-    if: always()
+    needs: [check-trigger, test-openagent, test-opencoder]
+    if: always() && needs.check-trigger.outputs.should_test == 'true'
     
     steps:
       - name: Download OpenAgent results
@@ -152,8 +202,16 @@ jobs:
   auto-version-bump:
     name: Auto Version Bump
     runs-on: ubuntu-latest
-    needs: [test-openagent, test-opencoder]
-    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
+    needs: [check-trigger, test-openagent, test-opencoder]
+    # Run version bump if:
+    # 1. Tests ran and passed, OR
+    # 2. This is a PR merge (tests already passed on PR)
+    if: |
+      github.event_name == 'push' && 
+      github.ref == 'refs/heads/main' &&
+      needs.check-trigger.outputs.should_bump == 'true' &&
+      (needs.check-trigger.outputs.should_test == 'false' || 
+       (needs.test-openagent.result == 'success' && needs.test-opencoder.result == 'success'))
     permissions:
       contents: write