chore: enhance CI tests (#3344)

* chore: add swift linter

* chore: add clang linters

* chore: add kotlin linter

* chore(ci): update workflows

* chore(ci): clean workflows
This commit is contained in:
Krzysztof Moch 2023-12-02 15:58:43 +01:00 committed by GitHub
parent 26043335e1
commit 91d7135562
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 271 additions and 3 deletions

34
.github/workflows/check-android.yml vendored Normal file
View File

@ -0,0 +1,34 @@
name: Check Android
on:
push:
branches:
- master
paths:
- '.github/workflows/check-android.yml'
- 'android/**'
pull_request:
paths:
- '.github/workflows/check-android.yml'
- 'android/**'
jobs:
Kotlin-Lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
curl -sSLO https://github.com/pinterest/ktlint/releases/download/1.0.0/ktlint && chmod a+x ktlint && sudo mv ktlint /usr/local/bin/
- name: run ktlint
working-directory: ./android/
run: |
ktlint --reporter=checkstyle,output=build/ktlint-report.xml --relative --editorconfig=./.editorconfig
continue-on-error: true
- uses: yutailang0119/action-ktlint@v3
with:
report-path: ./android/build/*.xml
continue-on-error: false
- uses: actions/upload-artifact@v3
with:
name: ktlint-report
path: ./android/build/*.xml

31
.github/workflows/check-clang.yml vendored Normal file
View File

@ -0,0 +1,31 @@
name: Check CLang
on:
push:
branches:
- master
paths:
- '.github/workflows/check-clang.yml'
- 'ios/**'
pull_request:
branches:
- master
paths:
- '.github/workflows/check-clang.yml'
- 'ios/**'
jobs:
CLang-Format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install clang-format
run: sudo apt-get install clang-format
- name: Check ios clang formatting
run: |
find ios -type f \( -name "*.h" -o -name "*.cpp" -o -name "*.m" -o -name "*.mm" \) -print0 | while read -d $'\0' file; do
clang-format -style=file:./ios/.clang-format -i "$file"
done
shell: bash
- name: Check for changes
run: git diff --exit-code HEAD

41
.github/workflows/check-ios.yml vendored Normal file
View File

@ -0,0 +1,41 @@
name: Check iOS
on:
push:
branches:
- master
paths:
- '.github/workflows/check-ios.yml'
- 'ios/**'
pull_request:
paths:
- '.github/workflows/check-ios.yml'
- 'ios/**'
jobs:
Swift-Lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Lint with SwiftLint
uses: norio-nomura/action-swiftlint@master
with:
args: --strict
env:
WORKING_DIRECTORY: ios
Swift-Format:
runs-on: macOS-latest
defaults:
run:
working-directory: ./ios
steps:
- uses: actions/checkout@v4
- name: Install SwiftFormat
run: brew install swiftformat
- name: Format Swift code
run: swiftformat --verbose .
- name: Verify formatted code is unchanged
run: git diff --exit-code HEAD

14
android/.editorconfig Normal file
View File

@ -0,0 +1,14 @@
[*.{kt,kts}]
indent_style=space
indent_size=2
continuation_indent_size=4
insert_final_newline=true
max_line_length=160
ktlint_code_style=android_studio
ktlint_standard=enabled
ktlint_experimental=enabled
ktlint_standard_filename=disabled # dont require PascalCase filenames
ktlint_standard_no-wildcard-imports=disabled # allow .* imports
ktlint_function_signature_body_expression_wrapping=multiline
ij_kotlin_allow_trailing_comma_on_call_site=false
ij_kotlin_allow_trailing_comma=false

25
ios/.clang-format Normal file
View File

@ -0,0 +1,25 @@
# Config for clang-format version 16
# standard
BasedOnStyle: llvm
Standard: c++14
# Indentation
IndentWidth: 2
ColumnLimit: 140
# Includes
SortIncludes: true
SortUsingDeclarations: true
# Pointer and reference alignment
PointerAlignment: Left
ReferenceAlignment: Left
ReflowComments: true
# Line breaking options
BreakBeforeBraces: Attach
BreakConstructorInitializers: BeforeColon
AllowShortFunctionsOnASingleLine: Empty
IndentCaseLabels: true
NamespaceIndentation: Inner

13
ios/.swiftformat Normal file
View File

@ -0,0 +1,13 @@
--allman false
--indent 2
--exclude Pods,Generated
--disable andOperator
--disable redundantReturn
--disable wrapMultilineStatementBraces
--disable organizeDeclarations
--disable redundantSelf
--enable markTypes
--enable isEmpty

51
ios/.swiftlint.yml Normal file
View File

@ -0,0 +1,51 @@
disabled_rules:
- identifier_name
- trailing_comma
- todo
- type_body_length
- file_length
- cyclomatic_complexity
- function_body_length
opt_in_rules:
- contains_over_filter_count
- contains_over_filter_is_empty
- contains_over_first_not_nil
- contains_over_range_nil_comparison
- empty_collection_literal
- empty_count
- empty_string
- first_where
- flatmap_over_map_reduce
- last_where
- reduce_boolean
- reduce_into
- yoda_condition
- vertical_whitespace_opening_braces
- vertical_whitespace_closing_braces
- vertical_parameter_alignment_on_call
- untyped_error_in_catch
- unowned_variable_capture
- unavailable_function
- switch_case_on_newline
- static_operator
- strict_fileprivate
- sorted_imports
- sorted_first_last
- required_enum_case
- redundant_type_annotation
- redundant_nil_coalescing
- attributes
- convenience_type
analyzer_rules:
- explicit_self
- unused_declaration
- unused_import
excluded: # paths to ignore during linting. Takes precedence over `included`.
- Pods
# Adjust rule numbers
line_length: 160
# reporter type (xcode, json, csv, checkstyle, codeclimate, junit, html, emoji, sonarqube, markdown, github-actions-logging)
reporter: "xcode"

View File

@ -23,6 +23,7 @@
"@types/react": "~18.0.0",
"@types/react-native": "0.72.3",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@jamesacarr/eslint-formatter-github-actions": "^0.2.0",
"eslint": "^8.19.0",
"eslint-plugin-jest": "^27.4.2",
"jest": "^29.7.0",
@ -45,7 +46,9 @@
"xbasic": "yarn --cwd examples/basic",
"docs": "yarn --cwd docs build",
"release": "release-it",
"test": "echo no test available"
"test": "echo no test available",
"check-ios": "scripts/swift-format.sh && scripts/swift-lint.sh && scripts/clang-format.sh",
"check-android": "scripts/kotlin-lint.sh"
},
"files": [
"android",

26
scripts/bootstrap.js vendored Normal file
View File

@ -0,0 +1,26 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const child_process = require('child_process');
const root = path.resolve(__dirname, '..');
const args = process.argv.slice(2);
const options = {
cwd: process.cwd(),
env: process.env,
stdio: 'inherit',
encoding: 'utf-8',
};
let result;
if (process.cwd() !== root || args.length) {
// We're not in the root of the project, or additional arguments were passed
// In this case, forward the command to `yarn`
result = child_process.spawnSync('yarn', args, options);
} else {
// If `yarn` is run without arguments, perform bootstrap
result = child_process.spawnSync('yarn', ['bootstrap'], options);
}
process.exitCode = result.status;

9
scripts/clang-format.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
if which clang-format >/dev/null; then
find ios -type f \( -name "*.h" -o -name "*.cpp" -o -name "*.m" -o -name "*.mm" \) -print0 | while read -d $'\0' file; do
clang-format -style=file:./ios/.clang-format -i "$file"
done
else
echo "[ERROR]: clang-format is not installed - Install with 'brew install clang-format' (or manually from https://clang.llvm.org/docs/ClangFormat.html)"
fi

7
scripts/kotlin-lint.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
if which ktlint >/dev/null; then
cd android && ktlint --color --relative --editorconfig=./.editorconfig -F ./**/*.kt*
else
echo "[ERROR]: KTLint is not installed - Install with 'brew install ktlint' (or manually from https://github.com/pinterest/ktlint)"
fi

7
scripts/swift-format.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
if which swiftformat >/dev/null; then
cd ios && swiftformat --quiet .
else
echo "[ERROR]: SwiftFormat is not installed -Install with 'brew install swiftformat' (or manually from https://github.com/nicklockwood/SwiftFormat)"
fi

7
scripts/swift-lint.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
if which swiftlint >/dev/null; then
cd ios && swiftlint --quiet --fix && swiftlint --quiet
else
echo "[ERROR]: SwiftLint is not installed - Install with 'brew install swiftlint' (or manually from https://github.com/realm/SwiftLint)"
fi