Skip to content

Add separate step for building node modules #1

Add separate step for building node modules

Add separate step for building node modules #1

Workflow file for this run

name: build package
on:
workflow_call:
inputs:
ENVIRONMENT:
required: true
type: string
MICROSERVICE_NAME:
required: true
type: string
EXPORT_FILE:
required: false
type: string
EXPORT_PATH:
required: false
type: string
DOWNLOAD_FILE:
required: false
type: string
DOWNLOAD_PATH:
required: false
type: string
env:
DIRECTORY_SUFFIX: ${{ contains(inputs.MICROSERVICE_NAME, '-api') && '-rest-endpoints' || '' }}
jobs:
build:
runs-on: ubuntu-latest
environment:
name: ${{ inputs.ENVIRONMENT }}
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'adopt'
- name: Set up nodejs
uses: actions/setup-node@v4
with:
node-version: 14
#NOTE: necessary to build client-war
- name: Add .npmrc file
run: echo -e '${{ secrets.NPMRC }}' > ~/.npmrc
- name: download files from other jobs
if: ${{ inputs.DOWNLOAD_FILE }}
uses: actions/download-artifact
with:
name: ${{ inputs.DOWNLOAD_FILE}}
path: ${{ inputs.DOWNLOAD_PATH}}
- name: Build with Maven
run: |
export MAVEN_OPTS="-Xmx3072m -XX:MaxMetaspaceSize=512m"
export NODE_OPTIONS="--max-old-space-size=4096"
mvn --settings=settings.xml --batch-mode --update-snapshots -f ${{ inputs.MICROSERVICE_NAME }}/pom.xml -Drepo.login=${{ secrets.IDIR_AS_EMAIL }} -Drepo.password=${{ secrets.IDIR_PASSWORD }} package
- name: Export file between jobs
uses: actions/upload-artifact
if: ${{ inputs.EXPORT_FILE }}
with:
name: ${{ inputs.EXPORT_FILE }}
path: ${{ inputs.EXPORT_PATH }}
- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: staging
key: ${{ runner.os }}-maven-${{ hashFiles('**war.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Extract version number
id: getVersion
run: echo "VERSION_NUMBER=$(grep -Po -m 1 '(?<=<version>)[0-9\.]+' ${{ inputs.MICROSERVICE_NAME }}/pom.xml )" >> $GITHUB_OUTPUT
- 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@v2
with:
registry: ${{ vars.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta_pr
uses: docker/metadata-action@v5
with:
images: ${{ vars.REGISTRY}}/${{ github.repository_owner }}/${{ inputs.MICROSERVICE_NAME }}
tags: |
type=schedule
type=raw,value=${{ github.base_ref }}
type=ref,event=tag
type=raw,value=${{ steps.getVersion.outputs.VERSION_NUMBER }}
${{ toJson(github.event.pull_request.number) == '{}' && format( 'type=raw,value=pr-{0}', github.event.pull_request.number) || '' }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: ./${{ inputs.MICROSERVICE_NAME }}
push: true
tags: ${{ steps.meta_pr.outputs.tags }}
labels: ${{ steps.meta_pr.outputs.labels }}
# NOTE: We store built images in ghcr.io, but use artifactory as a pull-through repository - artifacts.developer.gov.bc.ca/github-docker-remote/bcgov