Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added swiftlint to BuildAndTest workflow #665

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/BuildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ name: Build and Test
on: [push, pull_request, workflow_dispatch]

jobs:
SwiftLint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: GitHub Action for SwiftLint (Only files changed in the PR)
uses: norio-nomura/[email protected]
env:
args: --strict
DIFF_BASE: ${{ github.base_ref }}
macOS:
runs-on: macos-15
steps:
Expand Down
18 changes: 18 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
included:
- "Sources"
excluded:
- "Sources/Exporters/OpenTelemetryProtocolCommon/proto"
- ".build"
disabled_rules:
- nesting
- line_length
- type_body_length
- identifier_name
- file_length
- force_cast
- type_name
- large_tuple
- function_body_length
- function_parameter_count
- cyclomatic_complexity
- force_try
9 changes: 9 additions & 0 deletions Scripts/hooks/install-precommit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

HOOK_DIR=${SCRIPT_DIR}/../../.git/hooks

cp "${SCRIPT_DIR}/precommit-script.sh" "${HOOK_DIR}/precommit"

chmod 0755 "${HOOK_DIR}/precommit"
32 changes: 32 additions & 0 deletions Scripts/hooks/precommit-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

if ! command -v swiftlint 2>&1 >/dev/null
then

echo "install swiftlint \(v0.0.57\) for pre-commit linting."
exit 0
fi

if [ "$(swiftlint --version)" != "0.57.1" ]
then
echo "swiftlint installed with incorrect version (`swiftlint --version`). Please use version 0.57.1 for pre-commit linting."
exit 0
fi
OIFS="$IFS"
IFS=$'\n'
FILE_LIST=($(git diff --cached --name-only | grep "\.swift$"))
IFS="$OIFS"

if [ -z "${FILE_LIST}" ]; then
exit 0
fi

swiftlint lint --config .swiftlint.yml --strict "${FILE_LIST[@]}"
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo -e "Swiftlint failed!\n Fix issues above or run:\n\tswiftlint lint --fix $(printf "\"%s\" " "${FILE_LIST[@]}")"
echo "Skip linting with '--no-verify'."
exit 1
fi
echo "Swiftlint passed!"
exit 1
Loading