|
| 1 | +# Azure DevOps Pipeline to upload SARIF files to CodeAnalysisLogs artifact |
| 2 | +# Compatible with SARIF Viewer extension: https://marketplace.visualstudio.com/items?itemName=sariftools.scans |
| 3 | +# This enables viewing security assessment results in the Scans tab |
| 4 | + |
| 5 | +trigger: |
| 6 | + branches: |
| 7 | + include: |
| 8 | + - main |
| 9 | + paths: |
| 10 | + include: |
| 11 | + - docs/sarif/*.sarif |
| 12 | + |
| 13 | +pr: |
| 14 | + branches: |
| 15 | + include: |
| 16 | + - main |
| 17 | + paths: |
| 18 | + include: |
| 19 | + - docs/sarif/*.sarif |
| 20 | + |
| 21 | +pool: |
| 22 | + vmImage: ubuntu-latest |
| 23 | + |
| 24 | +steps: |
| 25 | +- checkout: self |
| 26 | + displayName: 'Checkout repository' |
| 27 | + |
| 28 | +- bash: | |
| 29 | + if [ -d "docs/sarif" ]; then |
| 30 | + SARIF_COUNT=$(find docs/sarif -name "*.sarif" | wc -l) |
| 31 | + echo "##vso[task.setvariable variable=sarifCount]$SARIF_COUNT" |
| 32 | + echo "Found $SARIF_COUNT SARIF file(s)" |
| 33 | + find docs/sarif -name "*.sarif" -exec echo " - {}" \; |
| 34 | + else |
| 35 | + echo "##vso[task.setvariable variable=sarifCount]0" |
| 36 | + echo "No docs/sarif directory found" |
| 37 | + fi |
| 38 | + displayName: 'Check for SARIF files' |
| 39 | + |
| 40 | +- task: UsePythonVersion@0 |
| 41 | + condition: ne(variables['sarifCount'], '0') |
| 42 | + inputs: |
| 43 | + versionSpec: '3.11' |
| 44 | + addToPath: true |
| 45 | + displayName: 'Set up Python' |
| 46 | + |
| 47 | +- bash: | |
| 48 | + # DevOps Shield exports SARIF with non-standard properties and numeric enums |
| 49 | + # Clean SARIF files for better compatibility |
| 50 | + # Using Python script for comprehensive cleaning |
| 51 | + |
| 52 | + for sarif_file in docs/sarif/*.sarif; do |
| 53 | + echo "Cleaning $sarif_file for compatibility..." |
| 54 | + python scripts/Clean-SarifForGitHub.py "$sarif_file" |
| 55 | + echo "✅ Cleaned: $sarif_file" |
| 56 | + |
| 57 | + # Validate basic structure |
| 58 | + if python -c "import json; d=json.load(open('$sarif_file')); assert d['version']=='2.1.0' and d['runs'][0]['tool']['driver']['name']"; then |
| 59 | + echo " Validation: PASSED" |
| 60 | + else |
| 61 | + echo " Validation: WARNING - may have issues" |
| 62 | + fi |
| 63 | + done |
| 64 | + condition: ne(variables['sarifCount'], '0') |
| 65 | + displayName: 'Clean SARIF files for compatibility' |
| 66 | + |
| 67 | +- task: PublishBuildArtifacts@1 |
| 68 | + condition: ne(variables['sarifCount'], '0') |
| 69 | + inputs: |
| 70 | + PathtoPublish: 'docs/sarif' |
| 71 | + ArtifactName: 'CodeAnalysisLogs' |
| 72 | + publishLocation: 'Container' |
| 73 | + displayName: 'Upload SARIF to CodeAnalysisLogs artifact' |
| 74 | + |
| 75 | +- bash: | |
| 76 | + echo "## SARIF Upload Summary" |
| 77 | + echo "" |
| 78 | + echo "✅ Successfully uploaded SARIF files to CodeAnalysisLogs artifact" |
| 79 | + echo "" |
| 80 | + echo "### Files Uploaded" |
| 81 | + find docs/sarif -name "*.sarif" -exec echo "- {}" \; |
| 82 | + echo "" |
| 83 | + echo "### View Results" |
| 84 | + echo "Install the SARIF Viewer extension and navigate to the Scans tab to view results." |
| 85 | + echo "Extension: https://marketplace.visualstudio.com/items?itemName=sariftools.scans" |
| 86 | + condition: ne(variables['sarifCount'], '0') |
| 87 | + displayName: 'Upload summary' |
| 88 | + |
| 89 | +- bash: | |
| 90 | + echo "## SARIF Upload Summary" |
| 91 | + echo "" |
| 92 | + echo "⚠️ No SARIF files found in docs/sarif directory" |
| 93 | + echo "" |
| 94 | + echo "Please ensure SARIF files are present before running this pipeline." |
| 95 | + condition: eq(variables['sarifCount'], '0') |
| 96 | + displayName: 'No SARIF files found' |
0 commit comments