name: Maven Release

on:
  workflow_dispatch:
  push:
    branches:
      - main

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: CheckOut
        uses: actions/checkout@v5
        with:
          fetch-depth: 0

      - name: Set up JDK 17
        uses: actions/setup-java@v5
        with:
          distribution: temurin
          java-version: 17

      - name: Cache local Maven repository
        uses: actions/cache@v4
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
          restore-keys: |
            ${{ runner.os }}-maven-

      - name: SonarScan
        env:
          SONAR_HOST_URL: https://sonarde.vmn.io
        run: mvn -P mtvi -s integration-test/settings.xml -f integration-test/pom.xml clean test-compile sonar:sonar -U -Dmtvi_nexus_username=${{ secrets.MTVI_NEXUS_USERID }} -Dmtvi_nexus_password=${{ secrets.MTVI_NEXUS_PASSWORD }} -Dsonar_login=${{ secrets.SONARQUBE_TOKEN_PARAMOUNT }}

      - name: Configure Git user
        run: |
          git config --global user.email "jenkins@pluto.tv"
          git config --global user.name "JenkinsPTV"

      - name: Configure ssh
        uses: webfactory/ssh-agent@v0.9.0
        with:
          ssh-private-key: ${{ secrets.STE_GHA_TOKEN }}

      - name: Maven Release | Prepare & Perform
        run: mvn -P mtvi --batch-mode -s integration-test/settings.xml -f integration-test/pom.xml release:clean release:prepare release:perform -X -Dmtvi_nexus_username=${{ secrets.MTVI_NEXUS_USERID }} -Dmtvi_nexus_password=${{ secrets.MTVI_NEXUS_PASSWORD }} -DskipTests -Dmaven.test.skip=true -DxmlFileName=testng.xml