@contractspec/app.cli-contractspec 0.0.0-canary-20260113170453
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.contractsrc.example.json +25 -0
- package/AGENTS.md +102 -0
- package/CHANGELOG.md +746 -0
- package/LICENSE +21 -0
- package/README.md +684 -0
- package/contractsrc.schema.json +404 -0
- package/dist/bun/cli.js +52230 -0
- package/dist/node/cli.js +52393 -0
- package/docs/ci-cd.md +598 -0
- package/package.json +80 -0
- package/templates/github-action.yml +117 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
name: ContractSpec CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches: [main, master]
|
|
6
|
+
push:
|
|
7
|
+
branches: [main, master]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
pull-requests: write
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
contractspec:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- name: Checkout
|
|
18
|
+
uses: actions/checkout@v4
|
|
19
|
+
|
|
20
|
+
- name: Setup Node.js
|
|
21
|
+
uses: actions/setup-node@v4
|
|
22
|
+
with:
|
|
23
|
+
node-version: '20'
|
|
24
|
+
|
|
25
|
+
- name: Install dependencies
|
|
26
|
+
run: npm ci
|
|
27
|
+
|
|
28
|
+
- name: Install ContractSpec
|
|
29
|
+
run: npm install -g @contractspec/cli
|
|
30
|
+
|
|
31
|
+
- name: Run ContractSpec CI
|
|
32
|
+
id: ci
|
|
33
|
+
run: |
|
|
34
|
+
contractspec ci --format json --check-drift > contractspec-results.json
|
|
35
|
+
echo "exit_code=$?" >> $GITHUB_OUTPUT
|
|
36
|
+
continue-on-error: true
|
|
37
|
+
|
|
38
|
+
- name: Generate PR Comment
|
|
39
|
+
if: github.event_name == 'pull_request'
|
|
40
|
+
uses: actions/github-script@v7
|
|
41
|
+
with:
|
|
42
|
+
script: |
|
|
43
|
+
const fs = require('fs');
|
|
44
|
+
const results = JSON.parse(fs.readFileSync('contractspec-results.json', 'utf8'));
|
|
45
|
+
|
|
46
|
+
const { schemaVersion, checks, summary, drift } = results;
|
|
47
|
+
|
|
48
|
+
let body = `## ContractSpec CI Results\n\n`;
|
|
49
|
+
|
|
50
|
+
// Summary
|
|
51
|
+
body += `| Metric | Count |\n|--------|-------|\n`;
|
|
52
|
+
body += `| ✅ Pass | ${summary.pass} |\n`;
|
|
53
|
+
body += `| ❌ Fail | ${summary.fail} |\n`;
|
|
54
|
+
body += `| ⚠️ Warn | ${summary.warn} |\n\n`;
|
|
55
|
+
|
|
56
|
+
// Drift status
|
|
57
|
+
if (drift) {
|
|
58
|
+
if (drift.status === 'detected') {
|
|
59
|
+
body += `### ⚠️ Drift Detected\n\n`;
|
|
60
|
+
body += `The following generated files are out of sync:\n`;
|
|
61
|
+
drift.files.forEach(f => body += `- \`${f}\`\n`);
|
|
62
|
+
body += `\nRun \`contractspec generate\` to fix.\n\n`;
|
|
63
|
+
} else {
|
|
64
|
+
body += `### ✅ No Drift Detected\n\n`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Checks
|
|
69
|
+
if (checks && checks.length > 0) {
|
|
70
|
+
const failures = checks.filter(c => c.status === 'fail');
|
|
71
|
+
if (failures.length > 0) {
|
|
72
|
+
body += `### Failed Checks\n\n`;
|
|
73
|
+
failures.forEach(c => {
|
|
74
|
+
body += `- **${c.name}**: ${c.message}\n`;
|
|
75
|
+
});
|
|
76
|
+
body += `\n`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
body += `\n---\n_Generated by ContractSpec v${schemaVersion || '1.0'}_`;
|
|
81
|
+
|
|
82
|
+
// Find existing comment
|
|
83
|
+
const { data: comments } = await github.rest.issues.listComments({
|
|
84
|
+
owner: context.repo.owner,
|
|
85
|
+
repo: context.repo.repo,
|
|
86
|
+
issue_number: context.issue.number,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const botComment = comments.find(c =>
|
|
90
|
+
c.user.type === 'Bot' && c.body.includes('ContractSpec CI Results')
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
if (botComment) {
|
|
94
|
+
await github.rest.issues.updateComment({
|
|
95
|
+
owner: context.repo.owner,
|
|
96
|
+
repo: context.repo.repo,
|
|
97
|
+
comment_id: botComment.id,
|
|
98
|
+
body,
|
|
99
|
+
});
|
|
100
|
+
} else {
|
|
101
|
+
await github.rest.issues.createComment({
|
|
102
|
+
owner: context.repo.owner,
|
|
103
|
+
repo: context.repo.repo,
|
|
104
|
+
issue_number: context.issue.number,
|
|
105
|
+
body,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
- name: Upload Results
|
|
110
|
+
uses: actions/upload-artifact@v4
|
|
111
|
+
with:
|
|
112
|
+
name: contractspec-results
|
|
113
|
+
path: contractspec-results.json
|
|
114
|
+
|
|
115
|
+
- name: Fail if checks failed
|
|
116
|
+
if: steps.ci.outputs.exit_code != '0'
|
|
117
|
+
run: exit 1
|