name: Testing PKI build

on: workflow_call

env:
  NAMESPACE: ${{ vars.REGISTRY_NAMESPACE || 'dogtagpki' }}

jobs:
  test:
    name: Test
    runs-on: ubuntu-latest
    env:
      SHARED: /tmp/workdir/jss
    steps:
      - name: Clone repository
        uses: actions/checkout@v4

      - name: Retrieve JSS images
        uses: actions/cache@v4
        with:
          key: jss-images-${{ github.sha }}
          path: jss-images.tar

      - name: Load JSS images
        run: docker load --input jss-images.tar

      - name: Set up JSS container
        run: |
          tests/bin/runner-init.sh \
              --hostname=pki.example.com \
              pki

      - name: Import LDAP SDK packages
        run: |
          docker create --name=ldapjdk-dist quay.io/$NAMESPACE/ldapjdk-dist:5.6
          docker cp ldapjdk-dist:/root/RPMS/. /tmp/RPMS/
          docker rm -f ldapjdk-dist

      - name: Install build dependencies
        run: |
          docker exec pki dnf install -y git rpm-build
          docker exec pki git clone -b v11.9 https://github.com/$NAMESPACE/pki
          docker exec pki dnf builddep -y --skip-unavailable --spec pki/pki.spec
          docker cp /tmp/RPMS/. pki:/root/RPMS/
          docker exec pki bash -c "dnf install -y /root/RPMS/*"

      - name: Build and install PKI
        run: |
          docker exec pki pki/build.sh --with-timestamp --with-commit-id rpm
          docker exec pki bash -c "dnf install -y /root/build/pki/RPMS/*.rpm"
