Skip to content

Commit b9eace5

Browse files
Set up GitHub Actions CI workflow for automated testing and Docker builds
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
1 parent e79f420 commit b9eace5

2 files changed

Lines changed: 77 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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

Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ FROM eclipse-temurin:21-jdk AS build
44

55
WORKDIR /app
66

7-
# Create .gradle directory with proper permissions
8-
RUN mkdir -p /home/app/.gradle && chmod -R 777 /home/app/.gradle
9-
107
# Copy the Gradle wrapper, build.gradle and settings.gradle
118
COPY gradlew .
129
COPY gradle gradle

0 commit comments

Comments
 (0)