Procházet zdrojové kódy

Add caching and GitHub Actions optimizations to unit test workflow

Added cache restore and save steps for Xcode DerivedData and .build to improve CI performance.

Limited workflow triggers to relevant file changes using paths-ignore for PRs and pushes.

Narrowed PR events to opened and synchronize only.

Added steps to display and check cache contents before and after the build.

Included a check for uncommitted changes with GitHub warnings for visibility.

Enabled optional parallel test execution using ENABLE_PARALLEL_TESTING flag.
bjornoleh před 11 měsíci
rodič
revize
7afc7300dc
1 změnil soubory, kde provedl 72 přidání a 5 odebrání
  1. 72 5
      .github/workflows/unit_tests.yml

+ 72 - 5
.github/workflows/unit_tests.yml

@@ -1,15 +1,26 @@
 name: zzz [DO NOT RUN] Automated unit tests
 name: zzz [DO NOT RUN] Automated unit tests
 
 
 on:
 on:
-  workflow_dispatch: # TODO: remove this after testing
+  workflow_dispatch: # TODO: remove this after testing?
+  
   pull_request:
   pull_request:
     branches:
     branches:
       - dev
       - dev
-      - main
+    types: [opened, synchronize]
+    paths-ignore:
+      - '**.md'
+      - '**/README'
+      - '**.yml'
+      - '**.txt'
+
   push:
   push:
     branches:
     branches:
       - dev
       - dev
-      - main
+    paths-ignore:
+      - '**.md'
+      - '**/README'
+      - '**.yml'
+      - '**.txt'
 
 
 jobs:
 jobs:
   test:
   test:
@@ -27,6 +38,25 @@ jobs:
           fetch-depth: 1
           fetch-depth: 1
           submodules: recursive
           submodules: recursive
 
 
+      - name: Restore cache
+        id: cache-restore
+        uses: actions/cache/restore@v4
+        with:
+          path: |
+            /Users/runner/Library/Developer/Xcode/DerivedData
+            .build
+          key: ${{ runner.os }}-trio-${{ hashFiles('**/*.swift', '**/*.xcodeproj', '**/*.xcworkspace') }}
+          restore-keys: |
+            ${{ runner.os }}-trio-
+
+      - name: Show cache contents before build
+        run: |
+          echo "📂 Contents of DerivedData:"
+          ls -lah /Users/runner/Library/Developer/Xcode/DerivedData || echo "Directory not found"
+          echo ""
+          echo "📂 Contents of .build:"
+          ls -lah .build || echo ".build directory not found"
+
       - name: Build for testing
       - name: Build for testing
         run: |
         run: |
           set -o pipefail && \
           set -o pipefail && \
@@ -34,6 +64,42 @@ jobs:
             -workspace Trio.xcworkspace \
             -workspace Trio.xcworkspace \
             -scheme "Trio Tests" \
             -scheme "Trio Tests" \
             -destination 'platform=iOS Simulator,name=iPhone 16,OS=18.4' \
             -destination 'platform=iOS Simulator,name=iPhone 16,OS=18.4' \
+
+      - name: Check for uncommitted changes
+        run: |
+          CHANGES=$(git status --porcelain)
+          if [ -n "$CHANGES" ]; then
+            echo "Uncommitted changes detected:"
+            echo "$CHANGES"
+            echo "$CHANGES" | while read -r line; do
+              FILE=$(echo $line | cut -c4-)
+              echo "::warning file=$FILE::Uncommitted change detected"
+            done
+            exit 0
+          else
+            echo "No uncommitted changes detected."
+          fi
+        shell: bash
+
+      - name: Show cache contents after build
+        run: |
+          echo "📂 Updated DerivedData contents:"
+          du -sh /Users/runner/Library/Developer/Xcode/DerivedData || echo "Directory not found"
+          ls -lah /Users/runner/Library/Developer/Xcode/DerivedData || echo "Directory not found"
+          echo ""
+          echo "📂 Updated .build contents:"
+          du -sh .build || echo ".build directory not found"
+          ls -lah .build || echo ".build directory not found"
+          
+      - name: Save cache
+        if: steps.cache-restore.outputs.cache-hit != 'true'
+        uses: actions/cache/save@v4
+        with:
+          path: |
+            /Users/runner/Library/Developer/Xcode/DerivedData
+            .build
+          key: ${{ runner.os }}-trio-${{ hashFiles('**/*.swift', '**/*.xcodeproj', '**/*.xcworkspace') }}  
+
       - name: Run tests
       - name: Run tests
         run: |
         run: |
           set -o pipefail
           set -o pipefail
@@ -41,7 +107,8 @@ jobs:
             -workspace Trio.xcworkspace \
             -workspace Trio.xcworkspace \
             -scheme "Trio Tests" \
             -scheme "Trio Tests" \
             -destination 'platform=iOS Simulator,name=iPhone 16,OS=18.4' \
             -destination 'platform=iOS Simulator,name=iPhone 16,OS=18.4' \
-          2>&1 | tee xcodebuild.log
+            $([ "$ENABLE_PARALLEL_TESTING" = "true" ] && echo "-parallel-testing-enabled YES") \
+            2>&1 | tee xcodebuild.log
 
 
       - name: Annotate test results
       - name: Annotate test results
         if: always()
         if: always()
@@ -64,4 +131,4 @@ jobs:
             fi
             fi
           else
           else
             echo "::warning::Test log (xcodebuild.log) not found"
             echo "::warning::Test log (xcodebuild.log) not found"
-          fi
+          fi