|
41 | 41 | VCS_REF=${{ github.sha }} |
42 | 42 | cache-from: type=gha |
43 | 43 | 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