name: Build on Mac

on: 
  workflow_call:
    inputs:
      verSion:
        required: true
        type: string
    secrets:
      AWS_ACCESS_KEY_ID:
        required: true
      AWS_SECRET_ACCESS_KEY:
        required: true
      AWS_BUCKET:
        required: true
  workflow_dispatch:

jobs:
  build-mac:
    runs-on: macos-11

    steps:
    - name: 'Checkout GitHub Action'
      uses: actions/checkout@v3
    - name: Set up JDK 17
      uses: actions/setup-java@v3
      with:
        distribution: 'temurin' # See 'Supported distributions' for available options.
        java-version: '8'
    - name: build jar
      run: |
        echo $JAVA_HOME
        export CPPFLAGS="-I$JAVA_HOME/include"
        export CXXFLAGS="-I$JAVA_HOME/include"
        brew install zlib
        brew install bzip2 lz4 snappy
        ROCKSDB_DISABLE_JEMALLOC=1 PORTABLE=1 DEBUG_LEVEL=0 make -j 2 rocksdbjavastatic #more CPU cores makes shared github runner to overload cpu and stop

    - name: Upload artifacts to S3
      if: inputs.verSion != ' '
      uses: NotCoffee418/s3-zip-upload@v1
      env:
        AWS_SECRET_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        AWS_BUCKET: ${{ secrets.AWS_BUCKET }}
        BUCKET_NAME: spdb-builder
        AWS_REGION:  us-east-1
        SOURCE_MODE: FILE
        SOURCE_PATH: java/target/libspeedbjni-osx-x86_64.jnilib
        DEST_FILE: jar_test/v${{ inputs.verSion }}/libspeedbjni-osx-x86_64.jnilib