Skip to content

Commit 9f45b18

Browse files
committed
chore: add github jobs
1 parent 4398531 commit 9f45b18

2 files changed

Lines changed: 100 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Build, Test and Publish Container
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
packages: write
15+
16+
env:
17+
REGISTRY: ghcr.io
18+
IMAGE_NAME: erhardtconsulting/database-development-app
19+
20+
jobs:
21+
maven:
22+
name: Maven build and tests
23+
runs-on: ubuntu-24.04
24+
outputs:
25+
app-version: ${{ steps.project-version.outputs.version }}
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
30+
- name: Set up Java 24
31+
uses: actions/setup-java@v4
32+
with:
33+
distribution: temurin
34+
java-version: "24"
35+
cache: maven
36+
37+
- name: Read project version
38+
id: project-version
39+
run: echo "version=$(./mvnw -q -DforceStdout help:evaluate -Dexpression=project.version)" >> "$GITHUB_OUTPUT"
40+
41+
- name: Run fast tests
42+
run: ./mvnw -B test
43+
44+
- name: Run Testcontainers integration tests
45+
run: ./mvnw -B -Ptestcontainers test
46+
47+
- name: Build application package
48+
run: ./mvnw -B package -DskipTests
49+
50+
container:
51+
name: Container build and publish
52+
runs-on: ubuntu-24.04
53+
needs: maven
54+
steps:
55+
- name: Checkout repository
56+
uses: actions/checkout@v4
57+
58+
- name: Set up Docker Buildx
59+
uses: docker/setup-buildx-action@v3
60+
61+
- name: Log in to GitHub Container Registry
62+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
63+
uses: docker/login-action@v3
64+
with:
65+
registry: ${{ env.REGISTRY }}
66+
username: ${{ github.actor }}
67+
password: ${{ secrets.GITHUB_TOKEN }}
68+
69+
- name: Prepare image tags
70+
id: image-tags
71+
run: |
72+
SHORT_SHA="${GITHUB_SHA::7}"
73+
VERSION="${{ needs.maven.outputs.app-version }}"
74+
IMAGE="${REGISTRY}/${IMAGE_NAME}"
75+
{
76+
echo "tags<<EOF"
77+
echo "${IMAGE}:${VERSION}-${SHORT_SHA}"
78+
if [ "${GITHUB_EVENT_NAME}" = "push" ] && [ "${GITHUB_REF}" = "refs/heads/main" ]; then
79+
echo "${IMAGE}:latest"
80+
fi
81+
echo "EOF"
82+
} >> "$GITHUB_OUTPUT"
83+
84+
- name: Build container image
85+
uses: docker/build-push-action@v6
86+
with:
87+
context: .
88+
file: Dockerfile
89+
platforms: linux/amd64
90+
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
91+
tags: ${{ steps.image-tags.outputs.tags }}

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ podman compose up --build
9696

9797
Danach ist die API unter `http://localhost:8080/api/tickets` erreichbar.
9898

99+
## GitHub Actions und Container Registry
100+
101+
Das Repository enthält einen GitHub-Actions-Workflow für die App:
102+
103+
- Pull Requests führen `./mvnw test`, `./mvnw -Ptestcontainers test` und einen Docker-Build ohne Push aus.
104+
- Pushes auf `main` führen dieselben Prüfungen aus und veröffentlichen das Image in der GitHub Container Registry.
105+
- Das veröffentlichte Image heisst `ghcr.io/erhardtconsulting/database-development-app`.
106+
- `latest` wird nur von `main` gesetzt; zusätzlich erhält jedes Image einen Versions- und Commit-Tag.
107+
99108
## Swagger und OpenAPI
100109

101110
Die API-Dokumentation ist in der laufenden Anwendung verfügbar:

0 commit comments

Comments
 (0)