-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
138 lines (125 loc) · 4.75 KB
/
Copy pathaction.yml
File metadata and controls
138 lines (125 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: "Schemap CI/CD AI Quality Gate"
description: "Evaluates database schema AI readiness, prevents breaking mutations, and provides PR impact summaries."
author: "Schemap AI"
branding:
icon: "shield"
color: "blue"
inputs:
config:
description: "Path to schemap.yaml configuration file"
required: false
default: "schemap.yaml"
min-score:
description: "Minimum AI readiness score required to pass gate (0-100)"
required: false
default: "80"
fail-on-breaking:
description: "Fail the workflow if breaking schema changes (dropped columns/tables) are detected"
required: false
default: "true"
output-report:
description: "Path to output the markdown PR Quality Report"
required: false
default: "pr-report.md"
license-key:
description: "Schemap Team/Enterprise license key (or set SCHEMAP_LICENSE_KEY secret)"
required: false
default: ""
github-token:
description: "GitHub token (e.g. secrets.GITHUB_TOKEN) for posting PR comments"
required: false
default: ""
comment-on-pr:
description: "Whether to post/update the quality scorecard as a Pull Request comment"
required: false
default: "true"
outputs:
score:
description: "Evaluated AI readiness score (0-100)"
value: ${{ steps.run-gate.outputs.score }}
passed:
description: "Whether the database schema passed all quality thresholds (true/false)"
value: ${{ steps.run-gate.outputs.passed }}
report-path:
description: "Path to the generated markdown report"
value: ${{ inputs.output-report }}
runs:
using: "composite"
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Schemap CLI
shell: bash
run: |
python -m pip install --upgrade pip
pip install schemap-tool
- name: Run Schemap AI Quality Gate
id: run-gate
shell: bash
env:
SCHEMAP_LICENSE_KEY: ${{ inputs.license-key || env.SCHEMAP_LICENSE_KEY }}
CI: "true"
run: |
EXTRA_FLAGS=""
if [ "${{ inputs.fail-on-breaking }}" = "true" ]; then
EXTRA_FLAGS="--fail-on-breaking"
fi
# 1. Run gate in JSON mode to capture programmatic outputs
schemap gate \
--config "${{ inputs.config }}" \
--min-score "${{ inputs.min-score }}" \
--output-report "${{ inputs.output-report }}" \
--step-summary \
--json \
$EXTRA_FLAGS > gate_output.json || true
# 2. Extract score and status for workflow outputs
SCORE=$(python -c 'import json, sys; sys.stdout.write(str(json.load(open("gate_output.json")).get("score", 0)))' 2>/dev/null || echo "0")
PASSED=$(python -c 'import json, sys; sys.stdout.write("true" if json.load(open("gate_output.json")).get("passed") else "false")' 2>/dev/null || echo "false")
echo "score=$SCORE" >> "$GITHUB_OUTPUT"
echo "passed=$PASSED" >> "$GITHUB_OUTPUT"
# 3. Print human-readable summary to console and enforce exit code
schemap gate \
--config "${{ inputs.config }}" \
--min-score "${{ inputs.min-score }}" \
--step-summary \
$EXTRA_FLAGS
- name: Post PR Comment
if: inputs.comment-on-pr == 'true' && inputs.github-token != '' && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
github-token: ${{ inputs.github-token }}
script: |
const fs = require('fs');
const reportPath = '${{ inputs.output-report }}';
if (!fs.existsSync(reportPath)) {
console.log('No report file found at ' + reportPath);
return;
}
const reportBody = fs.readFileSync(reportPath, 'utf8');
const marker = '<!-- schemap-gate-report -->';
const fullComment = `${marker}\n${reportBody}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body && c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: fullComment,
});
console.log('Updated existing Schemap PR comment.');
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: fullComment,
});
console.log('Created new Schemap PR comment.');
}