Skip to content

feat: add Mill build system and Google Java Format #32

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# EditorConfig helps maintain consistent coding styles
# between different editors and IDEs
# See https://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.java]
indent_style = space
indent_size = 2
max_line_length = 100

[*.{json,yaml,yml}]
indent_style = space
indent_size = 2

[*.{md,markdown}]
trim_trailing_whitespace = false

[*.{xml,html}]
indent_style = space
indent_size = 2

[*.gradle]
indent_style = space
indent_size = 4

[*.mill]
indent_style = space
indent_size = 2
26 changes: 26 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Pre-commit hook to format Java code with Google Java Format

echo "Running Google Java Format on staged Java files..."

# Get list of staged Java files
STAGED_JAVA_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.java$')

if [ -z "$STAGED_JAVA_FILES" ]; then
echo "No Java files to format."
exit 0
fi

# Format the files
mill formatJava

# Add the formatted files back to staging
for file in $STAGED_JAVA_FILES; do
if [ -f "$file" ]; then
git add "$file"
echo "Formatted and re-staged: $file"
fi
done

echo "Java formatting complete!"
exit 0
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Code Quality

on:
push:
branches: [main, develop]
pull_request:
branches: [main]

jobs:
format-check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

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

- uses: zhutmost/setup-mill@main
with:
mill-version: 0.12.11

- name: Check Java formatting
run: mill checkJavaFormat
# the server process is kept alive across steps,
# so separate invocations of mill remain extremely fast!

- name: Compile
run: mill compile
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,6 @@ compile_commands.json

# bun
node_modules/

# crush
.crush
1 change: 1 addition & 0 deletions .mill-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.12.11
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"recommendations": [
"redhat.java",
"vscjava.vscode-java-pack",
"esbenp.prettier-vscode",
"editorconfig.editorconfig",
"ms-vscode.vscode-json"
]
}
26 changes: 25 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
"java.configuration.updateBuildConfiguration": "automatic",
"java.server.launchMode": "Standard",
"java.format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml",
"java.format.settings.profile": "GoogleStyle",
"java.format.enabled": true,
"java.saveActions.organizeImports": true,
"java.compile.nullAnalysis.mode": "automatic",
"files.exclude": {
"**/.git": true,
"**/.svn": true,
Expand All @@ -26,8 +31,27 @@
}
],
"java.test.defaultConfig": "WPIlibUnitTests",
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"[java]": {
"editor.defaultFormatter": "redhat.java",
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.detectIndentation": false
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.formatOnSave": true
"[yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[markdown]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public class ExampleSubsystem extends SubsystemBase {
return new RunCommand(() -> motor.set(speed.getAsDouble()), this);
}
}

```

```java
Expand All @@ -113,7 +112,6 @@ public class RobotContainer {
joystick.trigger().onTrue(elevatorSubsystem.setPos(() -> 0.3));
}
}

```

## Why AGPL 3.0 as a license?
Expand Down
Loading