Skip to content

Commit 813d3f0

Browse files
committed
[ci] add pre-commit stylecheck and unit test autorun
1 parent f302511 commit 813d3f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2399
-1885
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.yml]
12+
indent_size = 2

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Set up JDK
17+
uses: actions/setup-java@v4
18+
with:
19+
distribution: temurin
20+
java-version: '24'
21+
cache: maven
22+
23+
- name: Run pre-commit (push-stage hooks)
24+
uses: pre-commit/action@v3.0.1
25+
with:
26+
extra_args: --all-files --hook-stage push
27+
28+
- name: Run unit tests
29+
run: mvn -B -ntp -DskipITs test

.pre-commit-config.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.6.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-merge-conflict
8+
- id: check-yaml
9+
files: \.(yml|yaml)$
10+
- id: check-added-large-files
11+
12+
- repo: local
13+
hooks:
14+
- id: spotless-apply
15+
name: Spotless Apply (Maven)
16+
entry: mvn -q -ntp spotless:apply
17+
language: system
18+
pass_filenames: false
19+
stages: [commit]
20+
21+
- id: spotless-check
22+
name: Spotless Check (Maven)
23+
entry: mvn -q -ntp spotless:check
24+
language: system
25+
pass_filenames: false
26+
stages: [push]
27+
28+
- id: unit-tests
29+
name: Unit Tests (Maven)
30+
entry: mvn -q -ntp -DskipITs test
31+
language: system
32+
pass_filenames: false
33+
stages: [push]

docker-compose.dev.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ services:
4545
- ./infra/minio/cors.json:/config/cors.json:ro
4646
entrypoint: >
4747
/bin/sh -c '
48-
set -e;
49-
echo "Waiting for MinIO to be ready...";
50-
until (mc alias set local http://minio:9000 ezclaim E2ClaimPass >/dev/null 2>&1); do
51-
sleep 3;
52-
done;
48+
set -e;
49+
echo "Waiting for MinIO to be ready...";
50+
until (mc alias set local http://minio:9000 ezclaim E2ClaimPass >/dev/null 2>&1); do
51+
sleep 3;
52+
done;
5353
echo "Ensuring bucket and applying CORS...";
54-
mc mb -p local/ezclaim-dev || true;
55-
mc cors set local/ezclaim-dev /config/cors.json;
56-
echo "MinIO CORS configured for bucket ezclaim-dev";
54+
mc mb -p local/ezclaim-dev || true;
55+
mc cors set local/ezclaim-dev /config/cors.json;
56+
echo "MinIO CORS configured for bucket ezclaim-dev";
5757
'
5858
5959
redpanda:

infra/minio/cors.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"CORSRules": [
3+
{
4+
"AllowedOrigins": [
5+
"http://localhost:3000"
6+
],
7+
"AllowedMethods": [
8+
"GET",
9+
"PUT",
10+
"POST",
11+
"HEAD"
12+
],
13+
"AllowedHeaders": [
14+
"*"
15+
],
16+
"ExposeHeaders": [
17+
"ETag"
18+
],
19+
"MaxAgeSeconds": 3000
20+
}
21+
]
22+
}

pom.xml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,24 @@
102102

103103
<build>
104104
<plugins>
105+
<plugin>
106+
<groupId>com.diffplug.spotless</groupId>
107+
<artifactId>spotless-maven-plugin</artifactId>
108+
<version>2.44.0</version>
109+
<configuration>
110+
<java>
111+
<googleJavaFormat>
112+
<version>1.28.0</version>
113+
</googleJavaFormat>
114+
<removeUnusedImports/>
115+
<formatAnnotations/>
116+
<includes>
117+
<include>src/main/java/**/*.java</include>
118+
<include>src/test/java/**/*.java</include>
119+
</includes>
120+
</java>
121+
</configuration>
122+
</plugin>
105123
<plugin>
106124
<groupId>org.apache.maven.plugins</groupId>
107125
<artifactId>maven-compiler-plugin</artifactId>
@@ -157,4 +175,4 @@
157175
</profile>
158176
</profiles>
159177

160-
</project>
178+
</project>

scripts/install-git-hooks.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
5+
HOOKS_DIR="$ROOT_DIR/.git/hooks"
6+
7+
if [[ ! -d "$HOOKS_DIR" ]]; then
8+
echo "[install-git-hooks] .git/hooks not found. Run after 'git init' or in a cloned repo."
9+
exit 1
10+
fi
11+
12+
if command -v pre-commit >/dev/null 2>&1; then
13+
echo "[install-git-hooks] Installing pre-commit hooks via pre-commit..."
14+
(cd "$ROOT_DIR" && pre-commit install --hook-type pre-commit --hook-type pre-push)
15+
echo "[install-git-hooks] pre-commit hooks installed."
16+
else
17+
echo "[install-git-hooks] 'pre-commit' not found. Falling back to legacy shell hook."
18+
install_hook() {
19+
local name="$1"; shift
20+
local src="$ROOT_DIR/scripts/$name.sh"
21+
local dst="$HOOKS_DIR/$name"
22+
if [[ ! -f "$src" ]]; then
23+
echo "[install-git-hooks] Missing script: $src"
24+
exit 1
25+
fi
26+
cp "$src" "$dst"
27+
chmod +x "$dst"
28+
echo "[install-git-hooks] Installed $name hook."
29+
}
30+
install_hook pre-commit
31+
echo "[install-git-hooks] Legacy shell pre-commit installed. To enable full hooks, install pre-commit: pipx install pre-commit (or pip install pre-commit)."
32+
fi

scripts/pre-commit.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
echo "[pre-commit] Running Spotless (auto-fix formatting)..."
5+
mvn -q -ntp spotless:apply
6+
7+
# If formatting changed files, stage them and abort commit for a clean retry.
8+
if ! git diff --quiet || ! git diff --cached --quiet; then
9+
echo "[pre-commit] Code style changes detected by Spotless."
10+
echo "[pre-commit] Staging formatted files..."
11+
git add -A
12+
echo "[pre-commit] Formatting applied. Please re-run 'git commit'."
13+
exit 1
14+
fi
15+
16+
echo "[pre-commit] Running unit tests..."
17+
mvn -q -ntp -DskipITs test
18+
19+
echo "[pre-commit] Done."

src/main/java/org/acssz/ezclaim/EzclaimApplication.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
@SpringBootApplication
77
public class EzclaimApplication {
88

9-
public static void main(String[] args) {
10-
SpringApplication.run(EzclaimApplication.class, args);
11-
}
12-
9+
public static void main(String[] args) {
10+
SpringApplication.run(EzclaimApplication.class, args);
11+
}
1312
}

src/main/java/org/acssz/ezclaim/audit/AuditEvent.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,24 @@
22

33
import java.time.Instant;
44
import java.util.Map;
5-
6-
import org.springframework.data.annotation.Id;
7-
import org.springframework.data.mongodb.core.mapping.Document;
8-
95
import lombok.AllArgsConstructor;
106
import lombok.Builder;
117
import lombok.Data;
128
import lombok.NoArgsConstructor;
9+
import org.springframework.data.annotation.Id;
10+
import org.springframework.data.mongodb.core.mapping.Document;
1311

1412
@Data
1513
@Builder
1614
@NoArgsConstructor
1715
@AllArgsConstructor
1816
@Document(collection = "audit_events")
1917
public class AuditEvent {
20-
@Id
21-
private String id;
18+
@Id private String id;
2219

23-
private String entityType; // e.g., org.acssz.ezclaim.domain.Claim
24-
private String entityId; // document id
25-
private String action; // SAVE | DELETE | INSERT | UPDATE (optional granularity)
26-
private Instant occurredAt; // event time
27-
private Map<String, Object> data; // snapshot or delta (here: snapshot of document)
20+
private String entityType; // e.g., org.acssz.ezclaim.domain.Claim
21+
private String entityId; // document id
22+
private String action; // SAVE | DELETE | INSERT | UPDATE (optional granularity)
23+
private Instant occurredAt; // event time
24+
private Map<String, Object> data; // snapshot or delta (here: snapshot of document)
2825
}
29-

0 commit comments

Comments
 (0)