name: CodeQL

on:
  pull_request:
    branches: [ "main" ]
  schedule:
    - cron: "22 2 * * 1"

permissions:
  actions: read
  contents: read
  security-events: write

jobs:
  analyze-swift:
    name: Analyze (swift)
    runs-on: macos-latest
    timeout-minutes: 120

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Initialize CodeQL
        uses: github/codeql-action/init@v3
        with:
          languages: swift
          build-mode: manual

      - name: Build Swift project (manual)
        run: |
          set -euo pipefail
          xcodebuild \
            -project "Neon Vision Editor.xcodeproj" \
            -scheme "Neon Vision Editor" \
            -destination "generic/platform=macOS" \
            CODE_SIGNING_ALLOWED=NO \
            CODE_SIGNING_REQUIRED=NO \
            CODE_SIGN_IDENTITY="" \
            build

      - name: Perform CodeQL analysis
        uses: github/codeql-action/analyze@v3

  analyze-other:
    name: Analyze (${{ matrix.language }})
    runs-on: ubuntu-latest
    timeout-minutes: 60
    strategy:
      fail-fast: false
      matrix:
        language: [ "actions", "python", "ruby" ]

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Initialize CodeQL
        uses: github/codeql-action/init@v3
        with:
          languages: ${{ matrix.language }}

      - name: Autobuild
        uses: github/codeql-action/autobuild@v3

      - name: Perform CodeQL analysis
        uses: github/codeql-action/analyze@v3
