From acb5b2c8b36a3646595ec48ab7e5ff41196d35f4 Mon Sep 17 00:00:00 2001 From: Andrew Tavis McAllister Date: Sat, 27 Apr 2024 00:44:09 +0200 Subject: [PATCH] #390 test swiftlint GitHub action in PR workflow --- .github/workflows/pr_swift_lint.yaml | 80 ++----------------- .../.swiftlint.yaml => .swiftlint.yaml | 13 +-- 2 files changed, 10 insertions(+), 83 deletions(-) rename .github/workflows/.swiftlint.yaml => .swiftlint.yaml (79%) diff --git a/.github/workflows/pr_swift_lint.yaml b/.github/workflows/pr_swift_lint.yaml index 3effac3b..e2bcdcc7 100644 --- a/.github/workflows/pr_swift_lint.yaml +++ b/.github/workflows/pr_swift_lint.yaml @@ -3,82 +3,16 @@ on: pull_request_target: branches: - main - types: - - opened + types: [opened, reopened, synchronize] jobs: - swift_format_check: - runs-on: macos-latest + swiftlint: + runs-on: ubuntu-latest - name: Run Swift Lint + name: Run SwiftLint steps: - - name: Checkout - uses: actions/checkout@v3 + - uses: actions/checkout@v3 - - name: Install Homebrew (if macOS does not have it) - run: | - if ! command -v brew &>/dev/null - then - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - fi - - - name: Install jq - run: brew install jq - - - name: Install SwiftLint - run: brew install swiftlint - - - name: Run SwiftLint - run: | - echo " " - set +e - swiftlint lint --reporter json --config /Users/runner/work/Scribe-iOS/Scribe-iOS/.github/workflows/.swiftlint.yaml > swiftlint-results.json - - # Verify the JSON output exists and is not empty - if [ ! -f swiftlint-results.json ] || [ ! -s swiftlint-results.json ]; then - echo "SwiftLint did not produce output or the output is empty." - exit 1 - fi - - echo " " - - # Formatting and printing warnings - echo "WARNINGS:" - warnings_count=$(jq -r '.[] | select(.severity == "Warning") | "\(.file):\(.line): warning: (\(.rule_id)) \(.reason)"' swiftlint-results.json | wc -l) - jq -r '.[] | select(.severity == "Warning") | "\(.file):\(.line): warning: (\(.rule_id)) \(.reason)"' swiftlint-results.json - - if [ "$warnings_count" -eq 0 ]; then - echo "No Warnings" - fi - - echo " " - - # Formatting and printing errors - echo "ERRORS:" - errors_count=$(jq -r '.[] | select(.severity == "Error") | "\(.file):\(.line): error: (\(.rule_id)) \(.reason)"' swiftlint-results.json | wc -l) - jq -r '.[] | select(.severity == "Error") | "\(.file):\(.line): error: (\(.rule_id)) \(.reason)"' swiftlint-results.json - - if [ "$errors_count" -eq 0 ]; then - echo "No Errors" - fi - - # Printing summary of counts - echo " " - - echo "-------- Summary --------" - echo "Total Warnings: $warnings_count" - echo "Total Errors: $errors_count" - - echo " " - - if [ "$errors_count" -gt 0 ]; then - echo "SwiftLint found errors." # Can change message to be more reflective of what needs to be conveyed - exit 2 - elif [ "$warnings_count" -gt 0 ]; then - echo "SwiftLint found warnings." # Can change message to be more reflective of what needs to be conveyed - # exit 1 #Uncomment to enforce warnings - else - echo "SwiftLint found no issues." # Can change message to be more reflective of what needs to be conveyed - fi - shell: bash + - name: GitHub Action for SwiftLint + uses: norio-nomura/action-swiftlint@3.2.1 diff --git a/.github/workflows/.swiftlint.yaml b/.swiftlint.yaml similarity index 79% rename from .github/workflows/.swiftlint.yaml rename to .swiftlint.yaml index 30ddcbfa..d55a1a1a 100644 --- a/.github/workflows/.swiftlint.yaml +++ b/.swiftlint.yaml @@ -1,8 +1,5 @@ # SwiftLint Configuration File - -# To be tailored to reflect projects ideal linting configuration - #disabled_rules: # ERRORS IN PROJECT CURRENTLY # - cyclomatic_complexity @@ -12,7 +9,7 @@ # - force_try # - line_length # - file_length -# - type_body_length +# - type_body_length # WARNINGS IN PROJECT CURRENTLY (excluding those already listed as errors) # - trailing_comma # - todo @@ -26,12 +23,8 @@ # - empty_enum_arguments # - closure_parameter_position - -# change individual rule configurations identifier_name: min_length: 1 - max_length: + max_length: warning: 40 - error: 41 - - + error: 41