# Validate on Ubuntu.
name: Ubuntu

on:
  workflow_call:

env:
  GITHUB_REPO: pmem/pmdk
  DOCKER_REPO: ghcr.io/pmem/pmdk

jobs:
  linux:
    name: Linux
    runs-on: ubuntu-latest
    env:
      HOST_WORKDIR:    /home/runner/work/pmdk/pmdk
      WORKDIR:         utils/docker
      PMDK_CC:         gcc
      PMDK_CXX:        g++
      MAKE_PKG:        0
      SRC_CHECKERS:    0
      OS:              ubuntu
      OS_VER:          22.04
      FAULT_INJECTION: 1
    strategy:
      matrix:
        TEST_BUILD: ['debug', 'nondebug']
    steps:
      - name: Clone the git repo
        uses: actions/checkout@v4
        with:
          fetch-depth: 50

      - name: Get system information
        run: ./$WORKDIR/get-system-info.sh

      - name: Pull the image
        run: cd $WORKDIR && ./pull-or-rebuild-image.sh

      - name: Run the build
        env:
          TEST_BUILD: ${{ matrix.TEST_BUILD }}
        run: cd $WORKDIR && ./build-CI.sh
        continue-on-error: true
        id: build

      - name: Archive logs
        if: steps.build.outcome != 'success'
        uses: actions/upload-artifact@v4.2.0
        with:
          name: logs-${{ matrix.TEST_BUILD }}
          path: ${{env.HOST_WORKDIR}}/src/test/**/*.log

      - name: Exit code
        run: |
          [ "${{steps.build.outcome}}" != "success" ] && exit 1
          exit 0
