93 lines
2.3 KiB
YAML
93 lines
2.3 KiB
YAML
name: ci
|
|
|
|
on:
|
|
push:
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- name: Set up JDK 17
|
|
uses: actions/setup-java@v3
|
|
with:
|
|
java-version: '17'
|
|
distribution: 'temurin'
|
|
cache: maven
|
|
|
|
- name: Build with Maven
|
|
run: ./mvnw clean package -DskipTests
|
|
|
|
run-tests:
|
|
runs-on: ubuntu-latest
|
|
needs: [ build ]
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v3
|
|
- name: Set up JDK 17
|
|
uses: actions/setup-java@v3
|
|
with:
|
|
java-version: '17'
|
|
distribution: 'temurin'
|
|
cache: maven
|
|
|
|
- name: Running Tests with Maven
|
|
run: ./mvnw test
|
|
|
|
docker:
|
|
needs: [ build, run-tests ]
|
|
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write # required to push to ghcr.io
|
|
id-token: write # optional for OIDC if you use it
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to GHCR
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Prepare image tags
|
|
run: |
|
|
OWNER=$(echo "${GITHUB_REPOSITORY_OWNER}" | tr '[:upper:]' '[:lower:]')
|
|
REPO=$(echo "${GITHUB_REPOSITORY#*/}" | tr '[:upper:]' '[:lower:]')
|
|
|
|
# Determine tag
|
|
if [ "${GITHUB_REF_NAME}" = "main" ]; then
|
|
TAG="latest"
|
|
else
|
|
TAG="dev"
|
|
fi
|
|
|
|
SHORT_SHA=$(echo "${GITHUB_SHA}" | cut -c1-7)
|
|
IMAGE_BASE="ghcr.io/${OWNER}/${REPO}"
|
|
|
|
echo "IMAGE_LATEST=${IMAGE_BASE}:${TAG}" >> $GITHUB_ENV
|
|
echo "IMAGE_SHA=${IMAGE_BASE}:sha-${SHORT_SHA}" >> $GITHUB_ENV
|
|
|
|
- name: Build and push Docker image (with registry cache)
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
push: true
|
|
platforms: linux/amd64,linux/arm64
|
|
tags: |
|
|
${{ env.IMAGE_LATEST }}
|
|
${{ env.IMAGE_SHA }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|