|
| 1 | +name: Code Quality |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + - release |
| 8 | + |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - master |
| 12 | + - release |
| 13 | + |
| 14 | + schedule: |
| 15 | + - cron: '17 5 * * 1' |
| 16 | + |
| 17 | + workflow_dispatch: |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 21 | + cancel-in-progress: true |
| 22 | + |
| 23 | +permissions: |
| 24 | + contents: read |
| 25 | + |
| 26 | +jobs: |
| 27 | + dependency-review: |
| 28 | + if: github.event_name == 'pull_request' |
| 29 | + runs-on: ubuntu-latest |
| 30 | + permissions: |
| 31 | + contents: read |
| 32 | + pull-requests: read |
| 33 | + steps: |
| 34 | + - name: Checkout code |
| 35 | + uses: actions/checkout@v5 |
| 36 | + |
| 37 | + - name: Review dependency changes |
| 38 | + uses: actions/dependency-review-action@v4 |
| 39 | + with: |
| 40 | + fail-on-severity: high |
| 41 | + license-check: false |
| 42 | + |
| 43 | + unit-quality: |
| 44 | + if: github.event_name != 'schedule' |
| 45 | + name: Unit Quality (Node ${{ matrix.node-version }}) |
| 46 | + timeout-minutes: 20 |
| 47 | + runs-on: ubuntu-latest |
| 48 | + strategy: |
| 49 | + fail-fast: false |
| 50 | + matrix: |
| 51 | + node-version: |
| 52 | + - 22.x |
| 53 | + - 24.x |
| 54 | + steps: |
| 55 | + - name: Checkout code |
| 56 | + uses: actions/checkout@v5 |
| 57 | + |
| 58 | + - name: Set up Node.js |
| 59 | + uses: actions/setup-node@v5 |
| 60 | + with: |
| 61 | + node-version: ${{ matrix.node-version }} |
| 62 | + cache: npm |
| 63 | + |
| 64 | + - name: Install dependencies |
| 65 | + run: npm ci |
| 66 | + |
| 67 | + - name: Type-check source |
| 68 | + run: npm run typecheck |
| 69 | + |
| 70 | + - name: Run unit tests with coverage gate |
| 71 | + run: npm run test:ci |
| 72 | + |
| 73 | + - name: Build package |
| 74 | + if: matrix.node-version == '24.x' |
| 75 | + run: npm run build |
| 76 | + |
| 77 | + - name: Upload coverage artifact |
| 78 | + if: always() && matrix.node-version == '24.x' && hashFiles('coverage/**/*') != '' |
| 79 | + uses: actions/upload-artifact@v4 |
| 80 | + with: |
| 81 | + name: coverage-node-${{ matrix.node-version }} |
| 82 | + path: coverage |
| 83 | + |
| 84 | + - name: Publish coverage summary |
| 85 | + if: always() && matrix.node-version == '24.x' && hashFiles('coverage/coverage-summary.json') != '' |
| 86 | + shell: bash |
| 87 | + run: | |
| 88 | + node <<'EOF' |
| 89 | + const fs = require('node:fs'); |
| 90 | +
|
| 91 | + const summaryPath = 'coverage/coverage-summary.json'; |
| 92 | + const summary = JSON.parse(fs.readFileSync(summaryPath, 'utf8')).total; |
| 93 | + const metrics = ['lines', 'functions', 'statements', 'branches']; |
| 94 | + const rows = metrics.map((metric) => { |
| 95 | + const value = summary[metric]?.pct ?? 0; |
| 96 | + return `| ${metric} | ${value.toFixed(2)}% |`; |
| 97 | + }); |
| 98 | +
|
| 99 | + const markdown = [ |
| 100 | + '## Coverage Summary', |
| 101 | + '', |
| 102 | + '| Metric | Coverage |', |
| 103 | + '| --- | ---: |', |
| 104 | + ...rows, |
| 105 | + '', |
| 106 | + 'Coverage thresholds are enforced by the test runner configuration.', |
| 107 | + '', |
| 108 | + ].join('\n'); |
| 109 | +
|
| 110 | + fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, markdown); |
| 111 | + EOF |
| 112 | +
|
| 113 | + codeql: |
| 114 | + name: CodeQL (JavaScript/TypeScript) |
| 115 | + timeout-minutes: 20 |
| 116 | + runs-on: ubuntu-latest |
| 117 | + permissions: |
| 118 | + actions: read |
| 119 | + contents: read |
| 120 | + security-events: write |
| 121 | + strategy: |
| 122 | + fail-fast: false |
| 123 | + matrix: |
| 124 | + language: |
| 125 | + - javascript |
| 126 | + steps: |
| 127 | + - name: Checkout code |
| 128 | + uses: actions/checkout@v5 |
| 129 | + |
| 130 | + - name: Set up Node.js |
| 131 | + uses: actions/setup-node@v5 |
| 132 | + with: |
| 133 | + node-version: '24.x' |
| 134 | + cache: npm |
| 135 | + |
| 136 | + - name: Initialize CodeQL |
| 137 | + uses: github/codeql-action/init@v3 |
| 138 | + with: |
| 139 | + languages: ${{ matrix.language }} |
| 140 | + build-mode: none |
| 141 | + config-file: ./.github/codeql/codeql-config.yml |
| 142 | + |
| 143 | + - name: Install dependencies |
| 144 | + run: npm ci |
| 145 | + |
| 146 | + - name: Build package |
| 147 | + run: npm run build |
| 148 | + |
| 149 | + - name: Perform CodeQL analysis |
| 150 | + uses: github/codeql-action/analyze@v3 |
| 151 | + with: |
| 152 | + category: /language:${{ matrix.language }} |
0 commit comments