Skip to content

Commit daf8be0

Browse files
committed
feat: npm package setup with CI/CD
- CLI entrypoint (cpk-e2e command) - tsconfig.build for package compilation - CI workflow (test on push/PR) - Publish workflow (npm publish on release/dispatch)
1 parent bc5c00b commit daf8be0

7 files changed

Lines changed: 238 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- uses: actions/setup-node@v4
17+
with:
18+
node-version: 20.x
19+
20+
- uses: oven-sh/setup-bun@v2
21+
with:
22+
bun-version: latest
23+
24+
- name: Install dependencies
25+
run: bun install
26+
27+
- name: Build
28+
run: bun run build
29+
30+
- name: Install Playwright browsers
31+
run: npx playwright install chromium --with-deps
32+
33+
# Clone cpk-ui for testing
34+
- name: Clone cpk-ui
35+
run: git clone --depth 1 https://github.com/crossplatformkorea/cpk-ui.git ../cpk-ui
36+
37+
- name: Install cpk-ui dependencies
38+
run: cd ../cpk-ui && bun install
39+
40+
- name: Build cpk-ui Storybook
41+
run: cd ../cpk-ui && CI=1 STORYBOOK=1 npx storybook build -o storybook-static
42+
43+
- name: Discover components
44+
run: bun run discover
45+
46+
- name: Check story coverage
47+
run: bun run check-coverage || true
48+
49+
- name: Run E2E tests
50+
run: bun run test
51+
52+
- name: Upload test report
53+
if: always()
54+
uses: actions/upload-artifact@v4
55+
with:
56+
name: playwright-report
57+
path: playwright-report/
58+
retention-days: 14
59+
60+
- name: Upload screenshots
61+
if: always()
62+
uses: actions/upload-artifact@v4
63+
with:
64+
name: screenshots
65+
path: screenshots/
66+
retention-days: 14

.github/workflows/publish.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Version bump type'
10+
required: true
11+
default: 'patch'
12+
type: choice
13+
options:
14+
- patch
15+
- minor
16+
- major
17+
18+
jobs:
19+
publish:
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: write
23+
id-token: write
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- uses: actions/setup-node@v4
31+
with:
32+
node-version: 20.x
33+
registry-url: 'https://registry.npmjs.org'
34+
35+
- uses: oven-sh/setup-bun@v2
36+
with:
37+
bun-version: latest
38+
39+
- name: Install dependencies
40+
run: bun install
41+
42+
- name: Bump version
43+
if: github.event_name == 'workflow_dispatch'
44+
run: |
45+
npm version ${{ inputs.version }} --no-git-tag-version
46+
VERSION=$(node -p "require('./package.json').version")
47+
git config user.name "github-actions[bot]"
48+
git config user.email "github-actions[bot]@users.noreply.github.com"
49+
git add package.json
50+
git commit -m "chore: bump version to $VERSION"
51+
git push
52+
53+
- name: Build
54+
run: bun run build
55+
56+
- name: Publish to npm
57+
run: npm publish --provenance --access public
58+
env:
59+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

bun.lock

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
{
22
"name": "cpk-e2e",
33
"version": "0.1.0",
4-
"private": true,
54
"description": "E2E render testing tool for cpk-ui React Native components",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
7+
"bin": {
8+
"cpk-e2e": "dist/cli.js"
9+
},
10+
"files": [
11+
"dist",
12+
"tests",
13+
"playwright.config.ts"
14+
],
15+
"publishConfig": {
16+
"access": "public"
17+
},
618
"scripts": {
719
"discover": "tsx scripts/discover-components.ts",
820
"check-coverage": "tsx scripts/check-coverage.ts",
@@ -13,11 +25,29 @@
1325
"test:ui": "playwright test --ui",
1426
"test:debug": "playwright test --debug",
1527
"e2e": "tsx scripts/run-e2e.ts",
16-
"report": "playwright show-report"
28+
"report": "playwright show-report",
29+
"build": "tsc --project tsconfig.build.json",
30+
"prepublishOnly": "bun run build"
31+
},
32+
"dependencies": {
33+
"@playwright/test": "^1.52.0"
1734
},
1835
"devDependencies": {
19-
"@playwright/test": "^1.52.0",
36+
"@types/node": "^25.5.0",
2037
"tsx": "^4.19.0",
2138
"typescript": "~5.9.3"
22-
}
39+
},
40+
"repository": {
41+
"type": "git",
42+
"url": "https://github.com/crossplatformkorea/cpk-e2e"
43+
},
44+
"license": "MIT",
45+
"keywords": [
46+
"e2e",
47+
"testing",
48+
"react-native",
49+
"storybook",
50+
"playwright",
51+
"cpk-ui"
52+
]
2353
}

scripts/cli.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* cpk-e2e CLI
5+
*
6+
* Usage:
7+
* cpk-e2e discover [--json] List all components in target project
8+
* cpk-e2e check-coverage Check story coverage
9+
* cpk-e2e test [--headed] Run Playwright render tests
10+
* cpk-e2e run [--skip-build] Full pipeline
11+
*/
12+
13+
import {execSync} from 'child_process';
14+
import * as path from 'path';
15+
16+
const args = process.argv.slice(2);
17+
const command = args[0];
18+
19+
const SCRIPTS_DIR = path.resolve(__dirname);
20+
21+
function exec(cmd: string) {
22+
execSync(cmd, {stdio: 'inherit', cwd: process.cwd()});
23+
}
24+
25+
switch (command) {
26+
case 'discover':
27+
exec(`node ${path.join(SCRIPTS_DIR, 'discover-components.js')} ${args.slice(1).join(' ')}`);
28+
break;
29+
30+
case 'check-coverage':
31+
exec(`node ${path.join(SCRIPTS_DIR, 'check-coverage.js')}`);
32+
break;
33+
34+
case 'test':
35+
exec(`npx playwright test ${args.slice(1).join(' ')}`);
36+
break;
37+
38+
case 'run':
39+
exec(`node ${path.join(SCRIPTS_DIR, 'run-e2e.js')} ${args.slice(1).join(' ')}`);
40+
break;
41+
42+
default:
43+
console.log(`
44+
cpk-e2e - E2E render testing for React Native components
45+
46+
Commands:
47+
discover [--json] List all components in target project
48+
check-coverage Check story coverage
49+
test [--headed] Run Playwright render tests
50+
run [--skip-build] Full pipeline (discover + build + test)
51+
`);
52+
break;
53+
}

scripts/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export {discoverExports, type ComponentInfo} from './discover-components';
2+
export {checkCoverage, type CoverageReport} from './check-coverage';

tsconfig.build.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2022",
4+
"module": "commonjs",
5+
"moduleResolution": "node",
6+
"strict": true,
7+
"esModuleInterop": true,
8+
"skipLibCheck": true,
9+
"outDir": "dist",
10+
"rootDir": "scripts",
11+
"declaration": true,
12+
"resolveJsonModule": true
13+
},
14+
"include": ["scripts/**/*.ts"],
15+
"exclude": ["node_modules", "dist", "tests"]
16+
}

0 commit comments

Comments
 (0)