name: a-pr-scanner
permissions:
  contents: read
  checks: read
  actions: read
  packages: read
  pull-requests: read
on:
  workflow_call:
    inputs:
      RELEASE:
        description: 'release'
        required: true
        type: string
      CLIENT:
        description: 'Client name'
        required: true
        type: string
      UNIT_TESTS_PATH:
        required: false
        type: string
        default: "./..."
      GO111MODULE:
        required: true
        type: string
      CGO_ENABLED:
        type: number
        default: 1
jobs:
  unit-tests:
    if: ${{ github.actor != 'kubescape' }}
    name: Create cross-platform build
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    runs-on: ubuntu-large
    steps:

      - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
        with:
          fetch-depth: 0

      - uses: actions/setup-go@7b8cf10d4e4a01d4992d18a89f4d7dc5a3e6d6f4 # v4.3.0
        name: Installing go
        with:
          go-version-file: go.mod

      - name: Test core pkg
        run: ${{ env.DOCKER_CMD }} go test -v ./...
        if: startsWith(github.ref, 'refs/tags')

      - name: Test httphandler pkg
        run: ${{ env.DOCKER_CMD }} sh -c 'cd httphandler && go test -v ./...'
        if: startsWith(github.ref, 'refs/tags')

      - uses: anchore/sbom-action/download-syft@e22c389904149dbc22b58101806040fa8d37a610 # v0.24.0
        name: Setup Syft

      - uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
        name: Build
        with:
          distribution: goreleaser
          version: latest
          args: build --clean --snapshot --single-target
        env:
          RELEASE: ${{ inputs.RELEASE }}
          CLIENT: ${{ inputs.CLIENT }}
          CGO_ENABLED: ${{ inputs.CGO_ENABLED }}

      - name: Smoke Testing
        env:
          RELEASE: ${{ inputs.RELEASE }}
          KUBESCAPE_SKIP_UPDATE_CHECK: "true"
        run: ${{ env.DOCKER_CMD }} python3 smoke_testing/init.py ${PWD}/dist/cli_linux_amd64_v1/kubescape

      - name: golangci-lint
        continue-on-error: false
        uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
        with:
          args: --timeout 10m
          only-new-issues: true
