name: HLink Docker CI

on:
  push:
    branches:
      - main
  pull_request:
  workflow_dispatch:

env:
  HLINK_TAG: hlink:githubactions

jobs:

  build:
    strategy:
      fail-fast: false
      matrix:
        python_version: ["3.10", "3.11", "3.12"]
        hlink_extras: ["dev", "dev,lightgbm,xgboost"]
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4
    - name: Build the Docker image
      run: docker build . --file Dockerfile --tag $HLINK_TAG-${{ matrix.python_version}} --build-arg PYTHON_VERSION=${{ matrix.python_version }} --build-arg HLINK_EXTRAS=${{ matrix.hlink_extras }}

    - name: Check dependency versions
      run: |
        docker run $HLINK_TAG-${{ matrix.python_version}} python -V
        echo "Java version:"
        docker run $HLINK_TAG-${{ matrix.python_version}} java -version
    
    - name: Check formatting with black
      run: docker run $HLINK_TAG-${{ matrix.python_version}} black --check .
      
    - name: Test
      run: docker run $HLINK_TAG-${{ matrix.python_version}} pytest -ra
    
    - name: Build sdist and wheel
      run: docker run $HLINK_TAG-${{ matrix.python_version}} python -m build
