name: cobj-api tests

on:
  workflow_call:
    inputs:
      os:
        required: true
        type: string

permissions:
  contents: read

env:
  CLASSPATH: ":/usr/lib/opensourcecobol4j/libcobj.jar"

jobs:
  test-other:
    runs-on: ubuntu-latest
    container:
      image: ${{ inputs.os }}
    steps:
      - name: Get the artifact name
        run: echo "ARTIFACT_NAME=${{ inputs.os }}" | sed 's/:/-/g' >> "$GITHUB_ENV"

      - uses: actions/download-artifact@v4
        with:
          name: opensourcecobol4j-${{ env.ARTIFACT_NAME }}

      - uses: actions/setup-java@v4
        if: inputs.os != 'amazonlinux:2023'
        with:
          distribution: 'temurin'
          java-version: '11'

      - name: Install dependencies on Ubuntu 24.04
        if: inputs.os == 'ubuntu:24.04'
        run: |
          apt-get update -y
          apt-get install -y build-essential

      - name: Install dependencies on AlmaLinux 9
        if: inputs.os == 'almalinux:9'
        run: |
          dnf -y update
          dnf install -y gcc make diffutils glibc-gconv-extra

      - name: Install dependencies on Amazon Linux 2023
        if: inputs.os == 'amazonlinux:2023'
        run: |
          dnf -y update
          dnf install -y gcc make diffutils tar gzip

      - name: Install Java
        if: inputs.os == 'amazonlinux:2023'
        run: |
          dnf install -y java-11-amazon-corretto-devel

      - name: Install opensource COBOL 4J
        run: |
          tar zxf opensourcecobol4j.tar.gz
          mv opensourcecobol4j/* .
          make install

      - name: Run tests cobj-api
        run:
          make test-cobj-api
