
name: Test

on:
  push:
    tags:
      - v*
    branches:
      - main
  pull_request:

jobs:
  test:
    if: ${{ ! github.event.pull_request.head.repo.fork }}
    runs-on: ubuntu-latest
    permissions:
      actions: 'read'
      contents: 'read'
      id-token: 'write'
    steps:
    - name: Install Go
      uses: actions/setup-go@v4
      with:
        go-version: '1.20'
    - name: Checkout code
      uses: actions/checkout@v3
    - id: 'auth'
      uses: 'google-github-actions/auth@v1'
      with:
        workload_identity_provider: 'projects/811013774421/locations/global/workloadIdentityPools/github-pool/providers/github-provider'
        service_account: 'github-ci-external@trufflehog-testing.iam.gserviceaccount.com'
    - name: Test
      run: make test-integration
  test-detectors:
    if: ${{ ! github.event.pull_request.head.repo.fork }}
    runs-on: ubuntu-latest
    permissions:
      actions: 'read'
      contents: 'read'
      id-token: 'write'
    steps:
    - name: Install Go
      uses: actions/setup-go@v4
      with:
        go-version: '1.20'
    - name: Checkout code
      uses: actions/checkout@v3
    - id: 'auth'
      uses: 'google-github-actions/auth@v1'
      with:
        workload_identity_provider: 'projects/811013774421/locations/global/workloadIdentityPools/github-pool/providers/github-provider'
        service_account: 'github-ci-external@trufflehog-testing.iam.gserviceaccount.com'
    - name: Test
      run: make test-detectors
      continue-on-error: true  
  test-fork:
    if: ${{ github.event.pull_request.head.repo.fork }}
    runs-on: ubuntu-latest
    permissions:
      actions: 'read'
      contents: 'read'
    steps:
    - name: Install Go
      uses: actions/setup-go@v4
      with:
        go-version: '1.20'
    - name: Checkout code
      uses: actions/checkout@v3
    - name: Test
      run: make test-forks
