name: hdf4 dev CI

# Triggers the workflow on a call from another workflow
on:
  workflow_call:
    inputs:
      build_mode:
        description: "release vs. debug build"
        required: true
        type: string
      build_option:
        description: "--enable-production or --disable-production"
        required: true
        type: string
      shared:
        description: "shared enable/disable"
        required: true
        type: string
      netcdf:
        description: "netcdf enable/disable"
        required: true
        type: string

permissions:
  contents: read

jobs:

  # A workflow that builds the library and runs all the tests
  # Linux (Ubuntu) w/ gcc + Autotools
  #
  Autotools_build_and_test:
    name: "GCC-${{ inputs.build_mode }}-NC=${{ inputs.netcdf }}d"
    # Don't run the action if the commit message says to skip CI
    if: "!contains(github.event.head_commit.message, 'skip-ci')"

    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # SETUP
      - name: Install Linux Dependencies
        run: |
          sudo apt update
          sudo apt install -y autoconf automake libtool libtool-bin libaec-dev libjpeg-dev
          sudo apt install -y doxygen libncurses-dev libquadmath0 libstdc++6 libxml2
          sudo apt install -y zlib1g-dev libcurl4-openssl-dev libjpeg-dev wget curl bzip2
          sudo apt install -y m4 flex bison cmake libzip-dev openssl build-essential

      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: Get Sources
        uses: actions/checkout@v4.1.7

      - name: Autotools Configure
        run: |
          sh ./autogen.sh
          mkdir "${{ runner.workspace }}/build"
          cd "${{ runner.workspace }}/build"
          $GITHUB_WORKSPACE/configure \
            ${{ inputs.build_option }} \
            --${{ inputs.netcdf }}-netcdf \
            --disable-fortran \
            --${{ inputs.shared }}-java \
            --${{ inputs.shared }}-shared
        shell: bash

      - name: Autotools Build
        run: make -j3
        working-directory: ${{ runner.workspace }}/build

      - name: Autotools Run Tests
        run: make check -j2
        working-directory: ${{ runner.workspace }}/build

      # INSTALL (note that this runs even when we don't run the tests)
      - name: Autotools Install
        run: make install
        working-directory: ${{ runner.workspace }}/build

#      - name: Autotools Verify Install
#        run: make check-install
#        working-directory: ${{ runner.workspace }}/build
