
name: IRAF CI test

on: [push, pull_request]

jobs:
  tests:
    name: ${{ matrix.name }}
    runs-on: ${{ matrix.os }}
    env:
      CFLAGS: ${{ matrix.cflags }}
      LDFLAGS: ${{ matrix.ldflags }}

    strategy:
      matrix:
        include:
          - name: Ubuntu latest x86_64
            os: ubuntu-latest
            cflags: -O2 -g -Wall -Wno-stringop-truncation -Wno-unused-result -Wno-format-overflow -Wno-parentheses

          - name: Ubuntu 22.04 Focal i386
            os: ubuntu-22.04
            irafarch: linux
            ldflags: -m32
            cflags: -m32 -O2 -g -Wall -Wno-stringop-truncation -Wno-unused-result -Wno-format-overflow -Wno-parentheses

          - name: macOS 15 Sequoia arm64
            os: macos-15
            cflags: -O2 -g -Wall -Wno-logical-op-parentheses

          - name: macOS 13 Ventura x86_64
            os: macos-13
            cflags: -O1 -g -Wall -Wno-logical-op-parentheses -arch x86_64
            ldflags: -arch x86_64

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup dependencies on Ubuntu
        if: startsWith(matrix.os, 'ubuntu')
        run: |
          if [ ${LDFLAGS} == '-m32' ] ; then
            sudo dpkg --add-architecture i386
            sudo apt-get update -y
            sudo apt-get install -y gcc-multilib libcurl4-openssl-dev:i386 libexpat1-dev:i386 libreadline-dev:i386 zlib1g-dev:i386
          else
            sudo apt-get update -y
            sudo apt-get install -y build-essential libcurl4-openssl-dev libexpat1-dev libreadline-dev zlib1g-dev
          fi

      - name: Build IRAF
        run: |
          if [ "${{ matrix.irafarch }}" ] ; then export IRAFARCH=${{ matrix.irafarch }}; fi
          make

      - name: Run tests
        run: |
         make test

      - name: Installation test
        run: |
          sudo make install
          /usr/local/lib/iraf/test/run_tests /usr/local/lib/iraf/test/noao.astutil.md
          cd pkg/images
          xc -d -c x_images.x
