|
| 1 | +name: 'VibeGuard' |
| 2 | +description: 'Deterministic pre-merge safety gate for AI-generated code' |
| 3 | +branding: |
| 4 | + icon: shield |
| 5 | + color: blue |
| 6 | + |
| 7 | +inputs: |
| 8 | + path: |
| 9 | + description: 'Directory to scan' |
| 10 | + required: false |
| 11 | + default: '.' |
| 12 | + config: |
| 13 | + description: 'Path to vibeguard.yaml' |
| 14 | + required: false |
| 15 | + default: '' |
| 16 | + diff: |
| 17 | + description: 'Scan only changed files' |
| 18 | + required: false |
| 19 | + default: 'false' |
| 20 | + fail-on: |
| 21 | + description: 'Severity threshold for gate failure (info|low|medium|high|critical)' |
| 22 | + required: false |
| 23 | + default: 'high' |
| 24 | + output-format: |
| 25 | + description: 'Output format: console, json, markdown, sarif, pr-comment' |
| 26 | + required: false |
| 27 | + default: 'console' |
| 28 | + output-file: |
| 29 | + description: 'Write output to this file path' |
| 30 | + required: false |
| 31 | + default: '' |
| 32 | + baseline: |
| 33 | + description: 'Path to baseline file' |
| 34 | + required: false |
| 35 | + default: '' |
| 36 | + python-version: |
| 37 | + description: 'Python version to use' |
| 38 | + required: false |
| 39 | + default: '3.11' |
| 40 | + |
| 41 | +outputs: |
| 42 | + findings-count: |
| 43 | + description: >- |
| 44 | + Total number of findings. Accurate when output-format is json (parsed from |
| 45 | + the JSON payload); otherwise the literal string "unknown". |
| 46 | + value: ${{ steps.scan.outputs.findings-count }} |
| 47 | + blocking-count: |
| 48 | + description: >- |
| 49 | + Number of findings at or above the fail-on threshold. Accurate when |
| 50 | + output-format is json; otherwise "unknown". The boolean gate-passed |
| 51 | + output is always accurate. |
| 52 | + value: ${{ steps.scan.outputs.blocking-count }} |
| 53 | + report-path: |
| 54 | + description: 'Path to the output file (if output-file was set)' |
| 55 | + value: ${{ steps.scan.outputs.report-path }} |
| 56 | + gate-passed: |
| 57 | + description: 'Whether the gate passed (true or false)' |
| 58 | + value: ${{ steps.scan.outputs.gate-passed }} |
| 59 | + |
| 60 | +runs: |
| 61 | + using: composite |
| 62 | + steps: |
| 63 | + - name: Set up Python |
| 64 | + uses: actions/setup-python@v5 |
| 65 | + with: |
| 66 | + python-version: ${{ inputs.python-version }} |
| 67 | + cache: pip |
| 68 | + |
| 69 | + - name: Install VibeGuard |
| 70 | + shell: bash |
| 71 | + # Install from the checked-out action source so the CLI version matches |
| 72 | + # the action ref (e.g. `uses: dgenio/vibeguard@v0.2`). Installing from |
| 73 | + # PyPI here would let the CLI float independently of the action tag, |
| 74 | + # which defeats the point of pinning. |
| 75 | + run: pip install "${{ github.action_path }}" |
| 76 | + |
| 77 | + - name: Run VibeGuard gate |
| 78 | + id: scan |
| 79 | + shell: bash |
| 80 | + # Pipe each input through an intermediate env var rather than inlining |
| 81 | + # `${{ inputs.* }}` into the shell command. See GitHub's security- |
| 82 | + # hardening guidance for composite actions: |
| 83 | + # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable |
| 84 | + env: |
| 85 | + INPUT_PATH: ${{ inputs.path }} |
| 86 | + INPUT_FAIL_ON: ${{ inputs.fail-on }} |
| 87 | + INPUT_DIFF: ${{ inputs.diff }} |
| 88 | + INPUT_CONFIG: ${{ inputs.config }} |
| 89 | + INPUT_BASELINE: ${{ inputs.baseline }} |
| 90 | + INPUT_OUTPUT_FORMAT: ${{ inputs.output-format }} |
| 91 | + INPUT_OUTPUT_FILE: ${{ inputs.output-file }} |
| 92 | + run: | |
| 93 | + set +e |
| 94 | +
|
| 95 | + # Build command using only env vars (quoted) — never inline templating. |
| 96 | + CMD=(vibeguard gate --path "$INPUT_PATH" --fail-on "$INPUT_FAIL_ON") |
| 97 | +
|
| 98 | + if [ "$INPUT_DIFF" = "true" ]; then |
| 99 | + CMD+=(--diff) |
| 100 | + fi |
| 101 | +
|
| 102 | + if [ -n "$INPUT_CONFIG" ]; then |
| 103 | + CMD+=(--config "$INPUT_CONFIG") |
| 104 | + fi |
| 105 | +
|
| 106 | + if [ -n "$INPUT_BASELINE" ]; then |
| 107 | + CMD+=(--baseline "$INPUT_BASELINE") |
| 108 | + fi |
| 109 | +
|
| 110 | + # Output format |
| 111 | + FORMAT="$INPUT_OUTPUT_FORMAT" |
| 112 | + case "$FORMAT" in |
| 113 | + json) CMD+=(--json) ;; |
| 114 | + markdown) CMD+=(--markdown) ;; |
| 115 | + sarif) CMD+=(--sarif) ;; |
| 116 | + pr-comment) CMD+=(--pr-comment) ;; |
| 117 | + esac |
| 118 | +
|
| 119 | + # Run and capture output. Redirect only stdout to OUTPUT_FILE so that |
| 120 | + # warnings on stderr (Git missing, config notices, rich formatting) |
| 121 | + # don't corrupt JSON/SARIF/Markdown reports; stderr flows to the job |
| 122 | + # log instead. |
| 123 | + OUTPUT_FILE="$INPUT_OUTPUT_FILE" |
| 124 | + if [ -n "$OUTPUT_FILE" ]; then |
| 125 | + "${CMD[@]}" > "$OUTPUT_FILE" |
| 126 | + EXIT_CODE=$? |
| 127 | + echo "report-path=$OUTPUT_FILE" >> "$GITHUB_OUTPUT" |
| 128 | + else |
| 129 | + "${CMD[@]}" |
| 130 | + EXIT_CODE=$? |
| 131 | + fi |
| 132 | +
|
| 133 | + # Parse counts from JSON output. We only know real counts when the user |
| 134 | + # asked for json + output-file; for any other format we emit "unknown" |
| 135 | + # rather than lying with a hardcoded zero. gate-passed below remains |
| 136 | + # authoritative regardless. jq is preinstalled on GitHub-hosted runners. |
| 137 | + FINDINGS_COUNT="unknown" |
| 138 | + BLOCKING_COUNT="unknown" |
| 139 | + if [ "$FORMAT" = "json" ] && [ -n "$OUTPUT_FILE" ] && [ -f "$OUTPUT_FILE" ] && command -v jq >/dev/null 2>&1; then |
| 140 | + FC=$(jq '.findings | length' "$OUTPUT_FILE" 2>/dev/null) |
| 141 | + BC=$(jq --arg t "$INPUT_FAIL_ON" ' |
| 142 | + ({info:0,low:1,medium:2,high:3,critical:4}) as $o |
| 143 | + | ($o[$t] // 3) as $thresh |
| 144 | + | [.findings[] | select(($o[(.severity // "info") | ascii_downcase] // 0) >= $thresh)] |
| 145 | + | length |
| 146 | + ' "$OUTPUT_FILE" 2>/dev/null) |
| 147 | + if [ -n "$FC" ]; then FINDINGS_COUNT="$FC"; fi |
| 148 | + if [ -n "$BC" ]; then BLOCKING_COUNT="$BC"; fi |
| 149 | + fi |
| 150 | + echo "findings-count=$FINDINGS_COUNT" >> "$GITHUB_OUTPUT" |
| 151 | + echo "blocking-count=$BLOCKING_COUNT" >> "$GITHUB_OUTPUT" |
| 152 | +
|
| 153 | + if [ $EXIT_CODE -eq 0 ]; then |
| 154 | + echo "gate-passed=true" >> "$GITHUB_OUTPUT" |
| 155 | + else |
| 156 | + echo "gate-passed=false" >> "$GITHUB_OUTPUT" |
| 157 | + fi |
| 158 | +
|
| 159 | + exit $EXIT_CODE |
0 commit comments