Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,73 @@ jobs:
VCS_REF=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max

audit-api-spec:
Comment thread
starfy84 marked this conversation as resolved.
name: Audit API Spec
runs-on: ubuntu-latest

steps:
- name: Checkout PR
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
Comment thread
starfy84 marked this conversation as resolved.
- name: Cache npm dependencies
id: node-modules-cache
uses: actions/cache@v4
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-modules-
- name: Install Dependencies
Comment thread
starfy84 marked this conversation as resolved.
if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: npm ci

- name: Download and install vacuum v0.18.1
run: |
curl -L \
--output vacuum.tar.gz \
--silent \
--show-error \
--fail \
https://github.com/daveshanley/vacuum/releases/download/v0.18.1/vacuum_0.18.1_linux_x86_64.tar.gz
tar -xzf vacuum.tar.gz
chmod u+x vacuum
sudo mv vacuum /usr/local/bin/
vacuum version
Comment thread
starfy84 marked this conversation as resolved.

- name: Generate API spec
run: |
./node_modules/.bin/openapi-generator \
src/masterBitgoExpress/routers/index.ts \
> api-generated.json
Comment thread
starfy84 marked this conversation as resolved.
Comment thread
starfy84 marked this conversation as resolved.

- name: Audit with Vacuum
run: |
vacuum report \
--no-style \
--stdout \
--ruleset ruleset.yaml \
api-generated.json > vacuum-report.json

jq '.resultSet.results // []' vacuum-report.json > vacuum-results.json

ERROR_COUNT=$(jq '[.[] | select(.ruleSeverity == "error")] | length' vacuum-results.json)
WARNING_COUNT=$(jq '[.[] | select(.ruleSeverity == "warn")] | length' vacuum-results.json)

echo "Found $ERROR_COUNT error(s) and $WARNING_COUNT warning(s)"

if [ "$ERROR_COUNT" -gt 0 ]; then
echo "API specification audit failed with $ERROR_COUNT error(s)"
echo ""
echo "Errors:"
jq -r '.[] | select(.ruleSeverity == "error") | " - [\(.ruleId)] \(.message) at \(.path)"' vacuum-results.json
exit 1
else
echo "API specification audit passed!"
fi
Loading