.github/workflows/mvn-build.yml #7
This file contains 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
env: | |
IMAGE_NAME: "${{ github.repository }}-${{inputs.COMPONENT_NAME}}" | |
NPMRC: ${{ secrets.NPMRC }} | |
permissions: | |
contents: read | |
packages: write | |
# Controls when the workflow will run | |
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 | |
- client | |
- 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@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 API with Maven | |
if: ${{ inputs.COMPONENT_TYPE == 'server' }} | |
run: | | |
export MAVEN_OPTS="-Xmx3072m -XX:MaxMetaspaceSize=512m" | |
export NODE_OPTIONS="--max-old-space-size=4096" | |
mvn --settings ${{ inputs.COMPONENT_TYPE }}/${{ inputs.COMPONENT_NAME }}/mvn_settings/settings.xml --batch-mode --update-snapshots -f ${{ inputs.COMPONENT_TYPE }}/${{ inputs.COMPONENT_NAME }}/pom.xml -Drepo.login=${{ secrets.IDIR_AS_EMAIL }} -Drepo.password=${{ secrets.IDIR_PASSWORD }} -DskipTests package | |
- name: Build UI with Maven | |
if: ${{ inputs.COMPONENT_TYPE == 'client' }} | |
run: | | |
export MAVEN_OPTS="-Xmx3072m -XX:MaxMetaspaceSize=512m" | |
export NODE_OPTIONS="--max-old-space-size=4096" | |
mvn --settings ${{ inputs.COMPONENT_TYPE }}/mvn_settings/settings.xml --batch-mode --update-snapshots -f ${{ inputs.COMPONENT_TYPE }}/pom.xml -Drepo.login=${{ secrets.IDIR_AS_EMAIL }} -Drepo.password=${{ secrets.IDIR_PASSWORD }} -DskipTests package | |
- name: Copy files to neccessary folders | |
run: mkdir staging && cp ${{ inputs.COMPONENT_TYPE }}/${{ inputs.COMPONENT_NAME }}/target/*.war staging | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ inputs.COMPONENT_NAME }}-package | |
path: staging | |
- name: Cache local Maven repository | |
uses: actions/cache@v2 | |
with: | |
path: staging | |
key: ${{ inputs.COMPONENT_NAME }}-maven-${{ hashFiles('**war.xml') }} | |
restore-keys: | | |
${{ inputs.COMPONENT_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 | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ inputs.COMPONENT_NAME }}-package | |
path: ${{inputs.COMPONENT_TYPE}}/${{inputs.COMPONENT_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 | |
uses: docker/build-push-action@v6 | |
with: | |
context: ${{inputs.COMPONENT_TYPE}}/${{inputs.COMPONENT_NAME}} | |
build-args: | | |
CONTAINER_NAME=${{inputs.COMPONENT_NAME}} | |
push: true | |
tags: ${{ steps.meta_pr.outputs.tags }} | |
labels: ${{ steps.meta_pr.outputs.labels }} |