Skip to content
Merged
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
24 changes: 24 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env sh

set -e

echo "🔍 Running pre-commit checks..."

# Check for staged Java files
STAGED_JAVA_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.java$' ||
true)

if [ -n "$STAGED_JAVA_FILES" ]; then
echo "📝 Checking code format..."
./gradlew spotlessCheck --quiet

if [ $? -ne 0 ]; then
echo ""
echo "❌ Code formatting issues found!"
echo "Run './gradlew spotlessApply' to fix them."
exit 1
fi
echo "✅ Code format OK"
fi

echo "✅ Pre-commit checks passed!"
25 changes: 25 additions & 0 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env sh

set -e

echo "🚀 Running pre-push checks..."

# Run tests
echo "🧪 Running tests..."
./gradlew test --quiet

if [ $? -ne 0 ]; then
echo "❌ Tests failed! Push aborted."
exit 1
fi

# Check coverage
echo "📊 Checking test coverage..."
./gradlew jacocoTestCoverageVerification --quiet

if [ $? -ne 0 ]; then
echo "❌ Coverage below threshold! Push aborted."
exit 1
fi

echo "✅ All pre-push checks passed!"
114 changes: 114 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: CI

on:
pull_request:
branches: [ main ]
types: [ ready_for_review, opened, reopened, synchronize ]
push:
branches: [ main ]
# Cancel in-progress runs for the same PR/branch
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build & Test
runs-on: ubuntu-latest
# Skip draft PRs
if: github.event.pull_request.draft == false

services:
postgres:
image: postgres:17
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test-db
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 3
steps:
- name: Checkout code
uses: actions/checkout@v6

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

- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: ${{ runner.os }}-gradle-

- name: Grant execute permissions for gradlew
run: chmod +x gradlew

- name: Check code formatting
run: ./gradlew spotlessCheck

- name: Build
run: ./gradlew build -x test

- name: Run tests
run: ./gradlew test
env:
SPRING_DATASOURCE_URL: jdbc:postgresql://localhost:5432/test-db
SPRING_DATASOURCE_USERNAME: test
SPRING_DATASOURCE_PASSWORD: test

- name: Generate test coverage report
run: ./gradlew jacocoTestReport

- name: Check test coverage
run: ./gradlew jacocoTestCoverageVerification

- name: Upload coverage report
uses: actions/upload-artifact@v5
if: always()
with:
name: coverage-report
path: build/reports/jacoco/test/html/
retention-days: 7

- name: Upload test results
uses: actions/upload-artifact@v5
if: always()
with:
name: test-results
path: build/reports/tests/test/
retention-days: 7

# Add coverage comment to PR
coverage-comment:
name: Coverage Report
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'pull_request'

steps:
- name: Download coverage report
uses: actions/download-artifact@v6
with:
name: coverage-report
path: coverage

- name: Add coverage to PR
uses: madrapps/jacoco-report@v1.7.2
with:
paths: build/reports/jacoco/test/jacocoTestReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 80
min-coverage-changed-files: 80


16 changes: 16 additions & 0 deletions auto/setup-hooks
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh
set -e

echo "🔧 Setting up git hooks..."

# Configure git to use .githooks directory
git config core.hooksPath .githooks

# Make hooks executable
chmod +x .githooks/*

echo "✅ Git hooks configured!"
echo ""
echo "Hooks installed:"
echo " - pre-commit: Format check"
echo " - pre-push: Tests + coverage"
5 changes: 0 additions & 5 deletions auto/test

This file was deleted.

Loading
Loading