|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, develop] |
| 6 | + pull_request: |
| 7 | + branches: [main, develop] |
| 8 | + |
| 9 | +jobs: |
| 10 | + lint: |
| 11 | + name: Lint |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Setup Node.js |
| 18 | + uses: actions/setup-node@v4 |
| 19 | + with: |
| 20 | + node-version: '18' |
| 21 | + cache: 'npm' |
| 22 | + |
| 23 | + - name: Install dependencies |
| 24 | + run: npm ci |
| 25 | + |
| 26 | + - name: Run ESLint |
| 27 | + run: npm run lint |
| 28 | + |
| 29 | + - name: Check formatting |
| 30 | + run: npm run format:check |
| 31 | + |
| 32 | + typecheck: |
| 33 | + name: Type Check |
| 34 | + runs-on: ubuntu-latest |
| 35 | + steps: |
| 36 | + - name: Checkout code |
| 37 | + uses: actions/checkout@v4 |
| 38 | + |
| 39 | + - name: Setup Node.js |
| 40 | + uses: actions/setup-node@v4 |
| 41 | + with: |
| 42 | + node-version: '18' |
| 43 | + cache: 'npm' |
| 44 | + |
| 45 | + - name: Install dependencies |
| 46 | + run: npm ci |
| 47 | + |
| 48 | + - name: Run TypeScript compiler |
| 49 | + run: npm run typecheck |
| 50 | + |
| 51 | + test: |
| 52 | + name: Test |
| 53 | + runs-on: ubuntu-latest |
| 54 | + strategy: |
| 55 | + matrix: |
| 56 | + node-version: [16, 18, 20] |
| 57 | + steps: |
| 58 | + - name: Checkout code |
| 59 | + uses: actions/checkout@v4 |
| 60 | + |
| 61 | + - name: Setup Node.js ${{ matrix.node-version }} |
| 62 | + uses: actions/setup-node@v4 |
| 63 | + with: |
| 64 | + node-version: ${{ matrix.node-version }} |
| 65 | + cache: 'npm' |
| 66 | + |
| 67 | + - name: Install dependencies |
| 68 | + run: npm ci |
| 69 | + |
| 70 | + - name: Run tests with coverage |
| 71 | + run: npm run test:coverage |
| 72 | + |
| 73 | + - name: Upload coverage to Codecov |
| 74 | + uses: codecov/codecov-action@v3 |
| 75 | + if: matrix.node-version == 18 |
| 76 | + with: |
| 77 | + files: ./coverage/lcov.info |
| 78 | + flags: unittests |
| 79 | + name: codecov-umbrella |
| 80 | + fail_ci_if_error: false |
| 81 | + |
| 82 | + build: |
| 83 | + name: Build |
| 84 | + runs-on: ubuntu-latest |
| 85 | + needs: [lint, typecheck, test] |
| 86 | + steps: |
| 87 | + - name: Checkout code |
| 88 | + uses: actions/checkout@v4 |
| 89 | + |
| 90 | + - name: Setup Node.js |
| 91 | + uses: actions/setup-node@v4 |
| 92 | + with: |
| 93 | + node-version: '18' |
| 94 | + cache: 'npm' |
| 95 | + |
| 96 | + - name: Install dependencies |
| 97 | + run: npm ci |
| 98 | + |
| 99 | + - name: Build package |
| 100 | + run: npm run build |
| 101 | + |
| 102 | + - name: Check build output |
| 103 | + run: | |
| 104 | + test -f dist/index.js |
| 105 | + test -f dist/index.mjs |
| 106 | + test -f dist/index.d.ts |
| 107 | +
|
| 108 | + - name: Upload build artifacts |
| 109 | + uses: actions/upload-artifact@v3 |
| 110 | + with: |
| 111 | + name: dist |
| 112 | + path: dist/ |
| 113 | + |
| 114 | + publish-check: |
| 115 | + name: Publish Check |
| 116 | + runs-on: ubuntu-latest |
| 117 | + needs: build |
| 118 | + steps: |
| 119 | + - name: Checkout code |
| 120 | + uses: actions/checkout@v4 |
| 121 | + |
| 122 | + - name: Setup Node.js |
| 123 | + uses: actions/setup-node@v4 |
| 124 | + with: |
| 125 | + node-version: '18' |
| 126 | + cache: 'npm' |
| 127 | + |
| 128 | + - name: Install dependencies |
| 129 | + run: npm ci |
| 130 | + |
| 131 | + - name: Build |
| 132 | + run: npm run build |
| 133 | + |
| 134 | + - name: Check package contents |
| 135 | + run: npm pack --dry-run |
| 136 | + |
| 137 | + - name: Verify package.json |
| 138 | + run: | |
| 139 | + node -e "const pkg = require('./package.json'); \ |
| 140 | + if (!pkg.name) throw new Error('Missing name'); \ |
| 141 | + if (!pkg.version) throw new Error('Missing version'); \ |
| 142 | + if (!pkg.main) throw new Error('Missing main'); \ |
| 143 | + if (!pkg.types) throw new Error('Missing types'); \ |
| 144 | + console.log('package.json is valid');" |
| 145 | +
|
| 146 | + all-checks-passed: |
| 147 | + name: All Checks Passed |
| 148 | + runs-on: ubuntu-latest |
| 149 | + needs: [lint, typecheck, test, build, publish-check] |
| 150 | + if: always() |
| 151 | + steps: |
| 152 | + - name: Check all jobs |
| 153 | + run: | |
| 154 | + if [[ "${{ needs.lint.result }}" != "success" || \ |
| 155 | + "${{ needs.typecheck.result }}" != "success" || \ |
| 156 | + "${{ needs.test.result }}" != "success" || \ |
| 157 | + "${{ needs.build.result }}" != "success" || \ |
| 158 | + "${{ needs.publish-check.result }}" != "success" ]]; then |
| 159 | + echo "One or more checks failed" |
| 160 | + exit 1 |
| 161 | + fi |
| 162 | + echo "All checks passed successfully!" |
0 commit comments