|
| 1 | +# Run AI-SAST in YOUR repo on YOUR runners. Your code never runs on ai-sast infrastructure. |
| 2 | +# |
| 3 | +# Required: copy this file as .github/workflows/ai-sast.yml, add secrets: |
| 4 | +# GOOGLE_CLOUD_PROJECT, GOOGLE_CREDENTIALS |
| 5 | +# Default: checks out rivian/ai-sast. Optional: set AI_SAST_REPO (e.g. for a fork); |
| 6 | +# AI_SAST_BASE_BRANCH (default: main); AI_SAST_REF (default: main); runs-on for self-hosted. |
| 7 | + |
| 8 | +name: AI-SAST |
| 9 | + |
| 10 | +on: |
| 11 | + pull_request: |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + pull-requests: write |
| 17 | + |
| 18 | +jobs: |
| 19 | + ai-sast: |
| 20 | + if: github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && (github.base_ref == vars.AI_SAST_BASE_BRANCH || (vars.AI_SAST_BASE_BRANCH == '' && github.base_ref == 'main'))) |
| 21 | + runs-on: ubuntu-latest |
| 22 | + continue-on-error: true |
| 23 | + |
| 24 | + env: |
| 25 | + GOOGLE_CLOUD_PROJECT: ${{ secrets.GOOGLE_CLOUD_PROJECT }} |
| 26 | + GOOGLE_LOCATION: us-central1 |
| 27 | + GEMINI_MODEL: ${{ vars.GEMINI_MODEL || 'gemini-2.0-flash-exp' }} |
| 28 | + AI_SAST_SEVERITY: ${{ vars.AI_SAST_SEVERITY || 'critical,high' }} |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Checkout repository |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + fetch-depth: 0 |
| 35 | + |
| 36 | + - name: Checkout AI-SAST |
| 37 | + uses: actions/checkout@v4 |
| 38 | + with: |
| 39 | + repository: ${{ vars.AI_SAST_REPO || 'rivian/ai-sast' }} |
| 40 | + path: ai-sast |
| 41 | + ref: ${{ vars.AI_SAST_REF || 'main' }} |
| 42 | + |
| 43 | + - name: Set up Python 3.12 |
| 44 | + uses: actions/setup-python@v5 |
| 45 | + with: |
| 46 | + python-version: '3.12' |
| 47 | + |
| 48 | + - name: Install dependencies |
| 49 | + run: pip install --upgrade pip && pip install -r ai-sast/requirements.txt |
| 50 | + |
| 51 | + - name: Authenticate to Google Cloud |
| 52 | + uses: google-github-actions/auth@v2 |
| 53 | + with: |
| 54 | + credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }} |
| 55 | + |
| 56 | + - name: Run AI-SAST PR Scan |
| 57 | + if: github.event_name == 'pull_request' |
| 58 | + id: scan |
| 59 | + run: PYTHONPATH=${{ github.workspace }}/ai-sast python -m src.main.pr_scan |
| 60 | + env: |
| 61 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 62 | + |
| 63 | + - name: Run AI-SAST Full Scan |
| 64 | + if: github.event_name == 'workflow_dispatch' |
| 65 | + id: scan |
| 66 | + run: PYTHONPATH=${{ github.workspace }}/ai-sast python -m src.main.full_scan --max-workers 1 |
| 67 | + env: |
| 68 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 69 | + |
| 70 | + - name: Post PR Comment with Results |
| 71 | + if: always() && github.event_name == 'pull_request' && steps.scan.outcome != 'skipped' |
| 72 | + uses: actions/github-script@v7 |
| 73 | + with: |
| 74 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + script: | |
| 76 | + const fs = require('fs'); |
| 77 | + if (!fs.existsSync('pr_comment.md')) { |
| 78 | + console.log('No pr_comment.md found'); |
| 79 | + return; |
| 80 | + } |
| 81 | + const report = fs.readFileSync('pr_comment.md', 'utf8'); |
| 82 | + if (!report || !report.trim()) { |
| 83 | + console.log('pr_comment.md is empty'); |
| 84 | + return; |
| 85 | + } |
| 86 | + await github.rest.issues.createComment({ |
| 87 | + owner: context.repo.owner, |
| 88 | + repo: context.repo.repo, |
| 89 | + issue_number: context.issue.number, |
| 90 | + body: report |
| 91 | + }); |
| 92 | + console.log('PR comment posted'); |
| 93 | +
|
| 94 | + - name: Upload PR scan reports |
| 95 | + if: always() && github.event_name == 'pull_request' |
| 96 | + uses: actions/upload-artifact@v4 |
| 97 | + with: |
| 98 | + name: ai-sast-pr-scan-reports |
| 99 | + path: | |
| 100 | + ai_sast_pr_scan_report_*.html |
| 101 | + pr_comment.md |
| 102 | + retention-days: 30 |
| 103 | + |
| 104 | + - name: Upload full scan reports |
| 105 | + if: always() && github.event_name == 'workflow_dispatch' |
| 106 | + uses: actions/upload-artifact@v4 |
| 107 | + with: |
| 108 | + name: ai-sast-full-scan-report |
| 109 | + path: | |
| 110 | + ai_sast_full_scan_report_*.html |
| 111 | + ai_sast_full_scan_report_*.txt |
| 112 | + retention-days: 30 |
0 commit comments