# 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: Deploy 1.x to Maven Central

on:
  # 手动触发事件
  workflow_dispatch:

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

      - name: Set up JDK 8
        uses: actions/setup-java@v3
        with:
          ref: '1.x'
          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: Deploy Release
        if: github.event_name != 'pull_request'
        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 }}