wetwire_gitlab_go

package module
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 1 Imported by: 0

README

wetwire-gitlab (Go)

CI codecov Go Reference Go Report Card

Generate GitLab CI/CD configuration from Go pipeline declarations using a declarative, type-safe syntax.

Status

v0.0.0 - In Development

See Implementation Roadmap for progress.

For the wetwire pattern, see the Wetwire Specification.

The No-Parens Principle

Wetwire uses flat struct declarations with direct variable references — no wrapper functions, no registration calls, no constructors:

// References are variable names, not function calls
Needs: []any{BuildJob}           // NOT: Needs(BuildJob)

// Nested configs are separate variables
Artifacts: BuildArtifacts        // NOT: Artifacts(&Artifacts{...})

// Predefined variables via field access
If: CI.DefaultBranch             // NOT: If("$CI_DEFAULT_BRANCH")

Quick Start

package ci

import (
    . "github.com/lex00/wetwire-gitlab-go/intrinsics"  // Dot-import for helpers
    "github.com/lex00/wetwire-gitlab-go/pipeline"       // Core types
    "github.com/lex00/wetwire-gitlab-go/components/sast"
)

// Stages as flat declaration
var Stages = List("build", "test", "deploy")

// Nested config extracted to separate variable
var BuildArtifacts = pipeline.Artifacts{
    Paths:    List("bin/"),
    ExpireIn: "1 week",
}

// Image config extracted
var GolangImage = pipeline.Image{
    Name: "golang:1.23",
}

// Job with direct references — no function calls
var BuildJob = pipeline.Job{
    Name:      "build",
    Stage:     "build",
    Image:     GolangImage,
    Script:    List("go build -v ./..."),
    Artifacts: BuildArtifacts,
}

// Use pre-defined rules from intrinsics (dot-imported)
var TestJob = pipeline.Job{
    Name:   "test",
    Stage:  "test",
    Image:  GolangImage,
    Script: List("go test -v ./..."),
    Needs:  []any{BuildJob},
    Rules:  List(OnDefaultBranch),
}

// Typed component wrapper
var SecurityScan = sast.SAST{
    Stage: "test",
}

// Deploy with environment
var DeployEnv = pipeline.Environment{
    Name: "production",
    URL:  "https://example.com",
}

// Rule extracted to separate variable
var OnTagRule = pipeline.Rule{
    If:   CI.CommitTag,
    When: Always,
}

var DeployJob = pipeline.Job{
    Name:        "deploy",
    Stage:       "deploy",
    Script:      List("./deploy.sh"),
    Environment: DeployEnv,
    Needs:       []any{TestJob, SecurityScan},
    Rules:       List(OnTagRule),
}

Generate configuration:

wetwire-gitlab build ./ci > .gitlab-ci.yml

Output:

stages:
  - build
  - test
  - deploy

build:
  stage: build
  image: golang:1.23
  script:
    - go build -v ./...
  artifacts:
    paths:
      - bin/
    expire_in: 1 week

test:
  stage: test
  image: golang:1.23
  script:
    - go test -v ./...
  needs:
    - build
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
      when: always

deploy:
  stage: deploy
  script:
    - ./deploy.sh
  environment:
    name: production
    url: https://example.com
  needs:
    - test
    - sast
  rules:
    - if: $CI_COMMIT_TAG
      when: always

Installation

go install github.com/lex00/wetwire-gitlab-go/cmd/wetwire-gitlab@latest

AI-Assisted Design (Kiro CLI)

Use Kiro CLI for AI-assisted pipeline design:

# Install Kiro CLI
curl -fsSL https://cli.kiro.dev/install | bash

# Start AI-assisted design session
wetwire-gitlab design --provider kiro "Create a CI/CD pipeline for a Go microservice"

The design command automatically configures the Kiro agent and launches an interactive session where Claude can use MCP tools (wetwire_init, wetwire_lint, wetwire_build) to help design your pipeline.

See GITLAB-KIRO-CLI.md for complete setup and usage guide.

CLI Commands

Command Status Description
build ✅ Done Generate .gitlab-ci.yml from Go definitions
validate ✅ Done Validate via glab ci lint
list ✅ Done List discovered pipelines/jobs
lint ✅ Done Check Go code for quality issues (27 rules)
import ✅ Done Import existing .gitlab-ci.yml to Go
graph ✅ Done Generate DAG visualization (DOT/Mermaid)
design ✅ Done AI-assisted pipeline design
test ✅ Done Persona-based testing
init ✅ Done Initialize new project
version ✅ Done Print version information

Core Concepts

Flat Declarations

Every job/config is a top-level var with a struct literal:

var MyJob = pipeline.Job{
    Name:   "my-job",
    Script: List("echo hello"),
}
Direct References

Job dependencies use variable names directly:

var TestJob = pipeline.Job{
    Needs: []any{BuildJob, LintJob},  // Variable references
}
Extracted Nested Config

Complex nested structures become separate variables:

// Instead of inline nesting
var CacheConfig = pipeline.Cache{
    Key:   "deps-${CI_COMMIT_REF_SLUG}",
    Paths: List("vendor/", ".cache/"),
}

var MyJob = pipeline.Job{
    Cache: CacheConfig,  // Reference extracted config
}
Predefined Variables

Type-safe access via intrinsics package (dot-imported):

var DeployRule = pipeline.Rule{
    If: CI.CommitTag,  // $CI_COMMIT_TAG
}

var NotifyRule = pipeline.Rule{
    If: CI.PipelineSource.Eq("merge_request_event"),
}

// Pre-defined rules for common patterns
var TestJob = pipeline.Job{
    Rules: List(OnDefaultBranch),  // if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
}

Package Structure

wetwire-gitlab-go/
├── cmd/wetwire-gitlab/       # CLI application
├── internal/
│   ├── agent/                # Tool definitions for orchestrator integration
│   ├── discover/             # AST-based pipeline discovery
│   ├── importer/             # YAML to Go code conversion
│   ├── linter/               # Go code lint rules (WGL001-WGL012)
│   ├── reference/            # Round-trip testing utilities
│   ├── runner/               # Runtime value extraction
│   ├── serialize/            # YAML serialization
│   ├── template/             # Pipeline builder with topological sort
│   └── validation/           # glab ci lint integration
├── pipeline/                 # Core pipeline types (Job, Rule, Artifacts...)
├── intrinsics/               # Helpers for dot-import (CI.*, OnDefaultBranch...)
├── components/               # Generated component wrappers (SAST, DAST, etc.)
├── templates/                # Auto DevOps template wrappers
├── runner/                   # GitLab Runner config.toml types
├── codegen/                  # Schema fetching, parsing, code generation
├── testdata/                 # Sample pipelines for testing
├── contracts.go              # Core interfaces
└── scripts/
    ├── ci.sh                 # Local CI script
    └── import_samples.sh     # Fetch gitlab-org samples
Package Design

The importer/init commands generate packages with strategic imports for clean syntax:

import (
    . "github.com/lex00/wetwire-gitlab-go/intrinsics"  // Dot-import: CI.*, OnDefaultBranch, etc.
    "github.com/lex00/wetwire-gitlab-go/pipeline"       // Prefixed: pipeline.Job, pipeline.Rule
)

intrinsics/ (dot-imported for clean syntax):

  • Json — type alias for map[string]any
  • List[T]() — create any typed slice (use for all slices except []any)
  • CI, GitLab, MR — predefined variable namespaces
  • OnDefaultBranch, OnTag, ManualOnly — pre-defined rules
  • Always, Never, OnSuccess, OnFailure, Manual — when values

pipeline/ (explicit namespace):

  • pipeline.Job, pipeline.Rule, pipeline.Artifacts — core types
  • Explicit prefix prevents collisions with user-defined variables

Development

# Run tests
go test -v ./...

# Run CI checks
./scripts/ci.sh

# Build CLI
go build -o wetwire-gitlab ./cmd/wetwire-gitlab

Documentation

License

MIT - See LICENSE for details.

Documentation

Overview

Package wetwire_gitlab_go provides types and interfaces for GitLab CI/CD pipeline synthesis.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildResult

type BuildResult struct {
	Success  bool     `json:"success"`
	Output   string   `json:"output,omitempty"`
	Errors   []string `json:"errors,omitempty"`
	FilePath string   `json:"file_path,omitempty"`
}

BuildResult represents the result of a build operation.

type DiscoveredJob

type DiscoveredJob struct {
	Name         string   `json:"name"`
	VariableName string   `json:"variable_name"`
	FilePath     string   `json:"file_path"`
	Line         int      `json:"line"`
	Dependencies []string `json:"dependencies,omitempty"`
}

DiscoveredJob represents a job discovered from Go source code.

type DiscoveredPipeline

type DiscoveredPipeline struct {
	Name         string          `json:"name"`
	VariableName string          `json:"variable_name"`
	FilePath     string          `json:"file_path"`
	Line         int             `json:"line"`
	Jobs         []DiscoveredJob `json:"jobs,omitempty"`
}

DiscoveredPipeline represents a pipeline discovered from Go source code.

type JobRef

type JobRef struct {
	Job       string `json:"job,omitempty"`
	Artifacts bool   `json:"artifacts,omitempty"`
	Optional  bool   `json:"optional,omitempty"`
}

JobRef represents a reference to another job for needs/dependencies.

func (JobRef) IsZero

func (r JobRef) IsZero() bool

IsZero returns true if JobRef is empty (has no job name).

func (JobRef) MarshalJSON

func (r JobRef) MarshalJSON() ([]byte, error)

MarshalJSON serializes JobRef to GitLab CI needs format. Simple references are serialized as strings, complex ones as objects.

type LintIssue

type LintIssue struct {
	RuleID     string `json:"rule_id"`
	Message    string `json:"message"`
	FilePath   string `json:"file_path"`
	Line       int    `json:"line"`
	Column     int    `json:"column,omitempty"`
	Severity   string `json:"severity"`
	Fixable    bool   `json:"fixable,omitempty"`
	Suggestion string `json:"suggestion,omitempty"`
}

LintIssue represents a single lint issue.

type LintResult

type LintResult struct {
	Success bool        `json:"success"`
	Issues  []LintIssue `json:"issues,omitempty"`
}

LintResult represents the result of a lint operation.

type ListResult

type ListResult struct {
	Pipelines []DiscoveredPipeline `json:"pipelines,omitempty"`
	Jobs      []DiscoveredJob      `json:"jobs,omitempty"`
}

ListResult represents the result of a list operation.

type Resource

type Resource interface {
	// ResourceType returns the type name of the resource.
	ResourceType() string
}

Resource is the interface for all pipeline resources.

type ValidateResult

type ValidateResult struct {
	Valid      bool     `json:"valid"`
	Errors     []string `json:"errors,omitempty"`
	Warnings   []string `json:"warnings,omitempty"`
	MergedYAML string   `json:"merged_yaml,omitempty"`
}

ValidateResult represents the result of a validation operation.

Directories

Path Synopsis
cmd
wetwire-gitlab command
Package main provides adapter implementations for wetwire-core-go command interfaces.
Package main provides adapter implementations for wetwire-core-go command interfaces.
Package codegen provides code generation tooling for GitLab CI/CD types.
Package codegen provides code generation tooling for GitLab CI/CD types.
Package components provides typed Go wrappers for GitLab CI/CD components.
Package components provides typed Go wrappers for GitLab CI/CD components.
examples
no_gomod
Example pipeline without requiring go.mod Run: wetwire-gitlab build .
Example pipeline without requiring go.mod Run: wetwire-gitlab build .
matrix-builds module
internal
agent
Package agent provides tool definitions and handlers for wetwire-core-go integration.
Package agent provides tool definitions and handlers for wetwire-core-go integration.
artifacts
Package artifacts provides analysis and optimization for GitLab CI/CD artifact configurations.
Package artifacts provides analysis and optimization for GitLab CI/CD artifact configurations.
discover
Package discover provides AST-based pipeline and job discovery from Go source files.
Package discover provides AST-based pipeline and job discovery from Go source files.
export
Package export provides conversion from GitLab CI to other CI/CD formats.
Package export provides conversion from GitLab CI to other CI/CD formats.
graph
Package graph provides DAG graph generation for pipeline visualization.
Package graph provides DAG graph generation for pipeline visualization.
importer
Package importer provides YAML parsing for converting existing .gitlab-ci.yml files to an intermediate representation for Go code generation.
Package importer provides YAML parsing for converting existing .gitlab-ci.yml files to an intermediate representation for Go code generation.
linter
Package linter provides Go code quality rules for wetwire pipeline definitions.
Package linter provides Go code quality rules for wetwire pipeline definitions.
optimizer
Package optimizer provides pipeline optimization analysis.
Package optimizer provides pipeline optimization analysis.
profile
Package profile provides performance analysis for GitLab CI/CD pipelines.
Package profile provides performance analysis for GitLab CI/CD pipelines.
reference
Package reference provides testing utilities for validating pipeline import/build round-trips against real GitLab CI examples.
Package reference provides testing utilities for validating pipeline import/build round-trips against real GitLab CI examples.
runner
Package runner provides runtime value extraction via temporary Go program generation.
Package runner provides runtime value extraction via temporary Go program generation.
schema
Package schema provides offline schema validation for GitLab CI/CD pipelines.
Package schema provides offline schema validation for GitLab CI/CD pipelines.
serialize
Package serialize provides YAML serialization for GitLab CI/CD pipeline types.
Package serialize provides YAML serialization for GitLab CI/CD pipeline types.
template
Package template provides pipeline YAML building with topological sorting for correct job dependency ordering.
Package template provides pipeline YAML building with topological sorting for correct job dependency ordering.
validation
Package validation provides GitLab CI YAML validation using glab CLI.
Package validation provides GitLab CI YAML validation using glab CLI.
Package intrinsics provides helper types, functions, and predefined constants for GitLab CI/CD pipeline definitions.
Package intrinsics provides helper types, functions, and predefined constants for GitLab CI/CD pipeline definitions.
Package pipeline provides core types for GitLab CI/CD pipeline definitions.
Package pipeline provides core types for GitLab CI/CD pipeline definitions.
Package runner provides types for GitLab Runner config.toml configuration.
Package runner provides types for GitLab Runner config.toml configuration.
Package templates provides typed wrappers for GitLab CI/CD templates.
Package templates provides typed wrappers for GitLab CI/CD templates.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL