name: Linux
on:
  - push
  - pull_request
jobs:
  test:
    name: Test
    strategy:
      fail-fast: false
      matrix:
        service:
          - almalinux-8
          - almalinux-9
          - almalinux-10
          - alpine-linux
          - apache-arrow
          - arch-linux
          - conda
          # - fedora-arm32v7-rawhide
          - fedora-rawhide
          - ruby-3.1
          - ruby-3.2
          - ruby-3.3
          - ruby-3.4
          - ubuntu-22.04
          - ubuntu-24.04
        include:
          - service: apache-arrow
            timeout-minutes: 60
    runs-on: ubuntu-latest
    timeout-minutes: ${{ matrix.timeout-minutes || 15 }}
    steps:
      - uses: actions/checkout@v6
      - uses: docker/login-action@v3
        if: |
          github.event_name == 'push'
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Pull Docker images
        run: |
          docker compose pull --ignore-pull-failures ${{ matrix.service }}-base || :
          docker compose pull --ignore-pull-failures ${{ matrix.service }} || :
      - name: Build Docker image
        run: |
          docker compose build ${{ matrix.service }}
      - name: Push Docker images
        if: |
          github.event_name == 'push'
        run: |
          docker compose push --ignore-push-failures ${{ matrix.service }} || :
      - name: Cache ccache
        if: |
          matrix.service == 'apache-arrow'
        uses: actions/cache@v4
        with:
          path: .ccache
          key: arrow-ccache-docker-${{ matrix.service }}-${{ github.sha }}
          restore-keys: arrow-ccache-docker-${{ matrix.service }}-
      - name: Adjust permission for cache
        if: |
          matrix.service == 'apache-arrow'
        run: |
          mkdir -p .ccache
          chmod -R a+rwx .ccache
      - name: Register problem matchers
        run: |
          echo ::add-matcher::dockerfiles/problem-matchers.json
      - name: Run
        run: |
          docker compose run --rm ${{ matrix.service }}
