Skip to content

Refactor GUI package #127

Refactor GUI package

Refactor GUI package #127

Workflow file for this run

name: Maven CI/CD
on: [ push, pull_request ]
jobs:
test:
runs-on : ubuntu-latest
permissions:
contents: read
env:
HAVE_SONAR_TOKEN: ${{ secrets.SONAR_TOKEN != '' }}
HAVE_SONAR_DETAILS: ${{ vars.SONAR_PROJECTKEY != '' && vars.SONAR_ORGANIZATION != '' }}
HAVE_DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN != '' }}
steps :
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout NJ-image-test
uses: actions/checkout@v4
with:
repository: GReD-Clermont/NucleusJ-tests-images
ref: 'v1'
path: test-images
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17' # 17 for Sonar
distribution: 'adopt'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ secrets.CACHE_VERSION }}-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2-${{ secrets.CACHE_VERSION }}
- name: Append branch name to version if 'push' did not happen on 'main' or a tag
if: ${{ github.event_name == 'push' && github.ref != 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/')}}
run: |
mvn versions:set -DremoveSnapshot
mvn help:evaluate -N -Dexpression=project.version|grep -v '\['
VERSION=$(mvn help:evaluate -N -Dexpression=project.version|grep -v '\[')
mvn versions:set -DnewVersion=$VERSION-${GITHUB_REF##*/}
- name : Package and test
run: mvn clean package
- name: Set folders ownership back to current user
run: sudo chown -R $(id -u):$(id -g) $GITHUB_WORKSPACE && sudo chown -R $(id -u):$(id -g) $HOME
- name: Sonar analysis
if: ${{ env.HAVE_SONAR_TOKEN == 'true' && env.HAVE_SONAR_DETAILS == 'true' }}
run: mvn sonar:sonar -Dsonar.host.url=$SONAR_URL -Dsonar.projectKey=$SONAR_PROJECTKEY -Dsonar.organization=$SONAR_ORGANIZATION
env:
SONAR_PROJECTKEY: ${{ vars.SONAR_PROJECTKEY }}
SONAR_ORGANIZATION: ${{ vars.SONAR_ORGANIZATION }}
SONAR_URL: ${{ vars.SONAR_URL }}
GITHUB_TOKEN: ${{ github.token }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
path: target
deploy:
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) }}
needs: [ test ]
runs-on : ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'adopt'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ secrets.CACHE_VERSION }}-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2-${{ secrets.CACHE_VERSION }}
- name: Append 'SNAPSHOT' to version if 'push' happened on 'main'
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: |
mvn versions:set -DremoveSnapshot
mvn help:evaluate -N -Dexpression=project.version|grep -v '\['
VERSION=$(mvn help:evaluate -N -Dexpression=project.version|grep -v '\[')
mvn versions:set -DnewVersion=$VERSION-SNAPSHOT
- name: Deploy
run: mvn deploy -DskipTests -s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}