Skip to content

Commit e88f439

Browse files
committed
chore: audit api spec with vacuum
Ticket: DX-2457
1 parent 746cfa4 commit e88f439

File tree

2 files changed

+478
-0
lines changed

2 files changed

+478
-0
lines changed

.github/workflows/pull_request.yaml

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

0 commit comments

Comments
 (0)