Skip to content

Commit 05df231

Browse files
authored
🚀 Major Refactor: Enhanced Type Safety & GitLab CI Support (#10)
* init refactor the builder * feat: Add schema definitions for policies, specs, steps, and workflows - Implemented Zod schemas for global options, job options, validation metadata, and missing extends policy. - Created schemas for base input, job inputs, pages configuration, and step definitions. - Added workflow rule and workflow configuration schemas. - Developed YAML serializer with custom handling for references and ordering of pipeline keys. - Enhanced tests for merge rules, pipeline state, schema transforms, and validation coverage. * feat: Refactor job schema and enhance test coverage for extends functionality * feat: Update README for clarity and consistency * feat: Enhance template handling in ConfigBuilder to default mergeExtends to false * feat: Update merge strategy for variables to use deep merge and enhance extends resolution tests
1 parent 4494482 commit 05df231

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+9644
-2663
lines changed

.changeset/plain-beers-win.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
"@noxify/gitlab-ci-builder": major
3+
---
4+
5+
Major Release: Improved Type Safety and GitLab CI Compatibility
6+
7+
This release brings significant improvements to type safety, extends resolution, and compatibility with complex GitLab CI configurations.
8+
9+
## Breaking Changes
10+
11+
### Architecture Refactoring
12+
13+
The internal architecture has been completely refactored for better type safety and reliability:
14+
15+
- **Type System**: Job definitions now use explicit input/output types (`JobDefinitionInput`, `JobDefinitionNormalized`, `JobDefinitionOutput`) instead of a single `JobDefinition` type. This provides better IntelliSense support and catches errors at compile time.
16+
- **Extends Resolution**: Completely rewritten extends resolution with proper topological sorting, cycle detection, and merge strategies that match GitLab CI's behavior.
17+
- **State Management**: New internal `PipelineState` model for cleaner separation of concerns and better maintainability.
18+
19+
### What This Means for You
20+
21+
If you're using TypeScript, you may need to update type annotations that reference the old `JobDefinition` type. However, the **public API remains the same** - all existing code using `ConfigBuilder` should continue to work without changes.
22+
23+
## What's New
24+
25+
### Enhanced GitLab CI Compatibility
26+
27+
- **Complex Script Support**: Full support for multiline scripts with shell operators, heredocs, and GitLab CI variables
28+
29+
```typescript
30+
config.job("release", {
31+
before_script: [
32+
"npm ci --cache .npm --prefer-offline",
33+
`{
34+
echo "@\${CI_PROJECT_ROOT_NAMESPACE}:registry=\${CI_API_V4_URL}/projects/\${CI_PROJECT_ID}/packages/npm/"
35+
echo "\${CI_API_V4_URL#https?}/projects/\${CI_PROJECT_ID}/packages/npm/:_authToken=\${CI_JOB_TOKEN}"
36+
} | tee -a .npmrc`,
37+
],
38+
})
39+
```
40+
41+
- **Array Syntax Normalization**: Single-element arrays in `extends` are now properly normalized to strings, matching GitLab CI's behavior
42+
43+
```yaml
44+
# Input YAML
45+
job:
46+
extends: [.base] # Single-element array
47+
48+
# Now correctly outputs
49+
job:
50+
extends: .base # Normalized to string
51+
```
52+
53+
- **Parallel Matrix Support**: Fixed schema to accept string, number, and array values for `parallel.matrix`, supporting all GitLab CI patterns
54+
```typescript
55+
config.job("test", {
56+
parallel: {
57+
matrix: [
58+
{ NODE_VERSION: "18" }, // String values ✓
59+
{ PARALLEL_COUNT: 3 }, // Number values ✓
60+
{ BROWSERS: ["chrome", "firefox"] }, // Array values ✓
61+
],
62+
},
63+
})
64+
```
65+
66+
### Import/Export Improvements
67+
68+
- **Variable Preservation**: GitLab CI variables like `${CI_COMMIT_BRANCH}` are now correctly preserved during YAML import/export cycles
69+
- **Template Literal Escaping**: Fixed double-escaping bug in generated TypeScript code for multiline scripts
70+
71+
### Better Type Safety
72+
73+
- **Explicit Types**: All pipeline components now have well-defined input and output types
74+
- **Union Type Handling**: Improved type guards for properties that can be strings or objects (like `environment`, `cache`, `needs`)
75+
- **Better IntelliSense**: More accurate autocomplete and type checking in your IDE
76+
77+
## Testing & Quality
78+
79+
- **241 tests** covering all functionality
80+
- **86%+ test coverage** with comprehensive real-world use case tests
81+
- New test suites for:
82+
- Complex script handling with GitLab CI variables
83+
- Merge strategies and extends resolution
84+
- Pipeline state management
85+
- Real-world deployment scenarios
86+
87+
## Migration Guide
88+
89+
For most users, no changes are required. However, if you have TypeScript code that references internal types:
90+
91+
**Before:**
92+
93+
```typescript
94+
import type { JobDefinition } from "@noxify/gitlab-ci-builder"
95+
const job: JobDefinition = { ... }
96+
```
97+
98+
**After:**
99+
100+
```typescript
101+
import type { JobDefinitionInput } from "@noxify/gitlab-ci-builder"
102+
const job: JobDefinitionInput = { ... }
103+
```
104+
105+
The public API (`ConfigBuilder` methods, import/export functions) remains fully compatible with previous versions.

.github/copilot-instructions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
- Add ESLint disable comments only when absolutely necessary
4242
- Follow the import order specified in prettier config
4343
- Use consistent naming conventions (camelCase for variables, PascalCase for types)
44-
- **Generic type parameters**: Always prefix with `T` (e.g., `TJobPayload`, `TResult`, `TEventData`)
44+
- **Generic type parameters**: Prefix generic type parameters with `T` for clarity (e.g., `GenericType<TPayload>`, `Handler<TResult, TError>`)
45+
- **Type/Interface names**: Use PascalCase without prefix (e.g., `JobDefinition`, `WorkflowRule`, `ConfigOptions`)
4546
- Prefer explicit return types for functions
4647
- Use proper error handling instead of throwing generic errors
4748
- Write self-documenting code that doesn't need excessive comments

0 commit comments

Comments
 (0)