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

💚 Add clang-format ci #8

Merged
merged 15 commits into from
Dec 28, 2024
Merged
7 changes: 7 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BasedOnStyle: LLVM
IndentWidth: 4
PointerAlignment: Right
AlignAfterOpenBracket: BlockIndent
BinPackArguments: false
BinPackParameters: false
InsertTrailingCommas: Wrapped
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[*.{kt,kts}]
end_of_line = lf
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_imports_layout = *,java.**,javax.**,kotlin.**,^
ij_kotlin_indent_before_arrow_on_new_line = false
ij_kotlin_line_break_after_multiline_when_entry = true
ij_kotlin_packages_to_use_import_on_demand = unset
indent_size = 4
indent_style = space
insert_final_newline = true
ktlint_argument_list_wrapping_ignore_when_parameter_count_greater_or_equal_than = unset
ktlint_chain_method_rule_force_multiline_when_chain_operator_count_greater_or_equal_than = 4
ktlint_class_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = 1
ktlint_code_style = ktlint_official
ktlint_enum_entry_name_casing = upper_or_camel_cases
ktlint_function_naming_ignore_when_annotated_with = [unset]
ktlint_function_signature_body_expression_wrapping = multiline
ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = 2
ktlint_ignore_back_ticked_identifier = false
ktlint_property_naming_constant_naming = screaming_snake_case
max_line_length = 140
24 changes: 24 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Format Check for C++ and Objective-C

on:
pull_request:
paths:
- '**/*.cpp'
- '**/*.c'
- '**/*.h'
- '**/*.mm'
- '**/*.m'

jobs:
format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install clang-format 19
run: sudo wget -qO- https://apt.llvm.org/llvm.sh | sudo bash -s -- 19
- name: Find and Check All Files
run: |
FILES=$(find . -type f \( -name '*.cpp' -o -name '*.c' -o -name '*.h' -o -name '*.mm' -o -name '*.m' \))
for file in $FILES; do
clang-format --dry-run -Werror -style=file $file || exit 1
done
26 changes: 26 additions & 0 deletions .github/workflows/java-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Java Format Check

on:
pull_request:
paths:
- '**/*.java'

jobs:
format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Install google-java-format
run: |
curl -Lo google-java-format.jar https://github.com/google/google-java-format/releases/download/v1.25.2/google-java-format-1.25.2-all-deps.jar

- name: Check formatting
run: |
java -jar google-java-format.jar --dry-run --set-exit-if-changed $(find . -name '*.java')
17 changes: 17 additions & 0 deletions .github/workflows/ktlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Format Check for Kotlin

on:
pull_request:
paths:
- '**/*.kt'
- '**/*.kts'

jobs:
format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install ktlint
run: curl -sSLO https://github.com/pinterest/ktlint/releases/download/1.5.0/ktlint && chmod a+x ktlint && sudo mv ktlint /usr/local/bin/
- name: Find and Check All Files
run: ktlint '!src/craftground/MinecraftEnv/src/main/java/com/kyhsgeekcode/minecraftenv/proto/**'
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ elseif(CUDAToolkit_FOUND)

# CUDA-specific compile options
set(CRAFTGROUND_PY_COMPILE_OPTIONS -DHAS_CUDA)
target_include_directories(craftground PRIVATE ${CUDAToolkit_INCLUDE_DIRS})
target_link_libraries(craftground PRIVATE ${CUDAToolkit_LIBRARIES})
endif()

# Add the module
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This is the latest development repository of CraftGround environment.
1. You need to install JDK >= 21
1. Run the following command to install the package.
```shell
pip install git+https://github.com/yhs0602/CraftGround
pip install craftground
```
1. Take a look at the [the demo repository](https://github.com/yhs0602/CraftGround-Baselines3)!
1. Here is a simple example that uses this environment.
Expand Down Expand Up @@ -249,3 +249,15 @@ https://dejavu-fonts.github.io/License.html
1. Edit .proto
2. protoc
3. Edit python files


# Formatting
## Install formatters
```zsh
brew install ktlint clang-format google-java-format
```
```bash
find . \( -iname '*.h' -o -iname '*.cpp' -o -iname '*.mm' \) | xargs clang-format -i
ktlint '!src/craftground/MinecraftEnv/src/main/java/com/kyhsgeekcode/minecraftenv/proto/**'
find . -name '*.java' -print0 | xargs -0 -P 4 google-java-format -i
```
Loading
Loading