diff --git a/.github/workflows/.swiftlint.yaml b/.github/workflows/.swiftlint.yaml new file mode 100644 index 00000000..30ddcbfa --- /dev/null +++ b/.github/workflows/.swiftlint.yaml @@ -0,0 +1,37 @@ +# SwiftLint Configuration File + + +# To be tailored to reflect projects ideal linting configuration + +#disabled_rules: +# ERRORS IN PROJECT CURRENTLY +# - cyclomatic_complexity +# - identifier_name +# - function_body_length +# - force_cast +# - force_try +# - line_length +# - file_length +# - type_body_length +# WARNINGS IN PROJECT CURRENTLY (excluding those already listed as errors) +# - trailing_comma +# - todo +# - orphaned_doc_comment +# - opening_brace +# - blanket_disable_command +# - for_where +# - trailing_whitespace +# - vertical_whitespace +# - void_function_in_ternary +# - empty_enum_arguments +# - closure_parameter_position + + +# change individual rule configurations +identifier_name: + min_length: 1 + max_length: + warning: 40 + error: 41 + + diff --git a/.github/workflows/pr_swift_lint.yaml b/.github/workflows/pr_swift_lint.yaml new file mode 100644 index 00000000..3effac3b --- /dev/null +++ b/.github/workflows/pr_swift_lint.yaml @@ -0,0 +1,84 @@ +name: pr_swift_lint +on: + pull_request_target: + branches: + - main + types: + - opened + +jobs: + swift_format_check: + runs-on: macos-latest + + name: Run Swift Lint + + steps: + - name: Checkout + 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