Skip to content

Commit 84a464f

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

File tree

2 files changed

+481
-0
lines changed

2 files changed

+481
-0
lines changed

.github/workflows/pull_request.yaml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,73 @@ 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+
id: node-modules-cache
61+
uses: actions/cache@v4
62+
with:
63+
path: '**/node_modules'
64+
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
65+
restore-keys: |
66+
${{ runner.os }}-modules-
67+
- name: Install Dependencies
68+
if: steps.node-modules-cache.outputs.cache-hit != 'true'
69+
run: npm ci
70+
71+
- name: Download and install vacuum v0.18.1
72+
run: |
73+
curl -L \
74+
--output vacuum.tar.gz \
75+
--silent \
76+
--show-error \
77+
--fail \
78+
https://github.com/daveshanley/vacuum/releases/download/v0.18.1/vacuum_0.18.1_linux_x86_64.tar.gz
79+
tar -xzf vacuum.tar.gz
80+
chmod u+x vacuum
81+
sudo mv vacuum /usr/local/bin/
82+
vacuum version
83+
84+
- name: Generate API spec
85+
run: |
86+
./node_modules/.bin/openapi-generator \
87+
src/masterBitgoExpress/routers/index.ts \
88+
> api-generated.json
89+
90+
- name: Audit with Vacuum
91+
run: |
92+
vacuum report \
93+
--no-style \
94+
--stdout \
95+
--ruleset ruleset.yaml \
96+
api-generated.json > vacuum-report.json
97+
98+
jq '.resultSet.results // []' vacuum-report.json > vacuum-results.json
99+
100+
ERROR_COUNT=$(jq '[.[] | select(.ruleSeverity == "error")] | length' vacuum-results.json)
101+
WARNING_COUNT=$(jq '[.[] | select(.ruleSeverity == "warn")] | length' vacuum-results.json)
102+
103+
echo "Found $ERROR_COUNT error(s) and $WARNING_COUNT warning(s)"
104+
105+
if [ "$ERROR_COUNT" -gt 0 ]; then
106+
echo "API specification audit failed with $ERROR_COUNT error(s)"
107+
echo ""
108+
echo "Errors:"
109+
jq -r '.[] | select(.ruleSeverity == "error") | " - [\(.ruleId)] \(.message) at \(.path)"' vacuum-results.json
110+
exit 1
111+
else
112+
echo "API specification audit passed!"
113+
fi

0 commit comments

Comments
 (0)