This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: build and test | |
on: | |
push: | |
workflow_dispatch: | |
inputs: | |
version: | |
type: string | |
required: true | |
description: semver - If set, the image will be published to ghcr.io with the semver as image-Tag. | |
default: '' | |
env: | |
MVN_PROJECT_ROOT: ./ | |
MVN_SUBPROJECT_BATCH: ./batch | |
MVN_SUBPROJECT_WEB: ./web | |
MVN_BUILD_TARGET_BATCH: ./batch/target | |
MVN_BUILD_TARGET_WEB: ./web/target | |
jobs: | |
compliance: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Advance Security Policy as Code | |
uses: advanced-security/policy-as-code@v2.7.2 | |
with: | |
policy: it-at-m/policy-as-code | |
policy-path: default.yaml | |
token: ${{ secrets.GITHUB_TOKEN }} | |
argvs: "--disable-dependabot --disable-secret-scanning --disable-code-scanning --display" | |
build: | |
runs-on: ubuntu-latest | |
name: Build and test the application | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
- name: build | |
working-directory: ${{ env.MVN_PROJECT_ROOT }} | |
run: mvn clean install | |
- name: test | |
working-directory: ${{ env.MVN_PROJECT_ROOT }} | |
run: mvn test | |
- name: Archive artifacts batch | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-artifacts-batch | |
path: ${{ env.MVN_BUILD_TARGET_BATCH }} | |
- name: Archive artifacts web | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build-artifacts-web | |
path: ${{ env.MVN_BUILD_TARGET_WEB }} | |
build-and-push-image-to-ghcr: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Download artifacts batch | |
uses: actions/download-artifact@v4 | |
with: | |
name: build-artifacts-batch | |
path: ${{ env.MVN_BUILD_TARGET_BATCH }} | |
- name: Download artifacts web | |
uses: actions/download-artifact@v4 | |
with: | |
name: build-artifacts-web | |
path: ${{ env.MVN_BUILD_TARGET_WEB }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker (BATCH) | |
id: meta1 | |
uses: docker/metadata-action@v5 | |
with: | |
images: ghcr.io/${{ github.repository }}-batch | |
tags: | | |
type=semver,pattern={{version}},value=${{ inputs.version }},enable=${{ github.event_name == 'workflow_dispatch' }} | |
- name: Build and push untested Docker image to GHCR (BATCH) | |
uses: docker/build-push-action@v5 | |
with: | |
context: ${{ env.MVN_SUBPROJECT_BATCH }} | |
push: ${{ github.event.inputs.version != '' }} | |
tags: ${{ steps.meta1.outputs.tags }} | |
labels: ${{ steps.meta1.outputs.labels }} | |
- name: Extract metadata (tags, labels) for Docker (WEB) | |
id: meta2 | |
uses: docker/metadata-action@v5 | |
with: | |
images: ghcr.io/${{ github.repository }}-web | |
tags: | | |
type=semver,pattern={{version}},value=${{ inputs.version }},enable=${{ github.event_name == 'workflow_dispatch' }} | |
- name: Build and push untested Docker image to GHCR (WEB) | |
uses: docker/build-push-action@v5 | |
with: | |
context: ${{ env.MVN_SUBPROJECT_WEB }} | |
push: ${{ github.event.inputs.version != '' }} | |
tags: ${{ steps.meta2.outputs.tags }} | |
labels: ${{ steps.meta2.outputs.labels }} |