name: CodeQL Analysis

permissions:
  contents: read
  security-events: write

on:
  push:
    branches: main
  pull_request:
    branches: main
  schedule:
    - cron: 30 23 * * 06
  workflow_dispatch:

jobs:
  analyze:
    name: Analyze
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        language:
          - go
    steps:
      - name: Checkout Repository
        uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
      - name: Setup Go
        uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
        with:
          go-version-file: go.mod
          cache: false
      - name: Initialize CodeQL
        uses: github/codeql-action/init@c4fb451437765abf5018c6fbf22cce1a7da1e5cc # codeql-bundle-v2.17.1
        with:
          languages: "${{ matrix.language }}"
          tools: latest
      - name: Build
        # Used instead of codeql-action/autobuild.
        run: |
          echo "Building govmomi..." && go build ./ > /dev/null 2>&1 || { echo "error building govmomi"; exit 1; }
          echo "Building govc..." && (cd govc && make clean > /dev/null 2>&1 && make all > /dev/null 2>&1) || { echo "error building govc"; exit 1; }
          echo "Building vcsim..." && (cd vcsim && make clean > /dev/null 2>&1 && make all > /dev/null 2>&1) || { echo "error building vcsim"; exit 1; }
      - name: Perform CodeQL Analysis
        uses: github/codeql-action/analyze@c4fb451437765abf5018c6fbf22cce1a7da1e5cc # codeql-bundle-v2.17.1
