-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added swiftlint to BuildAndTest workflow
also added swiftlint precommit hook script with an installation script.
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |