@kabran-tecnologia/kabran-config 1.10.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -1
- package/src/cli/commands/build.mjs +54 -0
- package/src/cli/commands/check.mjs +107 -0
- package/src/cli/commands/ci.mjs +109 -0
- package/src/cli/commands/test.mjs +133 -0
- package/src/cli/kabran.mjs +144 -0
- package/src/core/config-loader.mjs +305 -0
- package/src/schemas/ci-result.v2.schema.json +1 -1
- package/src/scripts/ci/ci-core.sh +1 -1
- package/src/scripts/ci-result-history.mjs +2 -2
- package/src/scripts/ci-result-utils.mjs +1 -1
- package/src/scripts/deploy/deploy-core.sh +1 -1
- package/src/scripts/env-validator.mjs +12 -11
- package/src/scripts/generate-ci-result.mjs +3 -3
- package/src/scripts/quality-standard-validator.mjs +24 -13
- package/src/scripts/readme-validator.mjs +35 -19
- package/src/scripts/setup.mjs +1 -0
- package/src/scripts/traceability/coverage-report.sh +1 -1
- package/src/scripts/traceability/traceability-core.sh +1 -1
- package/src/scripts/traceability/validate-traceability.sh +1 -1
- package/src/telemetry/README.md +11 -11
- package/src/telemetry/config/defaults.mjs +5 -7
- package/src/telemetry/shared/types.d.ts +1 -1
- package/templates/config/.prettierignore +35 -0
- package/templates/config/kabran.config.mjs +53 -0
- package/CI-CD-MIGRATION.md +0 -388
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# ==============================================================================
|
|
3
3
|
# Kabran Traceability Core - Shared Functions
|
|
4
|
-
# Part of @kabran-
|
|
4
|
+
# Part of @kabran-tecnologia/kabran-config
|
|
5
5
|
# Implements PROP-006: JSDoc Traceability Tags
|
|
6
6
|
# ==============================================================================
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# ==============================================================================
|
|
3
3
|
# Kabran Traceability Validator
|
|
4
|
-
# Part of @kabran-
|
|
4
|
+
# Part of @kabran-tecnologia/kabran-config
|
|
5
5
|
# Implements PROP-006: JSDoc Traceability Tags
|
|
6
6
|
#
|
|
7
7
|
# Validates FORMAT of traceability tags (not presence).
|
package/src/telemetry/README.md
CHANGED
|
@@ -161,8 +161,8 @@ SERVICE_VERSION=1.0.0 # Service version (default: 1.0.0)
|
|
|
161
161
|
ENVIRONMENT=production # Environment name (default: from NODE_ENV)
|
|
162
162
|
OTEL_NAMESPACE=kabran # Service namespace (default: kabran)
|
|
163
163
|
|
|
164
|
-
# OTLP Exporter
|
|
165
|
-
OTEL_EXPORTER_OTLP_ENDPOINT=https://otel.
|
|
164
|
+
# OTLP Exporter (REQUIRED)
|
|
165
|
+
OTEL_EXPORTER_OTLP_ENDPOINT=https://your-otel-collector.example.com # Your collector endpoint
|
|
166
166
|
OTEL_EXPORTER_OTLP_TIMEOUT=10000 # Export timeout in ms (default: 10000)
|
|
167
167
|
|
|
168
168
|
# Sampling
|
|
@@ -188,7 +188,7 @@ initTelemetry({
|
|
|
188
188
|
// Optional (all have sensible defaults)
|
|
189
189
|
serviceVersion: '1.0.0',
|
|
190
190
|
environment: 'production',
|
|
191
|
-
endpoint:
|
|
191
|
+
endpoint: process.env.OTEL_ENDPOINT, // Required - set via env var
|
|
192
192
|
sampleRate: 0.1,
|
|
193
193
|
enabled: true,
|
|
194
194
|
|
|
@@ -292,20 +292,20 @@ import {
|
|
|
292
292
|
} from '@kabran-tecnologia/kabran-config/telemetry/shared'
|
|
293
293
|
```
|
|
294
294
|
|
|
295
|
-
## Integration with
|
|
295
|
+
## Integration with Observability Stack
|
|
296
296
|
|
|
297
|
-
This package is designed to work with
|
|
297
|
+
This package is designed to work with standard observability stacks:
|
|
298
298
|
|
|
299
|
-
- **Traces** → Grafana Tempo
|
|
299
|
+
- **Traces** → Grafana Tempo, Jaeger, or any OTLP-compatible backend
|
|
300
300
|
- **Logs** → Grafana Loki (via stdout/Promtail or direct export)
|
|
301
|
-
- **Metrics** → Prometheus (planned
|
|
301
|
+
- **Metrics** → Prometheus (planned)
|
|
302
302
|
|
|
303
|
-
|
|
303
|
+
**Note:** You must configure `OTEL_ENDPOINT` to point to your OTLP collector.
|
|
304
304
|
|
|
305
305
|
### Viewing Traces
|
|
306
306
|
|
|
307
|
-
1. Open
|
|
308
|
-
2. Go to Explore → Select Tempo
|
|
307
|
+
1. Open your observability dashboard (e.g., Grafana)
|
|
308
|
+
2. Go to Explore → Select your trace backend (Tempo, Jaeger, etc.)
|
|
309
309
|
3. Search by service name or trace ID
|
|
310
310
|
|
|
311
311
|
## Best Practices
|
|
@@ -404,4 +404,4 @@ initTelemetry({
|
|
|
404
404
|
|
|
405
405
|
- [OpenTelemetry JavaScript](https://opentelemetry.io/docs/languages/js/)
|
|
406
406
|
- [W3C Trace Context](https://www.w3.org/TR/trace-context/)
|
|
407
|
-
- [
|
|
407
|
+
- [OpenTelemetry Collector](https://opentelemetry.io/docs/collector/)
|
|
@@ -76,9 +76,10 @@ function parseIgnorePaths(value) {
|
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
78
|
* Default OTLP endpoint
|
|
79
|
-
*
|
|
79
|
+
* REQUIRED: Set via OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_ENDPOINT
|
|
80
|
+
* No default is provided - users must configure their own collector endpoint
|
|
80
81
|
*/
|
|
81
|
-
export const DEFAULT_ENDPOINT =
|
|
82
|
+
export const DEFAULT_ENDPOINT = null
|
|
82
83
|
|
|
83
84
|
/**
|
|
84
85
|
* Default OTLP traces path
|
|
@@ -107,12 +108,9 @@ export const DEFAULT_NAMESPACE = 'kabran'
|
|
|
107
108
|
/**
|
|
108
109
|
* Default CORS URLs for trace header propagation
|
|
109
110
|
* Override: OTEL_PROPAGATE_TRACE_HEADER_CORS_URLS (comma-separated regex patterns)
|
|
111
|
+
* Only localhost is included by default - configure additional domains via env var
|
|
110
112
|
*/
|
|
111
|
-
export const DEFAULT_CORS_URLS = [
|
|
112
|
-
/.*\.supabase\.co/,
|
|
113
|
-
/.*\.kabran\.com\.br/,
|
|
114
|
-
/localhost/,
|
|
115
|
-
]
|
|
113
|
+
export const DEFAULT_CORS_URLS = [/localhost/]
|
|
116
114
|
|
|
117
115
|
/**
|
|
118
116
|
* Default instrumentation options
|
|
@@ -21,7 +21,7 @@ export interface TelemetryConfig {
|
|
|
21
21
|
/** Deployment environment (default: from NODE_ENV or 'development') */
|
|
22
22
|
environment?: string
|
|
23
23
|
|
|
24
|
-
/** OTLP endpoint URL (
|
|
24
|
+
/** OTLP endpoint URL (required - set via OTEL_ENDPOINT env var) */
|
|
25
25
|
endpoint?: string
|
|
26
26
|
|
|
27
27
|
/** Sampling rate 0.0-1.0 (default: 0.1) */
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Dependencies
|
|
2
|
+
node_modules
|
|
3
|
+
|
|
4
|
+
# Build outputs
|
|
5
|
+
dist
|
|
6
|
+
build
|
|
7
|
+
out
|
|
8
|
+
.next
|
|
9
|
+
.nuxt
|
|
10
|
+
|
|
11
|
+
# Cache directories
|
|
12
|
+
.cache
|
|
13
|
+
.vite
|
|
14
|
+
.turbo
|
|
15
|
+
.parcel-cache
|
|
16
|
+
|
|
17
|
+
# Test coverage
|
|
18
|
+
coverage
|
|
19
|
+
|
|
20
|
+
# Package manager locks (optional - some prefer to format these)
|
|
21
|
+
pnpm-lock.yaml
|
|
22
|
+
package-lock.json
|
|
23
|
+
yarn.lock
|
|
24
|
+
|
|
25
|
+
# Auto-generated files
|
|
26
|
+
*.min.js
|
|
27
|
+
*.min.css
|
|
28
|
+
|
|
29
|
+
# IDE and editor
|
|
30
|
+
.idea
|
|
31
|
+
.vscode
|
|
32
|
+
|
|
33
|
+
# OS files
|
|
34
|
+
.DS_Store
|
|
35
|
+
Thumbs.db
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kabran Configuration File
|
|
3
|
+
*
|
|
4
|
+
* This file customizes the behavior of kabran-config validators and tools.
|
|
5
|
+
* All settings are optional - defaults are applied for any missing values.
|
|
6
|
+
*
|
|
7
|
+
* @see https://github.com/kabran-owner/kabran-config
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** @type {import('@kabran-tecnologia/kabran-config/core/config-loader').KabranConfig} */
|
|
11
|
+
export default {
|
|
12
|
+
/**
|
|
13
|
+
* README Validator Configuration
|
|
14
|
+
*
|
|
15
|
+
* Customize which sections are required and recommended in your README.md
|
|
16
|
+
*/
|
|
17
|
+
readme: {
|
|
18
|
+
// Sections that MUST be present (validation fails if missing)
|
|
19
|
+
required: ['Installation', 'Usage', 'License'],
|
|
20
|
+
|
|
21
|
+
// Sections that SHOULD be present (warning if missing)
|
|
22
|
+
recommended: ['Development', 'Testing', 'Contributing'],
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Environment Validator Configuration
|
|
27
|
+
*
|
|
28
|
+
* Customize how environment variable usage is detected
|
|
29
|
+
*/
|
|
30
|
+
env: {
|
|
31
|
+
// Require .env.example file if env vars are detected
|
|
32
|
+
requireExample: true,
|
|
33
|
+
|
|
34
|
+
// Patterns to search for when detecting env var usage
|
|
35
|
+
detectPatterns: [
|
|
36
|
+
'process.env', // Node.js
|
|
37
|
+
'import.meta.env', // Vite/ESM
|
|
38
|
+
'Deno.env', // Deno
|
|
39
|
+
'os.getenv', // Python
|
|
40
|
+
'$_ENV', // PHP
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Quality Standard Validator Configuration
|
|
46
|
+
*
|
|
47
|
+
* Customize the location of your quality standard documentation
|
|
48
|
+
*/
|
|
49
|
+
quality: {
|
|
50
|
+
// Path to quality standard file (relative to project root)
|
|
51
|
+
standardPath: 'docs/quality/001-quality-standard.md',
|
|
52
|
+
},
|
|
53
|
+
};
|
package/CI-CD-MIGRATION.md
DELETED
|
@@ -1,388 +0,0 @@
|
|
|
1
|
-
# CI/CD Migration Guide
|
|
2
|
-
|
|
3
|
-
This guide helps you migrate existing CI/CD scripts to use `@kabran-owner/kabran-config` standardized scripts.
|
|
4
|
-
|
|
5
|
-
## Before/After Comparison
|
|
6
|
-
|
|
7
|
-
### Before (Old Pattern)
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
# scripts/ci.sh - 250 lines mixing logic + config
|
|
11
|
-
#!/usr/bin/env bash
|
|
12
|
-
set -euo pipefail
|
|
13
|
-
|
|
14
|
-
# Define colors
|
|
15
|
-
RED='\033[0;31m'
|
|
16
|
-
GREEN='\033[0;32m'
|
|
17
|
-
# ...
|
|
18
|
-
|
|
19
|
-
# Define logging functions
|
|
20
|
-
log_info() { ... }
|
|
21
|
-
log_error() { ... }
|
|
22
|
-
# ...
|
|
23
|
-
|
|
24
|
-
# Define execution function
|
|
25
|
-
run_step() { ... }
|
|
26
|
-
|
|
27
|
-
# CI steps (project-specific)
|
|
28
|
-
run_step "lint" "pnpm lint:ci"
|
|
29
|
-
run_step "test" "pnpm test:ci"
|
|
30
|
-
# ...
|
|
31
|
-
|
|
32
|
-
# Generate JSON output
|
|
33
|
-
echo "CI_RESULT_JSON: ..."
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
### After (New Pattern)
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
# scripts/ci.sh - 15 lines (wrapper)
|
|
40
|
-
#!/usr/bin/env bash
|
|
41
|
-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
42
|
-
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
43
|
-
RUNNER="$PROJECT_ROOT/node_modules/@kabran-owner/kabran-config/src/scripts/ci/ci-runner.sh"
|
|
44
|
-
|
|
45
|
-
export PROJECT_ROOT="$PROJECT_ROOT"
|
|
46
|
-
export CI_CONFIG_FILE="$SCRIPT_DIR/ci-config.sh"
|
|
47
|
-
exec bash "$RUNNER" "$@"
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
# scripts/ci-config.sh - 60 lines (config only)
|
|
52
|
-
#!/usr/bin/env bash
|
|
53
|
-
PROJECT_NAME="my-project"
|
|
54
|
-
PM="pnpm"
|
|
55
|
-
|
|
56
|
-
ci_steps() {
|
|
57
|
-
run_step "lint" "cd '$PROJECT_ROOT' && $PM lint:ci" || FAILED=1
|
|
58
|
-
run_step "test" "cd '$PROJECT_ROOT' && $PM test:ci" || FAILED=1
|
|
59
|
-
run_step "build" "cd '$PROJECT_ROOT' && $PM build" || FAILED=2
|
|
60
|
-
return $FAILED
|
|
61
|
-
}
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## Migration Steps
|
|
65
|
-
|
|
66
|
-
### Step 1: Install kabran-config
|
|
67
|
-
|
|
68
|
-
```bash
|
|
69
|
-
npm install --save-dev @kabran-owner/kabran-config@^1.5.0
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### Step 2: Extract Configuration
|
|
73
|
-
|
|
74
|
-
1. Identify your CI steps in existing `scripts/ci.sh`
|
|
75
|
-
2. Create `scripts/ci-config.sh` with only config
|
|
76
|
-
3. Move step definitions to `ci_steps()` function
|
|
77
|
-
|
|
78
|
-
**Example extraction:**
|
|
79
|
-
|
|
80
|
-
```bash
|
|
81
|
-
# OLD scripts/ci.sh
|
|
82
|
-
run_step "format-check" "pnpm format:check"
|
|
83
|
-
run_step "lint" "pnpm lint:ci"
|
|
84
|
-
run_step "typecheck" "pnpm type-check"
|
|
85
|
-
|
|
86
|
-
# NEW scripts/ci-config.sh
|
|
87
|
-
ci_steps() {
|
|
88
|
-
run_step "format-check" "cd '$PROJECT_ROOT' && $PM format:check" || FAILED=1
|
|
89
|
-
run_step "lint" "cd '$PROJECT_ROOT' && $PM lint:ci" || FAILED=1
|
|
90
|
-
run_step "typecheck" "cd '$PROJECT_ROOT' && $PM type-check" || FAILED=1
|
|
91
|
-
return $FAILED
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### Step 3: Replace Wrapper
|
|
96
|
-
|
|
97
|
-
```bash
|
|
98
|
-
# Backup old script
|
|
99
|
-
mv scripts/ci.sh scripts/ci.sh.backup
|
|
100
|
-
|
|
101
|
-
# Create new wrapper
|
|
102
|
-
cat > scripts/ci.sh << 'EOF'
|
|
103
|
-
#!/usr/bin/env bash
|
|
104
|
-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
105
|
-
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
106
|
-
RUNNER="$PROJECT_ROOT/node_modules/@kabran-owner/kabran-config/src/scripts/ci/ci-runner.sh"
|
|
107
|
-
|
|
108
|
-
export PROJECT_ROOT="$PROJECT_ROOT"
|
|
109
|
-
export CI_CONFIG_FILE="$SCRIPT_DIR/ci-config.sh"
|
|
110
|
-
exec bash "$RUNNER" "$@"
|
|
111
|
-
EOF
|
|
112
|
-
|
|
113
|
-
chmod +x scripts/ci.sh
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
### Step 4: Test Locally
|
|
117
|
-
|
|
118
|
-
```bash
|
|
119
|
-
# Dry run
|
|
120
|
-
CI_VERBOSE=true bash scripts/ci.sh
|
|
121
|
-
|
|
122
|
-
# Check JSON output
|
|
123
|
-
cat .workspace/ci-result.json | jq .
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### Step 5: Validate in CI
|
|
127
|
-
|
|
128
|
-
Push to a test branch and verify GitHub Actions / bash-worker works correctly.
|
|
129
|
-
|
|
130
|
-
## Common Pitfalls
|
|
131
|
-
|
|
132
|
-
### Path Issues
|
|
133
|
-
|
|
134
|
-
❌ **Wrong:**
|
|
135
|
-
```bash
|
|
136
|
-
run_step "lint" "pnpm lint:ci" # Runs in wrong directory
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
✅ **Correct:**
|
|
140
|
-
```bash
|
|
141
|
-
run_step "lint" "cd '$PROJECT_ROOT' && $PM lint:ci"
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
### Exit Code Handling
|
|
145
|
-
|
|
146
|
-
❌ **Wrong:**
|
|
147
|
-
```bash
|
|
148
|
-
ci_steps() {
|
|
149
|
-
run_step "build" "pnpm build" # Doesn't track failure
|
|
150
|
-
}
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
✅ **Correct:**
|
|
154
|
-
```bash
|
|
155
|
-
ci_steps() {
|
|
156
|
-
run_step "build" "cd '$PROJECT_ROOT' && $PM build" || FAILED=2
|
|
157
|
-
return $FAILED
|
|
158
|
-
}
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### Missing PM Variable
|
|
162
|
-
|
|
163
|
-
❌ **Wrong:**
|
|
164
|
-
```bash
|
|
165
|
-
# ci-config.sh without PM
|
|
166
|
-
ci_steps() {
|
|
167
|
-
run_step "lint" "npm run lint" # Hardcoded npm
|
|
168
|
-
}
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
✅ **Correct:**
|
|
172
|
-
```bash
|
|
173
|
-
PM="npm" # Or pnpm, yarn
|
|
174
|
-
|
|
175
|
-
ci_steps() {
|
|
176
|
-
run_step "lint" "cd '$PROJECT_ROOT' && $PM run lint"
|
|
177
|
-
}
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
## Rollback Procedure
|
|
181
|
-
|
|
182
|
-
If migration fails:
|
|
183
|
-
|
|
184
|
-
```bash
|
|
185
|
-
# Restore old script
|
|
186
|
-
mv scripts/ci.sh.backup scripts/ci.sh
|
|
187
|
-
|
|
188
|
-
# Remove kabran-config (optional)
|
|
189
|
-
npm uninstall @kabran-owner/kabran-config
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
## Project-Specific Examples
|
|
193
|
-
|
|
194
|
-
### Tricket (Monorepo with pnpm)
|
|
195
|
-
|
|
196
|
-
```bash
|
|
197
|
-
#!/usr/bin/env bash
|
|
198
|
-
PROJECT_NAME="tricket-monorepo"
|
|
199
|
-
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/..\" && pwd)"
|
|
200
|
-
PM="pnpm"
|
|
201
|
-
|
|
202
|
-
ci_steps() {
|
|
203
|
-
run_step "format-check" "cd '$PROJECT_ROOT' && $PM format:check" || FAILED=1
|
|
204
|
-
run_step "lint" "cd '$PROJECT_ROOT' && $PM lint:ci" || FAILED=1
|
|
205
|
-
run_step "typecheck" "cd '$PROJECT_ROOT' && $PM type-check" || FAILED=1
|
|
206
|
-
run_step "test" "cd '$PROJECT_ROOT' && $PM test:ci" || FAILED=1
|
|
207
|
-
run_step "build" "cd '$PROJECT_ROOT' && $PM build" || FAILED=2
|
|
208
|
-
return $FAILED
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
ci_metadata() {
|
|
212
|
-
jq -n \
|
|
213
|
-
--arg node_version "$(node --version)" \
|
|
214
|
-
--arg pm_version "$($PM --version)" \
|
|
215
|
-
--arg steps "format-check,lint,typecheck,test,build" \
|
|
216
|
-
'{
|
|
217
|
-
node_version: $node_version,
|
|
218
|
-
pnpm_version: $pm_version,
|
|
219
|
-
steps_completed: ($steps | split(","))
|
|
220
|
-
}'
|
|
221
|
-
}
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
### CIE (Multi-Component with Doppler)
|
|
225
|
-
|
|
226
|
-
```bash
|
|
227
|
-
#!/usr/bin/env bash
|
|
228
|
-
PROJECT_NAME="cie-monorepo"
|
|
229
|
-
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/..\" && pwd)"
|
|
230
|
-
FRONTEND_DIR="$PROJECT_ROOT/frontend"
|
|
231
|
-
CMS_DIR="$PROJECT_ROOT/cms"
|
|
232
|
-
WEBSITE_DIR="$PROJECT_ROOT/website"
|
|
233
|
-
PM="npm"
|
|
234
|
-
|
|
235
|
-
ci_steps() {
|
|
236
|
-
# Frontend
|
|
237
|
-
log_section "PART 1: FRONTEND CI (React + Vite)"
|
|
238
|
-
run_step "frontend-format" "cd '$FRONTEND_DIR' && $PM run format:ci" || FAILED=1
|
|
239
|
-
run_step "frontend-lint" "cd '$FRONTEND_DIR' && $PM run lint" || FAILED=1
|
|
240
|
-
run_step "frontend-typecheck" "cd '$FRONTEND_DIR' && $PM run type-check" || FAILED=1
|
|
241
|
-
run_step "frontend-test" "cd '$FRONTEND_DIR' && $PM run test:ci" "$FRONTEND_DIR/test-results.json" || FAILED=1
|
|
242
|
-
run_step "frontend-build" "cd '$FRONTEND_DIR' && $PM run build" || FAILED=2
|
|
243
|
-
|
|
244
|
-
# CMS
|
|
245
|
-
log_section "PART 2: CMS CI (Next.js + PayloadCMS)"
|
|
246
|
-
run_step "cms-typecheck" "cd '$CMS_DIR' && $PM run typecheck" || FAILED=1
|
|
247
|
-
run_step "cms-build" "cd '$CMS_DIR' && doppler run -- $PM run build" || FAILED=2
|
|
248
|
-
|
|
249
|
-
# Website
|
|
250
|
-
log_section "PART 3: WEBSITE CI (React + Vite)"
|
|
251
|
-
run_step "website-format" "cd '$WEBSITE_DIR' && $PM run format:ci" || FAILED=1
|
|
252
|
-
run_step "website-lint" "cd '$WEBSITE_DIR' && $PM run lint" || FAILED=1
|
|
253
|
-
run_step "website-typecheck" "cd '$WEBSITE_DIR' && $PM run type-check" || FAILED=1
|
|
254
|
-
run_step "website-test" "cd '$WEBSITE_DIR' && $PM run test:ci" "$WEBSITE_DIR/test-results.json" || FAILED=1
|
|
255
|
-
run_step "website-build" "cd '$WEBSITE_DIR' && $PM run build" || FAILED=2
|
|
256
|
-
|
|
257
|
-
return $FAILED
|
|
258
|
-
}
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
### Kabran-app (with Supabase)
|
|
262
|
-
|
|
263
|
-
```bash
|
|
264
|
-
#!/usr/bin/env bash
|
|
265
|
-
PROJECT_NAME="kabran-app"
|
|
266
|
-
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/..\" && pwd)"
|
|
267
|
-
SUPABASE_DIR="$PROJECT_ROOT/supabase"
|
|
268
|
-
PM="npm"
|
|
269
|
-
|
|
270
|
-
SUPABASE_STARTED=false
|
|
271
|
-
|
|
272
|
-
cleanup_supabase() {
|
|
273
|
-
if [ "$SUPABASE_STARTED" = "true" ]; then
|
|
274
|
-
log_warn "Cleaning up Supabase containers..."
|
|
275
|
-
cd "$PROJECT_ROOT" 2>/dev/null && supabase stop 2>/dev/null || true
|
|
276
|
-
fi
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
trap cleanup_supabase EXIT
|
|
280
|
-
|
|
281
|
-
has_migrations_changed() {
|
|
282
|
-
local base_branch="${CI_BASE_BRANCH:-main}"
|
|
283
|
-
|
|
284
|
-
if ! git rev-parse --git-dir > /dev/null 2>&1; then
|
|
285
|
-
return 1
|
|
286
|
-
fi
|
|
287
|
-
|
|
288
|
-
git fetch origin "$base_branch" --quiet 2>/dev/null || true
|
|
289
|
-
|
|
290
|
-
if git diff --name-only "origin/${base_branch}...HEAD" 2>/dev/null | grep -qE "^(supabase/migrations/|supabase/functions/)"; then
|
|
291
|
-
return 0
|
|
292
|
-
fi
|
|
293
|
-
|
|
294
|
-
return 1
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
ci_steps() {
|
|
298
|
-
# Frontend CI
|
|
299
|
-
log_section "PART 1: FRONTEND CI"
|
|
300
|
-
run_step "lint" "cd '$PROJECT_ROOT' && $PM run lint -w @kabran/web -- --max-warnings=0" || FAILED=1
|
|
301
|
-
run_step "typecheck" "cd '$PROJECT_ROOT' && $PM run type-check" || FAILED=1
|
|
302
|
-
run_step "test" "cd '$PROJECT_ROOT' && $PM run test -w @kabran/web -- run" || FAILED=1
|
|
303
|
-
run_step "build" "cd '$PROJECT_ROOT' && $PM run build" || FAILED=2
|
|
304
|
-
|
|
305
|
-
# Database CI (Conditional)
|
|
306
|
-
if has_migrations_changed; then
|
|
307
|
-
log_section "PART 2: DATABASE CI (Supabase Migrations)"
|
|
308
|
-
|
|
309
|
-
if ! run_step "supabase-start" "cd '$PROJECT_ROOT' && supabase start"; then
|
|
310
|
-
FAILED=2
|
|
311
|
-
supabase stop 2>/dev/null || true
|
|
312
|
-
else
|
|
313
|
-
SUPABASE_STARTED=true
|
|
314
|
-
|
|
315
|
-
run_step "supabase-migrations" "cd '$PROJECT_ROOT' && supabase db reset --linked=false" || FAILED=1
|
|
316
|
-
|
|
317
|
-
if ! run_step "supabase-stop" "cd '$PROJECT_ROOT' && supabase stop"; then
|
|
318
|
-
log_warn "Failed to stop Supabase cleanly"
|
|
319
|
-
fi
|
|
320
|
-
SUPABASE_STARTED=false
|
|
321
|
-
fi
|
|
322
|
-
else
|
|
323
|
-
log_info "No migrations/functions changed, skipping database CI"
|
|
324
|
-
fi
|
|
325
|
-
|
|
326
|
-
return $FAILED
|
|
327
|
-
}
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
## Deploy Migration
|
|
331
|
-
|
|
332
|
-
### Before
|
|
333
|
-
|
|
334
|
-
```bash
|
|
335
|
-
# scripts/deploy.sh - 300+ lines
|
|
336
|
-
# (manual JSON parsing, stack execution, etc.)
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
### After
|
|
340
|
-
|
|
341
|
-
```bash
|
|
342
|
-
# scripts/deploy.sh - 15 lines
|
|
343
|
-
#!/usr/bin/env bash
|
|
344
|
-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
345
|
-
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
346
|
-
RUNNER="$PROJECT_ROOT/node_modules/@kabran-owner/kabran-config/src/scripts/deploy/deploy-runner.sh"
|
|
347
|
-
|
|
348
|
-
export PROJECT_ROOT="$PROJECT_ROOT"
|
|
349
|
-
export SCRIPT_DIR="$SCRIPT_DIR"
|
|
350
|
-
export DEPLOY_CONFIG_FILE="$SCRIPT_DIR/deploy.json"
|
|
351
|
-
|
|
352
|
-
exec bash "$RUNNER" "$@"
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
```json
|
|
356
|
-
{
|
|
357
|
-
"project": "my-project",
|
|
358
|
-
"version": "1.0.0",
|
|
359
|
-
"stacks": [
|
|
360
|
-
{
|
|
361
|
-
"name": "api",
|
|
362
|
-
"type": "backend",
|
|
363
|
-
"path": "../apps/api/docker",
|
|
364
|
-
"script": "api-deploy.sh",
|
|
365
|
-
"condition": {
|
|
366
|
-
"type": "path_changed",
|
|
367
|
-
"paths": ["apps/api/", "packages/"]
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
],
|
|
371
|
-
"settings": {
|
|
372
|
-
"timeout_seconds": 300,
|
|
373
|
-
"skip_unchanged": true
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
## Support
|
|
379
|
-
|
|
380
|
-
Issues? Check:
|
|
381
|
-
1. kabran-config README.md
|
|
382
|
-
2. Example configs in this migration guide
|
|
383
|
-
3. Create issue in nexus repo
|
|
384
|
-
|
|
385
|
-
---
|
|
386
|
-
|
|
387
|
-
**Version:** 1.5.0
|
|
388
|
-
**Last Updated:** 2026-01-12
|