Skip to content

Commit 8a7d7bd

Browse files
feat: add GitHub Actions CI/CD workflows
1 parent 8ec41f6 commit 8a7d7bd

File tree

4 files changed

+191
-0
lines changed

4 files changed

+191
-0
lines changed

.github/dependabot.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "npm"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
open-pull-requests-limit: 5
8+
groups:
9+
typescript-eslint:
10+
patterns:
11+
- "@typescript-eslint/*"
12+
jest:
13+
patterns:
14+
- "jest"
15+
- "ts-jest"
16+
- "@types/jest"
17+
commit-message:
18+
prefix: "chore"
19+
include: "scope"

.github/workflows/ci.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [16.x, 18.x, 20.x]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
cache: 'npm'
25+
26+
- name: Install dependencies
27+
run: npm ci
28+
29+
- name: Run linting
30+
run: npm run lint
31+
32+
- name: Run type checking
33+
run: npm run typecheck
34+
35+
- name: Build the SDK
36+
run: npm run build
37+
38+
- name: Run tests
39+
run: npm test
40+
41+
- name: Run tests with coverage
42+
run: npm run test:coverage
43+
44+
- name: Upload coverage reports
45+
if: matrix.node-version == '20.x'
46+
uses: codecov/codecov-action@v3
47+
with:
48+
token: ${{ secrets.CODECOV_TOKEN }}
49+
fail_ci_if_error: false
50+
51+
release:
52+
needs: test
53+
runs-on: ubuntu-latest
54+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
55+
56+
steps:
57+
- uses: actions/checkout@v4
58+
59+
- name: Setup Node.js
60+
uses: actions/setup-node@v4
61+
with:
62+
node-version: '20.x'
63+
registry-url: 'https://registry.npmjs.org'
64+
65+
- name: Install dependencies
66+
run: npm ci
67+
68+
- name: Build
69+
run: npm run build
70+
71+
- name: Check if version changed
72+
id: version
73+
run: |
74+
PUBLISHED_VERSION=$(npm view @validkit/sdk version 2>/dev/null || echo "0.0.0")
75+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
76+
if [ "$PUBLISHED_VERSION" != "$PACKAGE_VERSION" ]; then
77+
echo "changed=true" >> $GITHUB_OUTPUT
78+
echo "version=$PACKAGE_VERSION" >> $GITHUB_OUTPUT
79+
else
80+
echo "changed=false" >> $GITHUB_OUTPUT
81+
fi
82+
83+
- name: Create Release
84+
if: steps.version.outputs.changed == 'true'
85+
uses: actions/create-release@v1
86+
env:
87+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
with:
89+
tag_name: v${{ steps.version.outputs.version }}
90+
release_name: Release v${{ steps.version.outputs.version }}
91+
body: |
92+
See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md) for details.
93+
draft: false
94+
prerelease: false
95+
96+
- name: Publish to npm
97+
if: steps.version.outputs.changed == 'true'
98+
run: npm publish --access public
99+
env:
100+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: PR Validation
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
validate:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Setup Node.js
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version: '20.x'
18+
cache: 'npm'
19+
20+
- name: Install dependencies
21+
run: npm ci
22+
23+
- name: Check formatting
24+
run: npm run lint
25+
26+
- name: Type check
27+
run: npm run typecheck
28+
29+
- name: Build
30+
run: npm run build
31+
32+
- name: Test
33+
run: npm run test:coverage
34+
35+
- name: Check test coverage
36+
run: |
37+
COVERAGE=$(npm run test:coverage -- --json --silent | jq '.coverageMap | to_entries | map(.value.branches.pct) | add / length')
38+
echo "Branch coverage: $COVERAGE%"
39+
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
40+
echo "❌ Branch coverage is below 80%"
41+
exit 1
42+
else
43+
echo "✅ Branch coverage meets threshold"
44+
fi
45+
46+
- name: Check bundle size
47+
run: |
48+
npm run build
49+
BUNDLE_SIZE=$(find dist -name "*.js" -type f -exec du -b {} + | awk '{sum+=$1} END {print sum}')
50+
MAX_SIZE=100000 # 100KB
51+
echo "Bundle size: $BUNDLE_SIZE bytes"
52+
if [ $BUNDLE_SIZE -gt $MAX_SIZE ]; then
53+
echo "❌ Bundle size exceeds 100KB limit"
54+
exit 1
55+
else
56+
echo "✅ Bundle size is within limits"
57+
fi
58+
59+
- name: Validate package.json
60+
run: |
61+
# Check required fields
62+
node -e "
63+
const pkg = require('./package.json');
64+
const required = ['name', 'version', 'description', 'main', 'types', 'license'];
65+
const missing = required.filter(field => !pkg[field]);
66+
if (missing.length > 0) {
67+
console.error('❌ Missing required fields in package.json:', missing.join(', '));
68+
process.exit(1);
69+
}
70+
console.log('✅ All required fields present in package.json');
71+
"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# ValidKit TypeScript SDK
22

3+
[![CI](https://github.com/ValidKit/validkit-typescript-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/ValidKit/validkit-typescript-sdk/actions/workflows/ci.yml)
34
[![npm version](https://badge.fury.io/js/%40validkit%2Fsdk.svg)](https://badge.fury.io/js/%40validkit%2Fsdk)
45
[![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
56
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

0 commit comments

Comments
 (0)