106 lines
2.9 KiB
YAML
106 lines
2.9 KiB
YAML
# Azure DevOps Pipeline for C++ Linter Template
|
|
trigger:
|
|
branches:
|
|
include:
|
|
- main
|
|
- develop
|
|
|
|
pr:
|
|
branches:
|
|
include:
|
|
- main
|
|
- develop
|
|
|
|
pool:
|
|
vmImage: 'ubuntu-latest'
|
|
|
|
variables:
|
|
buildConfiguration: 'Debug'
|
|
|
|
stages:
|
|
- stage: LintAndBuild
|
|
displayName: 'Lint and Build'
|
|
jobs:
|
|
- job: StaticAnalysis
|
|
displayName: 'Static Analysis with clang-tidy'
|
|
steps:
|
|
- task: Bash@3
|
|
displayName: 'Install Dependencies'
|
|
inputs:
|
|
targetType: 'inline'
|
|
script: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y clang-tidy clang-format cmake build-essential
|
|
clang-tidy --version
|
|
|
|
- task: Bash@3
|
|
displayName: 'Check Code Format'
|
|
inputs:
|
|
targetType: 'inline'
|
|
script: |
|
|
echo "Checking code format..."
|
|
find src tests -name "*.cpp" -o -name "*.h" | xargs clang-format --dry-run --Werror
|
|
|
|
- task: Bash@3
|
|
displayName: 'Run clang-tidy on all files'
|
|
inputs:
|
|
targetType: 'inline'
|
|
script: |
|
|
echo "Running clang-tidy..."
|
|
find src tests -name "*.cpp" -o -name "*.h" | xargs clang-tidy --config-file=.clang-tidy
|
|
|
|
# 階段一:只顯示警告,不中斷 CI
|
|
echo "Linter completed. Review warnings above."
|
|
|
|
- task: Bash@3
|
|
displayName: 'Build Project'
|
|
inputs:
|
|
targetType: 'inline'
|
|
script: |
|
|
mkdir build
|
|
cd build
|
|
cmake .. -DCMAKE_BUILD_TYPE=${{ variables.buildConfiguration }}
|
|
make -j$(nproc)
|
|
|
|
- task: Bash@3
|
|
displayName: 'Run Tests'
|
|
inputs:
|
|
targetType: 'inline'
|
|
script: |
|
|
cd build
|
|
./tests
|
|
./main
|
|
|
|
- job: PRAnalysis
|
|
displayName: 'PR Changed Files Analysis'
|
|
condition: eq(variables['Build.Reason'], 'PullRequest')
|
|
steps:
|
|
- task: Bash@3
|
|
displayName: 'Install Dependencies'
|
|
inputs:
|
|
targetType: 'inline'
|
|
script: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y clang-tidy
|
|
|
|
- task: Bash@3
|
|
displayName: 'Analyze Changed Files Only'
|
|
inputs:
|
|
targetType: 'inline'
|
|
script: |
|
|
echo "Analyzing only changed files in PR..."
|
|
|
|
# 取得變更的檔案
|
|
git fetch origin $(System.PullRequest.TargetBranch)
|
|
CHANGED_FILES=$(git diff origin/$(System.PullRequest.TargetBranch)...HEAD --name-only | grep -E '\.(cpp|cxx|cc|c\+\+|h|hpp|hxx)$' || true)
|
|
|
|
if [ -z "$CHANGED_FILES" ]; then
|
|
echo "No C++ files changed in this PR"
|
|
exit 0
|
|
fi
|
|
|
|
echo "Changed C++ files:"
|
|
echo "$CHANGED_FILES"
|
|
|
|
echo "Running clang-tidy on changed files..."
|
|
echo "$CHANGED_FILES" | xargs clang-tidy --config-file=.clang-tidy -- -std=c++98 |