name: CI

on:
  workflow_dispatch:
  push:
    paths-ignore:
      - '.github/**'

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - nickname: linux jdk17
            java: 17
            os: ubuntu-latest
          - nickname: macos jdk17
            java: 17
            os: macos-latest
          - nickname: windows jdk17
            java: 17
            os: windows-latest
    name: CI Build ${{ matrix.nickname }}
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-java@v3
        with:
          distribution: adopt
          java-version: ${{ matrix.java }}
          cache: gradle
      - name: Build
        run: ./gradlew build
  publish:
    runs-on: ubuntu-latest
    if: github.repository_owner == 'spring-projects'
    needs: [build]
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-java@v3
        with:
          distribution: adopt
          java-version: 17
          cache: gradle
      - uses: jfrog/setup-jfrog-cli@v3
        with:
          version: 2.21.5
        env:
          JF_ENV_SPRING: ${{ secrets.JF_ARTIFACTORY_SPRING }}
      - name: Configure JFrog Cli
        run: |
          jf rt gradlec \
            --use-wrapper \
            --uses-plugin \
            --deploy-ivy-desc=false \
            --server-id-resolve repo.spring.io \
            --server-id-deploy repo.spring.io \
            --repo-resolve snapshot \
            --repo-deploy snapshot
          echo JFROG_CLI_BUILD_NAME=spring-shell-main >> $GITHUB_ENV
          echo JFROG_CLI_BUILD_NUMBER=$GITHUB_RUN_NUMBER >> $GITHUB_ENV
      - name: Build and Publish
        env:
          ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_PRIVATE_KEY }}
          ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.GPG_PASSPHRASE }}
          GRADLE_ENTERPRISE_CACHE_USERNAME: ${{ secrets.GRADLE_ENTERPRISE_CACHE_USER }}
          GRADLE_ENTERPRISE_CACHE_PASSWORD: ${{ secrets.GRADLE_ENTERPRISE_CACHE_PASSWORD }}
          GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_SECRET_ACCESS_KEY }}
        run: |
          jf rt gradle build distZip artifactoryPublish
          jf rt build-publish
