# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle 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-gradle

name: Build

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main, develop ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4

    - name: Set up JDK8
      uses: actions/setup-java@v4
      with:
        distribution: 'temurin'
        java-version: 8

    - name: Clean Cache
      run: |
        rm -rf ~/.m2/repository/
        rm -rf ~/.gradle/

    - name: Clone Submodule
      run: git submodule update --init --recursive

    - name: Build Dingo Project
      run: |
        ./gradlew build

    - name: Build Java Documents
      uses: gradle/gradle-build-action@937999e9cc2425eddc7fd62d1053baf041147db7
      with:
        arguments: javadoc

    - name: Archive the dingo directory
      run: |
        mkdir dingo
        unzip ./dingo-dist/build/distributions/dingo.zip -d dingo
        wget https://github.com/dingodb/dingo-deploy/raw/main/artifacts/sqlline-1.13.0-SNAPSHOT-jar-with-dependencies.jar -P dingo/libs/
        cp -r ./dingo-client/build/docs/javadoc ./dingo/javadoc
        cp -r ./docker/templates/bin/* ./dingo/bin/
        cp -r ./docker/templates/conf/* ./dingo/conf/
        rm -rf ./dingo/conf/logback.xml
        rm -rf ./dingo/conf/config.yaml
        zip -r dingo.zip dingo/*

    - name: copy artifactory to another workflow
      uses: actions/upload-artifact@v4
      with:
          name: dingo.zip
          path: ./dingo.zip
