Skip to content

Commit effaa9c

Browse files
committed
[CI] Improve linters and git hooks
1 parent 13ff7ff commit effaa9c

File tree

10 files changed

+33
-300
lines changed

10 files changed

+33
-300
lines changed

.github/workflows/cron-checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ jobs:
234234
- uses: actions/checkout@v4.1.1
235235
- uses: ./.github/actions/bootstrap
236236
- run: bundle exec fastlane rubocop
237-
- run: bundle exec fastlane run_swift_format lint:true
237+
- run: bundle exec fastlane run_swift_format strict:true
238238
- run: bundle exec fastlane pod_lint
239239

240240
slack:

.github/workflows/smoke-checks.yml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,20 +137,13 @@ jobs:
137137
if: ${{ github.event.inputs.record_snapshots_swiftui != 'true' && github.event.inputs.record_snapshots_uikit != 'true' }}
138138
steps:
139139
- uses: actions/checkout@v4.1.1
140-
with:
141-
fetch-depth: 0
142140
- uses: ./.github/actions/bootstrap
143-
- name: Public Interface Validation
144-
run: bundle exec fastlane validate_public_interface
145-
- name: Run Danger
146-
run: bundle exec fastlane lint_pr
147-
- name: Run Fastlane Linting
148-
run: bundle exec fastlane rubocop
149-
- name: Run SwiftFormat Linting
150-
run: bundle exec fastlane run_swift_format lint:true
151-
- name: Run Podspec Linting
141+
- run: bundle exec fastlane validate_public_interface
142+
- run: bundle exec fastlane lint_pr
143+
- run: bundle exec fastlane rubocop
144+
- run: bundle exec fastlane run_swift_format strict:true
145+
- run: bundle exec fastlane pod_lint
152146
if: startsWith(github.event.pull_request.head.ref, 'release/')
153-
run: bundle exec fastlane pod_lint
154147

155148
build-xcode15:
156149
name: Build SDKs (Xcode 15)

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
77
gem 'danger', group: :danger_dependencies
88
gem 'fastlane', group: :fastlane_dependencies
99
gem 'json'
10+
gem 'lefthook'
1011
gem 'rubocop', '1.38', group: :rubocop_dependencies
1112
gem 'sinatra', group: :sinatra_dependencies
1213
gem 'slather'

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ GEM
273273
rexml (>= 3.3.9)
274274
kramdown-parser-gfm (1.1.0)
275275
kramdown (~> 2.0)
276+
lefthook (1.11.16)
276277
logger (1.7.0)
277278
method_source (1.1.0)
278279
mini_magick (4.13.2)
@@ -427,6 +428,7 @@ DEPENDENCIES
427428
fastlane-plugin-stream_actions (= 0.3.84)
428429
fastlane-plugin-versioning
429430
json
431+
lefthook
430432
plist
431433
puma
432434
rackup

Scripts/bootstrap.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@ trap "echo ; echo ❌ The Bootstrap script failed to finish without error. See t
2020

2121
source ./Githubfile
2222

23-
puts "Create git/hooks folder if needed"
24-
mkdir -p .git/hooks
25-
26-
# Symlink hooks folder to .git/hooks folder
27-
puts "Create symlink for pre-commit hooks"
28-
# Symlink needs to be ../../hooks and not ./hooks because git evaluates them in .git/hooks
29-
ln -sf ../../hooks/pre-commit.sh .git/hooks/pre-commit
30-
chmod +x .git/hooks/pre-commit
31-
chmod +x ./hooks/git-format-staged
23+
if [ "${GITHUB_ACTIONS:-}" != "true" ]; then
24+
puts "Set up git hooks"
25+
bundle install
26+
bundle exec lefthook install
27+
fi
3228

3329
if [ "${SKIP_MINT_BOOTSTRAP:-}" != true ]; then
3430
puts "Bootstrap Mint dependencies"

fastlane/Fastfile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ reversed_gci = gci.split('.').reverse.join('.')
2020
is_localhost = !is_ci
2121
@force_check = false
2222
swift_environment_path = File.absolute_path('../Sources/StreamVideo/Generated/SystemEnvironment+Version.swift')
23-
swiftformat_excluded_paths = ["**/Generated", "**/generated", "**/protobuf", "**/OpenApi"]
24-
swiftformat_source_paths = ["Sources", "DemoApp", "DemoAppUIKit", "StreamVideoTests", "StreamVideoSwiftUITests", "StreamVideoUIKitTests"]
2523

2624
before_all do |lane|
2725
if is_ci
@@ -673,10 +671,13 @@ end
673671
desc 'Run source code formatting/linting'
674672
lane :run_swift_format do |options|
675673
Dir.chdir('..') do
676-
action = options[:lint] ? "--lint" : ""
677-
swiftformat_source_paths.each do |path|
678-
sh("mint run swiftformat #{action} --config .swiftformat --exclude #{swiftformat_excluded_paths.join(',')} #{path}")
679-
sh("mint run swiftlint lint --config .swiftlint.yml --progress --quiet --reporter json #{path}")
674+
strict = options[:strict] ? '--lint' : nil
675+
sources_matrix[:swiftformat_include].each do |path|
676+
sh("mint run swiftformat #{strict} --config .swiftformat --exclude #{sources_matrix[:swiftformat_exclude].join(',')} #{path}")
677+
next if path.include?('Tests')
678+
679+
sh("mint run swiftlint lint --config .swiftlint.yml --fix --progress --quiet --reporter json #{path}") unless strict
680+
sh("mint run swiftlint lint --config .swiftlint.yml --strict --progress --quiet --reporter json #{path}")
680681
end
681682
end
682683
end
@@ -708,7 +709,9 @@ lane :sources_matrix do
708709
documentation_tests: ['Sources', 'DocumentationTests', xcode_project],
709710
size: ['Sources', xcode_project],
710711
public_interface: ['Sources'],
711-
ruby: ['fastlane']
712+
ruby: ['fastlane'],
713+
swiftformat_include: ["Sources", "DemoApp", "DemoAppUIKit", "StreamVideoTests", "StreamVideoSwiftUITests", "StreamVideoUIKitTests"],
714+
swiftformat_exclude: ["**/Generated", "**/generated", "**/protobuf", "**/OpenApi"]
712715
}
713716
end
714717

hooks/git-format-staged

Lines changed: 0 additions & 249 deletions
This file was deleted.

hooks/pre-commit.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

hooks/regenerage-spm-package-if-needed.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)