Skip to content

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

.github/workflows/mvn-build.yml

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

Workflow file for this run

env:
IMAGE_NAME: "${{ github.repository }}-${{inputs.PROJECT_NAME}}"
NPMRC: ${{ secrets.NPMRC }}
permissions:
contents: read
packages: write
# Controls when the workflow will run
on:
workflow_dispatch:
inputs:
PROJECT_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'
PROJECT_TYPE:
required: true
type: choice
options:
- server
- client
- libs
workflow_call:
inputs:
PROJECT_NAME:
type: string
required: true
TAG:
required: false
type: string
PROJECT_TYPE:
required: true
type: string
jobs:
build:
runs-on: ubuntu-latest
environment:
name: ${{ inputs.ENVIRONMENT }}
steps:
- uses: actions/checkout@v3
if: ${{ inputs.IS_HOTFIX != 'true' }}
- uses: actions/checkout@v3
if: ${{ inputs.IS_HOTFIX == 'true' }}
with:
ref: ${{ inputs.BRANCH }}
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'adopt'
- name: Add .npmrc file
run: echo -e $NPMRC > ~/.npmrc
- name: Build with Maven
run: |
export MAVEN_OPTS="-Xmx3072m -XX:MaxMetaspaceSize=512m"
export NODE_OPTIONS="--max-old-space-size=4096"
mvn --settings client/mvn_settings/settings.xml --batch-mode --update-snapshots -f client/pom.xml -Drepo.login=${{ secrets.IDIR_AS_EMAIL }} -Drepo.password=${{ secrets.IDIR_PASSWORD }} -DskipTests package
mvn --settings server/wfprev-api/mvn_settings/settings.xml --batch-mode --update-snapshots -f server/wfprev-api/pom.xml -Drepo.login=${{ secrets.IDIR_AS_EMAIL }} -Drepo.password=${{ secrets.IDIR_PASSWORD }} -DskipTests package
- name: Copy files to neccessary folders (frontend)
run: mkdir staging && cp client/wfprev-war/target/*.war staging
- name: Copy files to neccessary folders (backend)
run: mkdir staging && cp server/wfprev-api/target/*.war staging
- uses: actions/upload-artifact@v3
with:
name: ${{ inputs.PROJECT_NAME }}-package
path: staging
- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: staging
key: ${{ inputs.PROJECT_NAME }}-maven-${{ hashFiles('**war.xml') }}
restore-keys: |
${{ inputs.PROJECT_NAME }}-maven-
docker:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
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
# - uses: actions/checkout@v3
# if: ${{ github.event.inputs.IS_HOTFIX == 'true' }}
# with:
# ref: ${{ inputs.BRANCH }}
- name: download artifact (server)
if: ${{ inputs.PROJECT_TYPE == 'server' }}
uses: actions/download-artifact@v3
with:
name: ${{ inputs.PROJECT_NAME }}-package
path: ${{inputs.PROJECT_TYPE}}/${{inputs.PROJECT_NAME}}
- name: download artifact (client)
if: ${{ inputs.PROJECT_TYPE == 'client' }}
uses: actions/download-artifact@v3
with:
name: ${{ inputs.PROJECT_NAME }}-package
path: ${{inputs.PROJECT_TYPE}}/${{inputs.PROJECT_NAME}}
# - name: Update image name if PR number present
# if: ${{ github.event.pull_request.number > 0 || inputs.IS_HOTFIX == 'true' }}
# run: echo "IMAGE_NAME = ${{env.IMAGE_NAME}}-${{ inputs.IS_HOTFIX == 'true' && 'hotfix' || github.event.pull_request.number }}" >> $GITHUB_ENV
- 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 (tags, labels) for Docker (with PR)
# if: ${{ github.event.pull_request.number > 0 || inputs.IS_HOTFIX == 'true' }}
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 (backend)
if: ${{ inputs.PROJECT_TYPE == 'server' }}
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: ${{inputs.PROJECT_TYPE}}/${{inputs.PROJECT_NAME}}
build-args: |
CONTAINER_NAME=${{inputs.PROJECT_NAME}}
push: true
tags: ${{ steps.meta_pr.outputs.tags }}
labels: ${{ steps.meta_pr.outputs.labels }}
- name: Build and push Docker image (frontend)
if: ${{ inputs.PROJECT_TYPE == 'client' }}
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: ${{inputs.PROJECT_TYPE}}/${{inputs.PROJECT_NAME}}
push: true
tags: ${{ steps.meta_pr.outputs.tags }}
labels: ${{ steps.meta_pr.outputs.labels }}