Skip to content

Feature/dpav 3017

Feature/dpav 3017 #238

Workflow file for this run

# SPDX-License-Identifier: Apache-2.0
# © Crown Copyright 2025. This work has been developed by the National Digital Twin Programme
# and is legally attributed to the Department for Business and Trade (UK) as the governing entity.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
name: Automated tests
on:
push:
branches:
- 'develop'
- 'main'
pull_request:
branches:
- 'develop'
- 'main'
workflow_call:
env:
MAVEN_CLI_OPTS: "--batch-mode --no-transfer-progress"
DOCKER_TARGET: management-node
GITHUB_REPOSITORY: ${{ github.repository }}
jobs:
build:
permissions:
contents: read
pull-requests: read
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
with:
# Full history is recommended for accurate Sonar analysis and PR decoration
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
java-version: '21'
distribution: 'temurin'
cache: maven
server-password: 'GH_PACKAGES_PAT'
- name: Build and Test
env:
GH_PACKAGES_PAT: ${{ secrets.GH_PACKAGES_PAT }}
run: ./mvnw $MAVEN_CLI_OPTS verify
- name: Code Coverage
env:
GH_PACKAGES_PAT: ${{ secrets.GH_PACKAGES_PAT }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_N3 }}
run: ./mvnw $MAVEN_CLI_OPTS verify -Dsonar.projectKey=National-Node-Net_management-node -Dsonar.organization=national-node-net -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
- name: Verify JaCoCo XML exists
run: ls -l target/site/jacoco/jacoco.xml
lint:
permissions:
contents: read
pull-requests: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
- name: Set up JDK 21
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
java-version: '21'
distribution: 'temurin'
cache: maven
server-password: 'GH_PACKAGES_PAT'
- name: Lint
env:
GH_PACKAGES_PAT: ${{ secrets.GH_PACKAGES_PAT }}
run: ./mvnw $MAVEN_CLI_OPTS spotless:check
security-scanning:
permissions:
contents: read
pull-requests: read
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
- name: Set up JDK 21
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
java-version: '21'
distribution: 'temurin'
cache: maven
server-password: 'GH_PACKAGES_PAT'
- name: Get version
id: get_version
run: echo project_version=$(./mvnw $MAVEN_CLI_OPTS help:evaluate -Dexpression=project.version -q -DforceStdout) >> $GITHUB_OUTPUT
- name: Checkout repo
uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
- name: Login to ghcr.io
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Format repo name
run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
- name: Get server jar
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
pattern: management-node-*.jar
path: target
merge-multiple: true
- name: Build Server Image
run: docker build --no-cache --build-arg JAR_NAME="management-node-${{ steps.get_version.outputs.project_version}}" -t ghcr.io/${REPO}/management-node:staged -f "${{ github.workspace }}/docker/Dockerfile" --target ${{ env.DOCKER_TARGET }} .
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0
with:
image-ref: ghcr.io/${{ env.REPO }}/management-node:staged
format: table
exit-code: 1
ignore-unfixed: true
severity: "CRITICAL,HIGH"
trivyignores: .trivyignore
continue-on-error: false
- name: Clean up docker image
run: docker rmi ghcr.io/${REPO}/management-node:staged