Skip to content

Commit

Permalink
Merge branch 'main' into swiftlint-enable
Browse files Browse the repository at this point in the history
  • Loading branch information
bryce-b authored Jan 16, 2025
2 parents 182014e + bb3d181 commit fd5b71d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
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
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ included:
- "Sources"
excluded:
- "Sources/Exporters/OpenTelemetryProtocolCommon/proto"
- ".build"
disabled_rules:
- nesting
- line_length
Expand Down
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

0 comments on commit fd5b71d

Please sign in to comment.