Skip to content

Commit d9a2207

Browse files
author
Marvin Zhang
committed
feat: add CLI package build and verification to scripts; update README for GitHub Actions scripts
1 parent 93e4846 commit d9a2207

File tree

6 files changed

+194
-83
lines changed

6 files changed

+194
-83
lines changed

.github/scripts/README.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# GitHub Actions Scripts
2+
3+
This directory contains reusable shell scripts to optimize and simplify GitHub Actions workflows.
4+
5+
## 🎯 Benefits
6+
7+
- **DRY Principle**: Eliminates code duplication across workflows
8+
- **Maintainability**: Changes to logic only need to be made in one place
9+
- **Testability**: Scripts can be tested locally
10+
- **Readability**: Workflows are cleaner and easier to understand
11+
- **Reusability**: Scripts can be used in multiple workflows or locally
12+
13+
## 📁 Scripts Overview
14+
15+
### Core Build & Test Scripts
16+
17+
#### `setup-node.sh`
18+
Sets up Node.js environment and installs dependencies with pnpm.
19+
```bash
20+
./.github/scripts/setup-node.sh [node_version] [pnpm_version]
21+
```
22+
- **Default**: Node.js 20, pnpm 10.13.1
23+
- **Used in**: All workflows that need Node.js
24+
25+
#### `build-packages.sh`
26+
Builds all packages in dependency order (core → ai → mcp → cli → web).
27+
```bash
28+
./.github/scripts/build-packages.sh
29+
```
30+
- **Dependencies**: Requires pnpm workspace setup
31+
- **Output**: Build artifacts in `packages/*/build` and `packages/web/.next-build`
32+
33+
#### `verify-build.sh`
34+
Verifies that all expected build artifacts exist.
35+
```bash
36+
./.github/scripts/verify-build.sh
37+
```
38+
- **Checks**:
39+
- Core, AI, MCP, CLI packages: `build/index.js` and `build/index.d.ts`
40+
- Web package: `.next-build/` directory
41+
- **Exit codes**: 0 = success, 1 = missing artifacts
42+
43+
#### `run-tests.sh`
44+
Runs tests for all packages with coverage.
45+
```bash
46+
./.github/scripts/run-tests.sh
47+
```
48+
- **Command**: `pnpm -r test:coverage`
49+
- **Requirements**: All packages must have `test:coverage` script
50+
51+
### NPM Publishing Scripts
52+
53+
#### `check-versions.sh`
54+
Determines which packages need to be published based on version comparison.
55+
```bash
56+
./.github/scripts/check-versions.sh [force_publish] [package_filter]
57+
```
58+
- **Parameters**:
59+
- `force_publish`: "true" to force publish regardless of versions
60+
- `package_filter`: Comma-separated list (e.g., "core,mcp")
61+
- **Output**: Sets GitHub Actions outputs for downstream jobs
62+
- **Environment**: Requires `NODE_AUTH_TOKEN` for NPM registry access
63+
64+
#### `publish-packages.sh`
65+
Publishes specified packages to NPM registry.
66+
```bash
67+
./.github/scripts/publish-packages.sh "mcp,core,ai"
68+
```
69+
- **Input**: Comma-separated package list
70+
- **Environment**: Requires `NODE_AUTH_TOKEN`
71+
- **Output**: Sets `published_packages` GitHub Actions output
72+
73+
### Docker & Validation Scripts
74+
75+
#### `test-docker.sh`
76+
Tests Docker image functionality by starting container and checking endpoints.
77+
```bash
78+
./.github/scripts/test-docker.sh "image:tag"
79+
```
80+
- **Tests**:
81+
- Container starts successfully
82+
- HTTP endpoint responds (port 3000)
83+
- Health check endpoint (if available)
84+
- **Cleanup**: Automatically stops test container
85+
86+
#### `validate-pr.sh`
87+
Runs lightweight validation checks for pull requests.
88+
```bash
89+
./.github/scripts/validate-pr.sh
90+
```
91+
- **Checks**:
92+
- TypeScript compilation
93+
- Quick build test (core, ai, mcp, cli packages)
94+
- Unit tests
95+
- Import structure validation (if script exists)
96+
97+
## 🔧 Usage in Workflows
98+
99+
### Before (Workflow with inline scripts)
100+
```yaml
101+
- name: Build packages
102+
run: |
103+
pnpm --filter @codervisor/devlog-core build
104+
pnpm --filter @codervisor/devlog-ai build
105+
pnpm --filter @codervisor/devlog-mcp build
106+
pnpm --filter @codervisor/devlog-web build
107+
```
108+
109+
### After (Workflow with script)
110+
```yaml
111+
- name: Build packages
112+
run: ./.github/scripts/build-packages.sh
113+
```
114+
115+
## 🧪 Local Testing
116+
117+
All scripts can be tested locally:
118+
119+
```bash
120+
# Test build process
121+
./.github/scripts/setup-node.sh
122+
./.github/scripts/build-packages.sh
123+
./.github/scripts/verify-build.sh
124+
125+
# Test PR validation
126+
./.github/scripts/validate-pr.sh
127+
128+
# Test version checking (dry run)
129+
./.github/scripts/check-versions.sh "false" ""
130+
```
131+
132+
## 🔍 Script Standards
133+
134+
### Error Handling
135+
- All scripts use `set -euo pipefail` for strict error handling
136+
- Exit codes: 0 = success, 1 = failure
137+
- Clear error messages with emojis for visibility
138+
139+
### GitHub Actions Integration
140+
- Scripts write to `$GITHUB_OUTPUT` when available
141+
- Fallback to stdout for local testing
142+
- Support both CI and local environments
143+
144+
### Logging
145+
- Consistent emoji prefixes for different operations:
146+
- 🔧 Setup/configuration
147+
- 🔨 Building
148+
- 🧪 Testing
149+
- 📦 Packaging/publishing
150+
- 🐳 Docker operations
151+
- ✅ Success
152+
- ❌ Failure
153+
- ⚠️ Warning
154+
155+
### Parameters
156+
- Support both required and optional parameters
157+
- Provide sensible defaults
158+
- Document parameter usage in script comments
159+
160+
## 📊 Performance Impact
161+
162+
### Before Refactoring
163+
- **Duplicated logic**: ~150 lines across 3 workflows
164+
- **Maintenance**: Changes needed in multiple files
165+
- **Testing**: Difficult to test workflow logic locally
166+
167+
### After Refactoring
168+
- **Centralized logic**: ~50 lines per workflow (70% reduction)
169+
- **Maintenance**: Changes in single script files
170+
- **Testing**: Scripts testable locally and in CI
171+
172+
## 🚀 Future Enhancements
173+
174+
Potential improvements:
175+
- **Script parameters**: More configurable options
176+
- **Parallel execution**: Where safe and beneficial
177+
- **Advanced caching**: More granular cache strategies
178+
- **Integration testing**: End-to-end workflow testing
179+
- **Monitoring**: Script execution metrics

.github/scripts/build-packages.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ pnpm --filter @codervisor/devlog-ai build
1616
echo "Building @codervisor/devlog-mcp..."
1717
pnpm --filter @codervisor/devlog-mcp build
1818

19+
# Build cli package (depends on core and ai)
20+
echo "Building @codervisor/devlog-cli..."
21+
pnpm --filter @codervisor/devlog-cli build
22+
1923
# Build web package (depends on core)
2024
echo "Building @codervisor/devlog-web..."
2125
pnpm --filter @codervisor/devlog-web build

.github/scripts/validate-pr.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ echo "🔨 Quick build test..."
1313
pnpm --filter @codervisor/devlog-core build
1414
pnpm --filter @codervisor/devlog-ai build
1515
pnpm --filter @codervisor/devlog-mcp build
16+
pnpm --filter @codervisor/devlog-cli build
1617

1718
# Run tests
1819
echo "🧪 Running tests..."

.github/scripts/verify-build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ else
3030
FAILED=1
3131
fi
3232

33+
# Check cli package
34+
if [ -f "packages/cli/build/index.js" ] && [ -f "packages/cli/build/index.d.ts" ]; then
35+
echo "✅ CLI package build artifacts verified"
36+
else
37+
echo "❌ CLI package build artifacts missing"
38+
FAILED=1
39+
fi
40+
3341
# Check web package (uses .next-build for standalone builds)
3442
if [ -d "packages/web/.next-build" ]; then
3543
echo "✅ Web package build artifacts verified"

.github/workflows/README.md

Lines changed: 0 additions & 83 deletions
This file was deleted.

packages/cli/tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"compilerOptions": {
44
"outDir": "./build",
55
"rootDir": "./src",
6+
"declaration": true,
7+
"declarationMap": true,
68
"allowSyntheticDefaultImports": true
79
},
810
"include": ["src/**/*"],

0 commit comments

Comments
 (0)