# MegaLinter Azure Pipelines configuration file
# More info at https://megalinter.io
---
trigger:
  - main

pool:
  vmImage: ubuntu-latest

variables:
  # All available variables are described in documentation
  # https://megalinter.io/latest/config-file/
  DEFAULT_WORKSPACE: $(System.DefaultWorkingDirectory)

  # Disable LLM Advisor for bot PRs (dependabot, renovate, etc.)
  # Note: Azure Pipelines has limited access to PR author info, this is a basic check
  LLM_ADVISOR_ENABLED: >-
    ${{ not(or(
      contains(variables['Build.SourceBranch'], 'dependabot'),
      contains(variables['Build.SourceBranch'], 'renovate'),
      contains(variables['System.PullRequest.SourceBranch'], 'dependabot'),
      contains(variables['System.PullRequest.SourceBranch'], 'renovate'),
      startsWith(variables['Build.RequestedFor'], 'dependabot'),
      startsWith(variables['Build.RequestedFor'], 'renovate')
    )) }}

steps:
  # Checkout repo
  - checkout: self

  # Pull MegaLinter docker image
  - script: docker pull <%= DOCKER_IMAGE_NAME %>:<%= DOCKER_IMAGE_VERSION %>
    displayName: Pull MegaLinter

  # Run MegaLinter
  - script: |
      docker run -v $(System.DefaultWorkingDirectory):/tmp/lint \
        --env-file <(env | grep -e SYSTEM_ -e BUILD_ -e TF_ -e AGENT_) \
        -e SYSTEM_ACCESSTOKEN=$(System.AccessToken) \
        -e GIT_AUTHORIZATION_BEARER=$(System.AccessToken) \
        -e DEFAULT_WORKSPACE=/tmp/lint \
        -e LLM_ADVISOR_ENABLED=$(LLM_ADVISOR_ENABLED) \
        <%= DOCKER_IMAGE_NAME %>:<%= DOCKER_IMAGE_VERSION %>
    displayName: Run MegaLinter

  # Upload MegaLinter reports
  - task: PublishPipelineArtifact@0
    inputs:
      targetPath: megalinter-reports
      artifactName: MegaLinterReports
    condition: always()
