# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    environment: ci
    steps:
      - uses: actions/checkout@v5

      - name: Set up JDK 8
        uses: actions/setup-java@v5
        with:
          java-version: '8'
          distribution: 'temurin'
          cache: 'maven'
          server-id: ossrh
          server-username: CI_DEPLOY_USERNAME
          server-password: CI_DEPLOY_PASSWORD
          gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
          gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase

      - name: Build With Maven
        run: mvn -B package --file pom.xml "-Dextend.dingtalk.webhook=${{ secrets.CI_DINGTALK_HOOK }}" "-Dextend.dingtalk.secret=${{ secrets.CI_DINGTALK_SECRET }}" -P ci

      - name: Extract project Maven version
        if: github.event_name != 'pull_request'
        id: projectVersion
        run: echo "version=$(mvn org.apache.maven.plugins:maven-help-plugin:3.3.0:evaluate -DforceStdout -Dexpression=revision -q)" >> $GITHUB_OUTPUT

      - name: Deploy Snapshot
        if: github.event_name != 'pull_request' && endsWith(steps.projectVersion.outputs.version, '-SNAPSHOT')
        run:
          mvn -B deploy -DskipTests -P ossrh
        env:
          CI_DEPLOY_USERNAME: ${{ secrets.HCCAKE_OSSRH_USERNAME }}
          CI_DEPLOY_PASSWORD: ${{ secrets.HCCAKE_OSSRH_PASSWORD }}
          MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}

        # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
      - name: Update dependency graph
        if: github.event_name != 'pull_request'
        uses: advanced-security/maven-dependency-submission-action@v3