name: Build and Test PR
on: [pull_request, workflow_dispatch]
jobs:
  build-test:
    runs-on: ubuntu-latest
    env:
      VC_HTTP_API_AUTH_TOKEN: ${{secrets.VC_HTTP_API_AUTH_TOKEN}}
    services:
      postgres:
        image: postgres:10.10
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: test123
        ports:
          - 5432:5432
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: pnpm/action-setup@v2
        with:
          version: 8
      - name: Use Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '18.x'
          cache: 'pnpm'
      - name: setup npmrc
        run: |
          echo "link-workspace-packages=deep" >> .npmrc
          echo "prefer-workspace-packages=true" >> .npmrc
      - run: git diff -u
      - run: pnpm install --frozen-lockfile
      - run: pnpm build
      - name: run CI tests
        env:
          INCLUDE_POSTGRES_TESTS: true
          POSTGRES_HOST: localhost
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: test123
          POSTGRES_PORT: 5432
          SPHEREON_SSI_MSAL_TENANT_ID: ${{ secrets.SPHEREON_SSI_MSAL_TENANT_ID }}
          SPHEREON_SSI_MSAL_CLIENT_ID: ${{ secrets.SPHEREON_SSI_MSAL_CLIENT_ID }}
          SPHEREON_SSI_MSAL_CLIENT_SECRET: ${{ secrets.SPHEREON_SSI_MSAL_CLIENT_SECRET }}
          SPHEREON_SSI_MSAL_USERNAME: ${{ secrets.SPHEREON_SSI_MSAL_USERNAME }}
          SPHEREON_SSI_MSAL_PASSWORD: ${{ secrets.SPHEREON_SSI_MSAL_PASSWORD }}
        run: pnpm test:ci
      - run: npx codecov