@@ -368,3 +368,86 @@ jobs:
368368 git diff
369369 exit 1
370370 fi
371+
372+ audit-api-spec :
373+ runs-on : ubuntu-latest
374+
375+ steps :
376+ - name : Checkout PR
377+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
378+ with :
379+ ref : ${{ github.event.pull_request.head.sha }}
380+
381+ - name : Setup Node.js 18
382+ uses : actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
383+ with :
384+ node-version : 22
385+
386+ - name : Restore lerna dependencies
387+ id : lerna-cache
388+ uses : actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
389+ with :
390+ path : |
391+ node_modules
392+ modules/*/node_modules
393+ key : ${{ runner.os }}-node18-${{ hashFiles('yarn.lock') }}-${{ hashFiles('tsconfig.packages.json') }}-${{ hashFiles('**/package.json') }}
394+
395+ - name : Install Packages
396+ if : steps.lerna-cache.outputs.cache-hit != 'true'
397+ run : yarn install --with-frozen-lockfile --ignore-scripts
398+
399+ - name : Build packages
400+ env :
401+ DISABLE_V8_COMPILE_CACHE : ' 1'
402+ run : yarn run postinstall
403+
404+ - name : Install OpenAPI Generator at root
405+ run : yarn add -W @api-ts/openapi-generator@v5
406+
407+ - name : Download and install vacuum v0.18.1
408+ run : |
409+ curl -L \
410+ --output vacuum.tar.gz \
411+ --silent \
412+ --show-error \
413+ --fail \
414+ https://github.com/daveshanley/vacuum/releases/download/v0.18.1/vacuum_0.18.1_linux_x86_64.tar.gz
415+ tar -xzf vacuum.tar.gz
416+ chmod u+x vacuum
417+ sudo mv vacuum /usr/local/bin/
418+ vacuum version
419+
420+ - name : Generate API spec
421+ working-directory : modules/express
422+ run : |
423+ ../../node_modules/.bin/openapi-generator \
424+ --codec-file openapi-generator.rc.js \
425+ src/typedRoutes/api/index.ts \
426+ > api-generated.json
427+
428+ - name : Audit with Vacuum
429+ working-directory : modules/express
430+ run : |
431+
432+ vacuum report \
433+ --no-style \
434+ --stdout \
435+ --ruleset ruleset.yaml \
436+ api-generated.json > vacuum-report.json
437+
438+ jq '.resultSet.results // []' vacuum-report.json > vacuum-results.json
439+
440+ ERROR_COUNT=$(jq '[.[] | select(.ruleSeverity == "error")] | length' vacuum-results.json)
441+ WARNING_COUNT=$(jq '[.[] | select(.ruleSeverity == "warn")] | length' vacuum-results.json)
442+
443+ echo "Found $ERROR_COUNT error(s) and $WARNING_COUNT warning(s)"
444+
445+ if [ "$ERROR_COUNT" -gt 0 ]; then
446+ echo "API specification audit failed with $ERROR_COUNT error(s)"
447+ echo ""
448+ echo "Errors:"
449+ jq -r '.[] | select(.ruleSeverity == "error") | " - [\(.ruleId)] \(.message) at \(.path)"' vacuum-results.json
450+ exit 1
451+ else
452+ echo "API specification audit passed!"
453+ fi
0 commit comments