Skip to content

Commit a8b9ad9

Browse files
committed
chore: add GitHub Actions workflows for build, CI, publish, and security checks
1 parent 1825933 commit a8b9ad9

File tree

4 files changed

+252
-0
lines changed

4 files changed

+252
-0
lines changed

.github/workflows/build-check.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Build Check
2+
3+
on:
4+
pull_request:
5+
branches: [main, master]
6+
7+
jobs:
8+
build:
9+
name: Verify Build
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '20.x'
20+
cache: 'npm'
21+
22+
- name: Install dependencies
23+
run: npm ci
24+
25+
- name: Build package
26+
run: npm run build
27+
28+
- name: Verify build output
29+
run: |
30+
if [ ! -d "dist" ]; then
31+
echo "Error: dist directory not found"
32+
exit 1
33+
fi
34+
if [ ! -f "dist/index.js" ]; then
35+
echo "Error: dist/index.js not found"
36+
exit 1
37+
fi
38+
if [ ! -f "dist/index.d.ts" ]; then
39+
echo "Error: dist/index.d.ts not found"
40+
exit 1
41+
fi
42+
echo "Build output verified successfully"
43+
44+
- name: Check bundle size
45+
run: |
46+
SIZE=$(du -sh dist | cut -f1)
47+
echo "Build size: $SIZE"
48+
# Fail if build is suspiciously large (>50MB)
49+
SIZE_BYTES=$(du -sb dist | cut -f1)
50+
if [ $SIZE_BYTES -gt 52428800 ]; then
51+
echo "Warning: Build size exceeds 50MB"
52+
fi

.github/workflows/ci.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
9+
jobs:
10+
test:
11+
name: Test & Lint
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
node-version: [18.x, 20.x, 22.x]
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
cache: 'npm'
27+
28+
- name: Install dependencies
29+
run: npm ci
30+
31+
- name: Run linter
32+
run: npm run lint
33+
34+
- name: Check formatting
35+
run: npm run prettier:check
36+
37+
- name: Build
38+
run: npm run build
39+
40+
- name: Run tests
41+
run: npm test
42+
43+
- name: Generate coverage
44+
if: matrix.node-version == '20.x'
45+
run: npm run test:coverage
46+
47+
- name: Upload coverage reports
48+
if: matrix.node-version == '20.x'
49+
uses: codecov/codecov-action@v4
50+
with:
51+
files: ./coverage/coverage-final.json
52+
fail_ci_if_error: false
53+
token: ${{ secrets.CODECOV_TOKEN }}
54+
55+
type-check:
56+
name: Type Check
57+
runs-on: ubuntu-latest
58+
59+
steps:
60+
- name: Checkout code
61+
uses: actions/checkout@v4
62+
63+
- name: Setup Node.js
64+
uses: actions/setup-node@v4
65+
with:
66+
node-version: '20.x'
67+
cache: 'npm'
68+
69+
- name: Install dependencies
70+
run: npm ci
71+
72+
- name: Type check
73+
run: npx tsc --noEmit

.github/workflows/publish.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Publish to npm
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Version to publish (e.g., 1.0.0)'
10+
required: true
11+
type: string
12+
13+
jobs:
14+
publish:
15+
name: Publish Package
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
19+
id-token: write
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Setup Node.js
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: '20.x'
31+
registry-url: 'https://registry.npmjs.org'
32+
cache: 'npm'
33+
34+
- name: Install dependencies
35+
run: npm ci
36+
37+
- name: Run tests
38+
run: npm test
39+
40+
- name: Build
41+
run: npm run build
42+
43+
- name: Verify package
44+
run: npm pack --dry-run
45+
46+
- name: Extract version from release
47+
if: github.event_name == 'release'
48+
id: version
49+
run: |
50+
VERSION=${GITHUB_REF#refs/tags/v}
51+
VERSION=${VERSION#refs/tags/}
52+
echo "version=$VERSION" >> $GITHUB_OUTPUT
53+
echo "Publishing version: $VERSION"
54+
55+
- name: Verify version matches package.json
56+
if: github.event_name == 'release'
57+
run: |
58+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
59+
RELEASE_VERSION="${{ steps.version.outputs.version }}"
60+
if [ "$PACKAGE_VERSION" != "$RELEASE_VERSION" ]; then
61+
echo "Error: package.json version ($PACKAGE_VERSION) doesn't match release tag ($RELEASE_VERSION)"
62+
exit 1
63+
fi
64+
echo "Version verified: $PACKAGE_VERSION"
65+
66+
- name: Update package.json version (manual)
67+
if: github.event_name == 'workflow_dispatch'
68+
run: |
69+
npm version "${{ github.event.inputs.version }}" --no-git-tag-version
70+
echo "Updated package.json to version ${{ github.event.inputs.version }}"
71+
72+
- name: Publish to npm
73+
uses: JS-DevTools/npm-publish@v3
74+
with:
75+
token: ${{ secrets.NPM_TOKEN }}
76+
registry: https://registry.npmjs.org
77+
access: public

.github/workflows/security.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Security
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
schedule:
9+
# Run weekly on Monday at 00:00 UTC
10+
- cron: '0 0 * * 1'
11+
12+
jobs:
13+
audit:
14+
name: Security Audit
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: '20.x'
25+
cache: 'npm'
26+
27+
- name: Install dependencies
28+
run: npm ci
29+
30+
- name: Run npm audit
31+
run: npm audit --audit-level=moderate
32+
continue-on-error: true
33+
34+
- name: Check for known vulnerabilities
35+
run: npm audit --audit-level=high
36+
continue-on-error: true
37+
38+
dependency-review:
39+
name: Dependency Review
40+
runs-on: ubuntu-latest
41+
if: github.event_name == 'pull_request'
42+
43+
steps:
44+
- name: Checkout code
45+
uses: actions/checkout@v4
46+
47+
- name: Dependency Review
48+
uses: actions/dependency-review-action@v4
49+
with:
50+
fail-on-severity: moderate

0 commit comments

Comments
 (0)