Skip to content

Commit 4585e72

Browse files
committed
chore: audit api spec with vacuum
Ticket: DX-2457
1 parent 031e5b1 commit 4585e72

File tree

2 files changed

+473
-0
lines changed

2 files changed

+473
-0
lines changed

.github/workflows/pull_request.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,66 @@ jobs:
4141
VCS_REF=${{ github.sha }}
4242
cache-from: type=gha
4343
cache-to: type=gha,mode=max
44+
45+
audit-api-spec:
46+
runs-on: ubuntu-latest
47+
48+
steps:
49+
- name: Checkout PR
50+
uses: actions/checkout@v4
51+
with:
52+
ref: ${{ github.event.pull_request.head.sha }}
53+
54+
- name: Setup Node.js
55+
uses: actions/setup-node@v4
56+
with:
57+
node-version: 22
58+
- name: Install Dependencies
59+
run: npm ci
60+
- name: Install OpenAPI Generator at root
61+
run: npm install @api-ts/openapi-generator@v5
62+
63+
- name: Download and install vacuum v0.18.1
64+
run: |
65+
curl -L \
66+
--output vacuum.tar.gz \
67+
--silent \
68+
--show-error \
69+
--fail \
70+
https://github.com/daveshanley/vacuum/releases/download/v0.18.1/vacuum_0.18.1_linux_x86_64.tar.gz
71+
tar -xzf vacuum.tar.gz
72+
chmod u+x vacuum
73+
sudo mv vacuum /usr/local/bin/
74+
vacuum version
75+
76+
- name: Generate API spec
77+
run: |
78+
./node_modules/.bin/openapi-generator \
79+
src/masterBitgoExpress/routers/index.ts \
80+
> api-generated.json
81+
82+
- name: Audit with Vacuum
83+
run: |
84+
85+
vacuum report \
86+
--no-style \
87+
--stdout \
88+
--ruleset ruleset.yaml \
89+
api-generated.json > vacuum-report.json
90+
91+
jq '.resultSet.results // []' vacuum-report.json > vacuum-results.json
92+
93+
ERROR_COUNT=$(jq '[.[] | select(.ruleSeverity == "error")] | length' vacuum-results.json)
94+
WARNING_COUNT=$(jq '[.[] | select(.ruleSeverity == "warn")] | length' vacuum-results.json)
95+
96+
echo "Found $ERROR_COUNT error(s) and $WARNING_COUNT warning(s)"
97+
98+
if [ "$ERROR_COUNT" -gt 0 ]; then
99+
echo "API specification audit failed with $ERROR_COUNT error(s)"
100+
echo ""
101+
echo "Errors:"
102+
jq -r '.[] | select(.ruleSeverity == "error") | " - [\(.ruleId)] \(.message) at \(.path)"' vacuum-results.json
103+
exit 1
104+
else
105+
echo "API specification audit passed!"
106+
fi

0 commit comments

Comments
 (0)