1+ name : CI
2+
3+ on :
4+ push :
5+ branches : [ main ]
6+ pull_request :
7+ branches : [ main ]
8+
9+ jobs :
10+ test :
11+ runs-on : ubuntu-latest
12+
13+ steps :
14+ - uses : actions/checkout@v4
15+
16+ - name : Set up JDK 21
17+ uses : actions/setup-java@v4
18+ with :
19+ java-version : ' 21'
20+ distribution : ' temurin'
21+
22+ - name : Cache Gradle packages
23+ uses : actions/cache@v4
24+ with :
25+ path : |
26+ ~/.gradle/caches
27+ ~/.gradle/wrapper
28+ key : ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
29+ restore-keys : |
30+ ${{ runner.os }}-gradle-
31+
32+ - name : Make gradlew executable
33+ run : chmod +x ./gradlew
34+
35+ - name : Run tests
36+ run : ./gradlew test
37+
38+ - name : Build application
39+ run : ./gradlew build
40+
41+ docker :
42+ runs-on : ubuntu-latest
43+ needs : test
44+ if : github.ref == 'refs/heads/main'
45+
46+ steps :
47+ - uses : actions/checkout@v4
48+
49+ - name : Set up Docker Buildx
50+ uses : docker/setup-buildx-action@v3
51+
52+ - name : Log in to GitHub Container Registry
53+ uses : docker/login-action@v3
54+ with :
55+ registry : ghcr.io
56+ username : ${{ github.actor }}
57+ password : ${{ secrets.GITHUB_TOKEN }}
58+
59+ - name : Extract metadata
60+ id : meta
61+ uses : docker/metadata-action@v5
62+ with :
63+ images : ghcr.io/${{ github.repository }}
64+ tags : |
65+ type=ref,event=branch
66+ type=sha,prefix={{branch}}-
67+ type=raw,value=latest,enable={{is_default_branch}}
68+
69+ - name : Build and push Docker image
70+ uses : docker/build-push-action@v5
71+ with :
72+ context : .
73+ push : true
74+ tags : ${{ steps.meta.outputs.tags }}
75+ labels : ${{ steps.meta.outputs.labels }}
76+ cache-from : type=gha
77+ cache-to : type=gha,mode=max
0 commit comments