Skip to content

chore: add github jobs #1

chore: add github jobs

chore: add github jobs #1

name: Build, Test and Publish Container
on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: erhardtconsulting/database-development-app
jobs:
maven:
name: Maven build and tests
runs-on: ubuntu-24.04
outputs:
app-version: ${{ steps.project-version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Java 24
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "24"
cache: maven
- name: Read project version
id: project-version
run: echo "version=$(./mvnw -q -DforceStdout help:evaluate -Dexpression=project.version)" >> "$GITHUB_OUTPUT"
- name: Run fast tests
run: ./mvnw -B test
- name: Run Testcontainers integration tests
run: ./mvnw -B -Ptestcontainers test
- name: Build application package
run: ./mvnw -B package -DskipTests
container:
name: Container build and publish
runs-on: ubuntu-24.04
needs: maven
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare image tags
id: image-tags
run: |
SHORT_SHA="${GITHUB_SHA::7}"
VERSION="${{ needs.maven.outputs.app-version }}"
IMAGE="${REGISTRY}/${IMAGE_NAME}"
{
echo "tags<<EOF"
echo "${IMAGE}:${VERSION}-${SHORT_SHA}"
if [ "${GITHUB_EVENT_NAME}" = "push" ] && [ "${GITHUB_REF}" = "refs/heads/main" ]; then
echo "${IMAGE}:latest"
fi
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Build container image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
platforms: linux/amd64
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
tags: ${{ steps.image-tags.outputs.tags }}