name: System Tests

on:
  pull_request:
  merge_group:
  push:
    branches:
      - main

permissions:
  contents: read

concurrency:
  group: ci-${{ github.ref }}-system-tests
  cancel-in-progress: true

jobs:
  setup:
    runs-on: depot-ubuntu-22.04-4
    outputs:
      git_diff: ${{ steps.git_diff.outputs.diff }}
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-tags: true

      - uses: actions/setup-go@v7
        with:
          go-version-file: "go.mod"
          cache: true
          cache-dependency-path: |
            ./go.sum
            **/go.mod
            **/go.sum
            **/Makefile
            Makefile

      - uses: technote-space/get-diff-action@v6.1.2
        id: git_diff
        with:
          # Core Go code, go.mod, Makefile; exclude non-core (workflow passes when skipped)
          PATTERNS: |
            **/*.go
            go.mod
            go.sum
            **/go.mod
            **/go.sum
            **/Makefile
            Makefile

  test-sdk-system:
    needs: setup
    if: needs.setup.outputs.git_diff
    runs-on: depot-ubuntu-22.04-4
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - uses: actions/setup-go@v7
        with:
          go-version-file: "go.mod"
          cache: true
          cache-dependency-path: go.sum

      - name: Run SDK system tests
        run: make test-sdk-system

      - name: Upload system test logs if failed
        if: failure()
        uses: actions/upload-artifact@v6
        with:
          name: system-test-logs
          path: ./tests/systemtests/testnet/*.out
          if-no-files-found: ignore

  test-poa-system:
    runs-on: depot-ubuntu-22.04-4
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-go@v7
        with:
          go-version-file: "go.mod"
          cache: true
          cache-dependency-path: enterprise/poa/go.sum
      - uses: technote-space/get-diff-action@v6.1.2
        id: git_diff
        with:
          PATTERNS: |
            enterprise/poa/**/*.go
            enterprise/poa/go.mod
            enterprise/poa/go.sum
      - name: system tests
        if: env.GIT_DIFF
        run: |
          cd enterprise/poa
          make test-system

  test-group-system:
    runs-on: depot-ubuntu-22.04-4
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-go@v7
        with:
          go-version-file: "go.mod"
          cache: true
          cache-dependency-path: enterprise/group/go.sum
      - uses: technote-space/get-diff-action@v6.1.2
        id: git_diff
        with:
          PATTERNS: |
            enterprise/group/**/*.go
            enterprise/group/go.mod
            enterprise/group/go.sum
      - name: system tests
        if: env.GIT_DIFF
        run: |
          cd enterprise/group
          make test-system

