diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml index 1dac2048..83cbeb2f 100644 --- a/.github/workflows/pr-validation.yml +++ b/.github/workflows/pr-validation.yml @@ -50,6 +50,14 @@ jobs: - name: Run SwiftLint run: | + # Check if there are any Swift files in the PR + SWIFT_FILES=$(find . -name "*.swift" -not -path "*/.*" | head -n 1) + + if [ -z "$SWIFT_FILES" ]; then + echo "No Swift files found in repository, skipping SwiftLint" + exit 0 + fi + if [ -f .swiftlint.yml ]; then swiftlint lint --reporter github-actions-logging --config .swiftlint.yml else @@ -77,7 +85,17 @@ jobs: fi done + - name: Check if Swift project + id: check_swift + run: | + if [ -f "project.yml" ] && [ -n "$(find . -name "*.swift" -not -path "*/.*" | head -n 1)" ]; then + echo "is_swift=true" >> $GITHUB_OUTPUT + else + echo "is_swift=false" >> $GITHUB_OUTPUT + fi + - name: Generate Xcode project + if: steps.check_swift.outputs.is_swift == 'true' run: | if ! command -v xcodegen &> /dev/null; then echo "Installing XcodeGen..." @@ -86,12 +104,14 @@ jobs: xcodegen generate - name: Resolve Swift Package Dependencies + if: steps.check_swift.outputs.is_swift == 'true' run: | xcodebuild -resolvePackageDependencies \ -project HomeInventoryModular.xcodeproj \ -scheme HomeInventoryApp - name: Build for iOS Simulator + if: steps.check_swift.outputs.is_swift == 'true' run: | set -o pipefail xcodebuild build \ @@ -102,6 +122,7 @@ jobs: CODE_SIGNING_ALLOWED=NO - name: Check for compilation warnings + if: steps.check_swift.outputs.is_swift == 'true' run: | set -o pipefail warnings=$(xcodebuild clean build \ @@ -126,6 +147,7 @@ jobs: fi - name: Check for TODO and FIXME comments + if: steps.check_swift.outputs.is_swift == 'true' run: | todos=$(find . -name "*.swift" -not -path "./.*" -exec grep -n "TODO\|FIXME" {} + | wc -l) echo "Found $todos TODO/FIXME comments" @@ -134,6 +156,7 @@ jobs: fi - name: Security checks + if: steps.check_swift.outputs.is_swift == 'true' run: | # Check for potential security issues echo "Running basic security checks..."