Skip to content

.github/workflows/mvn-build.yml #17

.github/workflows/mvn-build.yml

.github/workflows/mvn-build.yml #17

Workflow file for this run

env:
IMAGE_NAME: "${{ github.repository }}-${{inputs.COMPONENT_NAME}}"
NPMRC: ${{ secrets.NPMRC }}
permissions:
contents: read
packages: write
on:
workflow_dispatch:
inputs:
COMPONENT_NAME:
type: string
description: 'Name of project, as given to the subfolder of /server or /client to build'
required: true
TAG:
required: false
type: string
description: 'Additional tag to add to docker image'
COMPONENT_TYPE:
required: true
type: choice
options:
- server
- libs
workflow_call:
inputs:
COMPONENT_NAME:
type: string
required: true
TAG:
required: false
type: string
COMPONENT_TYPE:
required: true
type: string
jobs:
build:
runs-on: ubuntu-latest
environment:
name: ${{ inputs.ENVIRONMENT }}
steps:
- uses: actions/checkout@v4
if: ${{ inputs.IS_HOTFIX != 'true' }}
- uses: actions/checkout@v4
if: ${{ inputs.IS_HOTFIX == 'true' }}
with:
ref: ${{ inputs.BRANCH }}
- name: Setup Maven
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
cache: 'maven'
- name: Setup GraalVM
uses: graalvm/setup-graalvm@v1
with:
java-version: '21'
distribution: 'graalvm-community'
github-token: ${{ secrets.GITHUB_TOKEN }}
native-image-job-reports: 'true'
components: 'native-image'
- name: Add .npmrc file
run: echo -e $NPMRC > ~/.npmrc
- name: Build Native Image with Maven
if: ${{ inputs.COMPONENT_TYPE == 'server' }}
run: |
set -x
export MAVEN_OPTS="-Xmx6g -XX:MaxMetaspaceSize=1g"
export NATIVE_IMAGE_OPTS="-Xmx8g"
cd ${{ inputs.COMPONENT_TYPE }}/${{ inputs.COMPONENT_NAME }}
# Use absolute path to settings.xml
settings_file="$(pwd)/mvn_settings/settings.xml"
echo "Looking for settings file at: $settings_file"
# Check if file exists and is readable
if [ ! -f "$settings_file" ]; then
echo "ERROR: $settings_file not found!"
ls -la mvn_settings/
exit 1
fi
if [ ! -r "$settings_file" ]; then
echo "ERROR: $settings_file not readable!"
ls -la "$settings_file"
exit 1
fi
echo "Using settings file: $settings_file"
mvn -s "$settings_file" --batch-mode -Pnative native:compile -DskipTests -Drepo.login=${{ secrets.IDIR_AS_EMAIL }} -Drepo.password=${{ secrets.IDIR_PASSWORD }}
- name: Copy native binary to staging
if: ${{ inputs.COMPONENT_TYPE == 'server' }}
run: |
mkdir -p staging
cp ${{ inputs.COMPONENT_TYPE }}/${{ inputs.COMPONENT_NAME }}/target/wfprev-api staging/
- uses: actions/upload-artifact@v3
with:
name: ${{ inputs.COMPONENT_NAME }}-package
path: staging
docker:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
if: ${{ github.event.inputs.IS_HOTFIX != 'true' }}
- id: trimBranchName
name: trim branch name if necessary
run: |
export branchTag="${{ github.ref_name }}"
trimTag="${branchTag##*/}"
echo "BRANCH_TAG=$trimTag" >> $GITHUB_OUTPUT
- name: download native binary
uses: actions/download-artifact@v3
with:
name: ${{ inputs.COMPONENT_NAME }}-package
path: ${{inputs.COMPONENT_TYPE}}/${{inputs.COMPONENT_NAME}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ vars.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN}}
- name: Extract metadata for Docker
id: meta_pr
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ vars.REGISTRY}}/${{ env.IMAGE_NAME }}
tags: |
type=schedule
type=raw,value=${{ steps.trimBranchName.outputs.BRANCH_TAG }}
type=ref,event=tag
type=raw,value=${{ inputs.TAG }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ${{inputs.COMPONENT_TYPE}}/${{inputs.COMPONENT_NAME}}
file: ${{inputs.COMPONENT_TYPE}}/${{inputs.COMPONENT_NAME}}/Dockerfile.graalvm
build-args: |
CONTAINER_NAME=${{inputs.COMPONENT_NAME}}
MAVEN_SETTINGS_FILE=settings.xml
push: true
tags: ${{ steps.meta_pr.outputs.tags }}
labels: ${{ steps.meta_pr.outputs.labels }}