-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
219 lines (192 loc) · 7.84 KB
/
action.yml
File metadata and controls
219 lines (192 loc) · 7.84 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
name: 'WireMock OpenAPI Validator'
description: 'Validates WireMock stub mappings against OpenAPI specifications in your PR pipeline'
branding:
icon: 'alert-circle'
color: 'green'
inputs:
openapi-path:
description: 'Path to the OpenAPI specification file (YAML or JSON)'
required: true
wiremock-path:
description: 'Path to the WireMock mappings directory'
required: true
fail-on-warnings:
description: 'Fail the build if warnings are found (default: false)'
required: false
default: 'false'
post-comment:
description: 'Post validation results as a PR comment (default: true)'
required: false
default: 'true'
github-token:
description: 'GitHub token for posting PR comments (default: GITHUB_TOKEN)'
required: false
default: ${{ github.token }}
skip-install:
description: 'Skip tool installation (use when tool is already installed, e.g., for local development)'
required: false
default: 'false'
outputs:
validation-passed:
description: 'Whether all validations passed (true/false)'
value: ${{ steps.validate.outputs.passed }}
total-checks:
description: 'Total number of validation checks'
value: ${{ steps.parse-results.outputs.total }}
passed-checks:
description: 'Number of passed checks'
value: ${{ steps.parse-results.outputs.passed }}
failed-checks:
description: 'Number of failed checks'
value: ${{ steps.parse-results.outputs.failed }}
warning-checks:
description: 'Number of warnings'
value: ${{ steps.parse-results.outputs.warnings }}
error-checks:
description: 'Number of errors'
value: ${{ steps.parse-results.outputs.errors }}
runs:
using: 'composite'
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- name: Install WireMock OpenAPI Validator
if: ${{ inputs.skip-install != 'true' }}
shell: bash
run: dotnet tool install --global Wiremock.OpenAPIValidator || dotnet tool update --global Wiremock.OpenAPIValidator
- name: Run Validation
id: validate
shell: bash
run: |
set +e
wiremockopenapi -o "${{ inputs.openapi-path }}" -w "${{ inputs.wiremock-path }}" --format json --output-file validation-results.json --quiet
EXIT_CODE=$?
set -e
echo "exit-code=$EXIT_CODE" >> $GITHUB_OUTPUT
if [ $EXIT_CODE -eq 0 ]; then
echo "passed=true" >> $GITHUB_OUTPUT
else
echo "passed=false" >> $GITHUB_OUTPUT
fi
- name: Parse Results
id: parse-results
shell: bash
run: |
if [ -f validation-results.json ]; then
TOTAL=$(jq '.summary.total' validation-results.json)
PASSED=$(jq '.summary.passed' validation-results.json)
FAILED=$(jq '.summary.failed' validation-results.json)
WARNINGS=$(jq '.summary.warning' validation-results.json)
ERRORS=$(jq '.summary.error' validation-results.json)
echo "total=$TOTAL" >> $GITHUB_OUTPUT
echo "passed=$PASSED" >> $GITHUB_OUTPUT
echo "failed=$FAILED" >> $GITHUB_OUTPUT
echo "warnings=$WARNINGS" >> $GITHUB_OUTPUT
echo "errors=$ERRORS" >> $GITHUB_OUTPUT
else
echo "Error: validation-results.json not found"
exit 1
fi
- name: Create PR Comment
if: ${{ inputs.post-comment == 'true' && github.event_name == 'pull_request' }}
uses: actions/github-script@v7
with:
github-token: ${{ inputs.github-token }}
script: |
const fs = require('fs');
const results = JSON.parse(fs.readFileSync('validation-results.json', 'utf8'));
const passed = results.summary.passed;
const failed = results.summary.failed;
const warnings = results.summary.warning;
const errors = results.summary.error;
const total = results.summary.total;
const passRate = total > 0 ? ((passed / total) * 100).toFixed(1) : '0';
let statusEmoji = '✅';
let statusText = 'All validations passed!';
if (failed > 0 || errors > 0) {
statusEmoji = '❌';
statusText = 'Validation failures detected';
} else if (warnings > 0) {
statusEmoji = '⚠️';
statusText = 'Validation passed with warnings';
}
let commentBody = `## ${statusEmoji} WireMock OpenAPI Validation Results\n\n`;
commentBody += `**${statusText}**\n\n`;
commentBody += `### Summary\n\n`;
commentBody += `| Metric | Count |\n`;
commentBody += `|--------|-------|\n`;
commentBody += `| Total Checks | ${total} |\n`;
commentBody += `| ✅ Passed | ${passed} |\n`;
commentBody += `| ⚠️ Warnings | ${warnings} |\n`;
commentBody += `| ❌ Failed | ${failed} |\n`;
commentBody += `| 🔴 Errors | ${errors} |\n`;
commentBody += `| **Pass Rate** | **${passRate}%** |\n\n`;
// Add failure/error details if any
if (failed > 0 || errors > 0) {
commentBody += `### ❌ Failures and Errors\n\n`;
const failuresAndErrors = results.results.filter(r =>
r.result === 'Failed' || r.result === 'Error'
);
for (const result of failuresAndErrors.slice(0, 20)) {
const emoji = result.result === 'Failed' ? '❌' : '🔴';
commentBody += `- ${emoji} **${result.name}** (${result.type})\n`;
commentBody += ` > ${result.description}\n\n`;
}
if (failuresAndErrors.length > 20) {
commentBody += `\n_... and ${failuresAndErrors.length - 20} more failures/errors_\n\n`;
}
}
// Add warning details if any (limit to 10)
if (warnings > 0) {
commentBody += `### ⚠️ Warnings\n\n`;
const warningResults = results.results.filter(r => r.result === 'Warning');
for (const result of warningResults.slice(0, 10)) {
commentBody += `- ⚠️ **${result.name}** (${result.type})\n`;
commentBody += ` > ${result.description}\n\n`;
}
if (warningResults.length > 10) {
commentBody += `\n_... and ${warningResults.length - 10} more warnings_\n\n`;
}
}
commentBody += `\n---\n`;
commentBody += `*Generated by [WireMock OpenAPI Validator](https://github.com/Wiremock.OpenAPIValidator)*`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('WireMock OpenAPI Validation Results')
);
// Update or create comment
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});
}
- name: Check Warnings
if: ${{ inputs.fail-on-warnings == 'true' && steps.parse-results.outputs.warnings > 0 }}
shell: bash
run: |
echo "::error::Build failed due to warnings (fail-on-warnings is enabled)"
exit 1
- name: Check Validation Status
if: ${{ steps.validate.outputs.passed == 'false' }}
shell: bash
run: |
echo "::error::WireMock OpenAPI validation failed"
exit 1