Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit dc81a03

Browse files
committed
refactor: remove all legacy/backward compatibility code and docs
- Remove legacy format fallback from main_config_loader.go - Remove JSON export functions (ExportConfigAsJSON, ExportConfigAsYAML) - Remove ConfigTemplate and GetConfigTemplates functions - Remove 'convert' command from config-validator CLI tool - Remove all migration guides and legacy format references from docs - Update test to verify main config requires workflow_configs - Update FAQ to reflect current config structure - Remove all references to JSON conversion and legacy formats All tests passing (14/14 MainConfigLoader tests)
1 parent 303a2ee commit dc81a03

File tree

10 files changed

+22
-265
lines changed

10 files changed

+22
-265
lines changed

examples-copier/cmd/config-validator/README.md

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ The `config-validator` tool helps you:
1010
- Validate workflow configuration files
1111
- Test pattern matching
1212
- Test path transformations
13-
- Convert legacy JSON configs to YAML
1413
- Debug configuration issues
1514

1615
## Installation
@@ -178,38 +177,6 @@ Variables used:
178177
name = main
179178
```
180179

181-
### convert
182-
183-
Convert legacy JSON configuration to YAML format.
184-
185-
**Usage:**
186-
```bash
187-
./config-validator convert -input <file> -output <file>
188-
```
189-
190-
**Options:**
191-
- `-input` - Input JSON file (required)
192-
- `-output` - Output YAML file (required)
193-
194-
**Example:**
195-
196-
```bash
197-
./config-validator convert -input config.json -output workflow-config.yaml
198-
```
199-
200-
**Output:**
201-
```
202-
✅ Conversion successful!
203-
204-
Converted 2 legacy rules to YAML format.
205-
Output written to: workflow-config.yaml
206-
207-
Next steps:
208-
1. Review the generated workflow-config.yaml
209-
2. Enhance with new features (regex patterns, path transforms)
210-
3. Validate: ./config-validator validate -config workflow-config.yaml
211-
```
212-
213180
## Common Use Cases
214181

215182
### Debugging Pattern Matching
@@ -271,9 +238,6 @@ Before deploying a new configuration:
271238
### Migrating from JSON to YAML
272239

273240
```bash
274-
# Convert
275-
./config-validator convert -input config.json -output workflow-config.yaml
276-
277241
# Validate
278242
./config-validator validate -config workflow-config.yaml -v
279243

examples-copier/cmd/config-validator/main.go

Lines changed: 6 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ func main() {
2828

2929
initCmd := flag.NewFlagSet("init", flag.ExitOnError)
3030
initTemplate := initCmd.String("template", "basic", "Template to use: basic, glob, or regex")
31-
initOutput := initCmd.String("output", "copier-config.yaml", "Output file path")
32-
33-
convertCmd := flag.NewFlagSet("convert", flag.ExitOnError)
34-
convertInput := convertCmd.String("input", "", "Input config file (required)")
35-
convertOutput := convertCmd.String("output", "", "Output config file (required)")
31+
initOutput := initCmd.String("output", "workflow-config.yaml", "Output file path")
3632

3733
if len(os.Args) < 2 {
3834
printUsage()
@@ -71,40 +67,29 @@ func main() {
7167
initCmd.Parse(os.Args[2:])
7268
initConfig(*initTemplate, *initOutput)
7369

74-
case "convert":
75-
convertCmd.Parse(os.Args[2:])
76-
if *convertInput == "" || *convertOutput == "" {
77-
fmt.Println("Error: -input and -output are required")
78-
convertCmd.Usage()
79-
os.Exit(1)
80-
}
81-
convertConfig(*convertInput, *convertOutput)
82-
8370
default:
8471
printUsage()
8572
os.Exit(1)
8673
}
8774
}
8875

8976
func printUsage() {
90-
fmt.Println("Config Validator - Validate and test copier configurations")
77+
fmt.Println("Config Validator - Validate and test copier workflow configurations")
9178
fmt.Println()
9279
fmt.Println("Usage:")
9380
fmt.Println(" config-validator <command> [options]")
9481
fmt.Println()
9582
fmt.Println("Commands:")
96-
fmt.Println(" validate Validate a configuration file")
83+
fmt.Println(" validate Validate a workflow configuration file")
9784
fmt.Println(" test-pattern Test a pattern against a file path")
9885
fmt.Println(" test-transform Test a path transformation")
99-
fmt.Println(" init Initialize a new config file from template")
100-
fmt.Println(" convert Convert between JSON and YAML formats")
86+
fmt.Println(" init Initialize a new workflow config file from template")
10187
fmt.Println()
10288
fmt.Println("Examples:")
103-
fmt.Println(" config-validator validate -config copier-config.yaml -v")
89+
fmt.Println(" config-validator validate -config .copier/workflows/config.yaml -v")
10490
fmt.Println(" config-validator test-pattern -type glob -pattern 'examples/**/*.go' -file 'examples/go/main.go'")
10591
fmt.Println(" config-validator test-transform -source 'examples/go/main.go' -template 'code/${filename}'")
106-
fmt.Println(" config-validator init -template basic -output my-config.yaml")
107-
fmt.Println(" config-validator convert -input config.json -output config.yaml")
92+
fmt.Println(" config-validator init -template basic -output workflow-config.yaml")
10893
}
10994

11095
func validateConfig(configFile string, verbose bool) {
@@ -230,42 +215,3 @@ func initConfig(templateName, output string) {
230215
fmt.Printf("✅ Created config file: %s\n", output)
231216
fmt.Printf("Template: %s\n", selectedTemplate.Description)
232217
}
233-
234-
func convertConfig(input, output string) {
235-
content, err := os.ReadFile(input)
236-
if err != nil {
237-
fmt.Printf("❌ Error reading input file: %v\n", err)
238-
os.Exit(1)
239-
}
240-
241-
loader := services.NewConfigLoader()
242-
config, err := loader.LoadConfigFromContent(string(content), input)
243-
if err != nil {
244-
fmt.Printf("❌ Error parsing input file: %v\n", err)
245-
os.Exit(1)
246-
}
247-
248-
var outputContent string
249-
if strings.HasSuffix(output, ".yaml") || strings.HasSuffix(output, ".yml") {
250-
outputContent, err = services.ExportConfigAsYAML(config)
251-
} else if strings.HasSuffix(output, ".json") {
252-
outputContent, err = services.ExportConfigAsJSON(config)
253-
} else {
254-
fmt.Println("❌ Output file must have .yaml, .yml, or .json extension")
255-
os.Exit(1)
256-
}
257-
258-
if err != nil {
259-
fmt.Printf("❌ Error converting config: %v\n", err)
260-
os.Exit(1)
261-
}
262-
263-
err = os.WriteFile(output, []byte(outputContent), 0644)
264-
if err != nil {
265-
fmt.Printf("❌ Error writing output file: %v\n", err)
266-
os.Exit(1)
267-
}
268-
269-
fmt.Printf("✅ Converted %s to %s\n", input, output)
270-
}
271-

examples-copier/configs/copier-config-examples/MAIN-CONFIG-README.md

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -162,43 +162,6 @@ workflows:
162162
2. Trigger a webhook event (merge a PR in source repo)
163163
3. Verify workflows execute correctly
164164

165-
## Migration Guide
166-
167-
### From Legacy Format
168-
169-
If you have an existing `copier-config.yaml`:
170-
171-
#### Option 1: Keep Legacy Format (No Changes)
172-
173-
Don't set `MAIN_CONFIG_FILE` - the app will continue using the legacy format.
174-
175-
#### Option 2: Migrate to Main Config
176-
177-
1. **Create main config file**:
178-
```yaml
179-
defaults:
180-
# Copy defaults from legacy config
181-
182-
workflow_configs:
183-
- source: "inline"
184-
workflows:
185-
# Copy workflows from legacy config
186-
```
187-
188-
2. **Update env.yaml**:
189-
```yaml
190-
MAIN_CONFIG_FILE: "main-config.yaml"
191-
USE_MAIN_CONFIG: "true"
192-
```
193-
194-
3. **Test thoroughly** before deploying
195-
196-
#### Option 3: Gradual Migration
197-
198-
1. Start with inline workflows in main config
199-
2. Gradually move workflows to separate files
200-
3. Eventually move to distributed workflow configs
201-
202165
## Best Practices
203166

204167
### 1. Organization

examples-copier/configs/copier-config-examples/QUICK-START-MAIN-CONFIG.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -242,25 +242,6 @@ workflows:
242242
4. **Add more workflows**: Expand your configuration
243243
5. **Use reusable components**: Extract common configs
244244

245-
## Migration from Legacy Format
246-
247-
Already using `copier-config.yaml`? You have options:
248-
249-
### Option 1: Keep Legacy Format
250-
Don't change anything - legacy format still works!
251-
252-
### Option 2: Migrate Gradually
253-
1. Set `MAIN_CONFIG_FILE` to new file
254-
2. Use inline workflows initially
255-
3. Gradually move to separate files
256-
257-
### Option 3: Full Migration
258-
1. Create main config with workflow references
259-
2. Move workflows to source repos
260-
3. Update env.yaml
261-
4. Test thoroughly
262-
5. Deploy
263-
264245
## Support
265246

266247
- **Documentation**: `MAIN-CONFIG-README.md`

examples-copier/configs/copier-config-examples/main-config-example.yaml

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -166,29 +166,6 @@ workflow_configs:
166166
# - Clear separation between global and local settings
167167
#
168168
# ============================================================================
169-
# MIGRATION FROM LEGACY FORMAT
170-
# ============================================================================
171-
#
172-
# If you have an existing copier-config.yaml with workflows directly defined:
173-
#
174-
# OPTION 1: Keep using legacy format
175-
# - Don't set MAIN_CONFIG_FILE in env.yaml
176-
# - App will use legacy config loader
177-
# - No changes needed
178-
#
179-
# OPTION 2: Migrate to main config format
180-
# - Create this main config file
181-
# - Move workflows to separate workflow config files
182-
# - Set MAIN_CONFIG_FILE in env.yaml
183-
# - Set USE_MAIN_CONFIG=true in env.yaml
184-
#
185-
# OPTION 3: Hybrid approach
186-
# - Use inline workflows in main config
187-
# - Gradually migrate to separate workflow configs
188-
# - Start with simple workflows inline
189-
# - Move complex workflows to separate files
190-
#
191-
# ============================================================================
192169
# ENVIRONMENT VARIABLES
193170
# ============================================================================
194171
#

examples-copier/docs/ARCHITECTURE.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ targets:
243243

244244
**Files:**
245245
- `types/config.go` - Configuration types with $ref support
246-
- `services/config_loader.go` - Configuration loader with YAML/JSON support
246+
- `services/config_loader.go` - Configuration loader
247247
- `services/main_config_loader.go` - Main config loader with reference resolution
248248

249249
**Capabilities:**
@@ -412,10 +412,7 @@ config-validator test-transform \
412412
-template "code/${filename}"
413413
414414
# Initialize new config from template
415-
config-validator init -template basic -output my-copier-config.yaml
416-
417-
# Convert between formats
418-
config-validator convert -input config.json -output copier-config.yaml
415+
config-validator init -template basic -output my-workflow-config.yaml
419416
```
420417

421418
### 11. Development/Testing Features

examples-copier/docs/FAQ.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,11 @@ Yes. A file can match multiple workflows and be copied to multiple targets. This
7474
7575
### Where should I store the config file?
7676
77-
**For production:** Store `copier-config.yaml` in your source repository (the repo being monitored for PRs).
77+
**Main config:** Store in a central config repository and set `MAIN_CONFIG_FILE` in env.yaml.
7878

79-
**For local testing:** Store `copier-config.yaml` in the examples-copier directory and set `CONFIG_FILE=copier-config.yaml`.
79+
**Workflow configs:** Store in `.copier/workflows/config.yaml` in source repositories, or reference them from the main config.
8080

81-
### How do I migrate from JSON to YAML?
82-
83-
Use the config-validator tool:
84-
85-
```bash
86-
./config-validator convert -input config.json -output copier-config.yaml
87-
```
88-
89-
The tool will automatically convert your legacy JSON configuration to the new YAML format while preserving all settings.
81+
**For local testing:** Store config files in the examples-copier directory and set appropriate environment variables.
9082

9183
## Pattern Matching
9284

examples-copier/services/config_loader.go

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package services
22

33
import (
44
"context"
5-
"encoding/json"
65
"fmt"
76
"os"
87

@@ -147,58 +146,6 @@ func (cv *ConfigValidator) TestTransform(sourcePath string, template string, var
147146
return transformer.Transform(sourcePath, template, variables)
148147
}
149148

150-
// ExportConfigAsYAML exports a config as YAML string
151-
func ExportConfigAsYAML(config *types.YAMLConfig) (string, error) {
152-
data, err := yaml.Marshal(config)
153-
if err != nil {
154-
return "", fmt.Errorf("failed to marshal config to YAML: %w", err)
155-
}
156-
return string(data), nil
157-
}
158-
159-
// ExportConfigAsJSON exports a config as JSON string
160-
func ExportConfigAsJSON(config *types.YAMLConfig) (string, error) {
161-
data, err := json.MarshalIndent(config, "", " ")
162-
if err != nil {
163-
return "", fmt.Errorf("failed to marshal config to JSON: %w", err)
164-
}
165-
return string(data), nil
166-
}
167-
168-
// ConfigTemplate represents a configuration template
169-
type ConfigTemplate struct {
170-
Name string
171-
Description string
172-
Content string
173-
}
174-
175-
// GetConfigTemplates returns available configuration templates
176-
func GetConfigTemplates() []ConfigTemplate {
177-
return []ConfigTemplate{
178-
{
179-
Name: "basic-workflow",
180-
Description: "Basic workflow configuration",
181-
Content: `workflows:
182-
- name: "Copy examples"
183-
source:
184-
repo: "owner/source-repo"
185-
branch: "main"
186-
destination:
187-
repo: "owner/target-repo"
188-
branch: "main"
189-
transformations:
190-
- move:
191-
from: "examples"
192-
to: "code-examples"
193-
commit_strategy:
194-
type: "pull_request"
195-
pr_title: "Update code examples"
196-
pr_body: "Automated update from source repository"
197-
`,
198-
},
199-
}
200-
}
201-
202149
// loadLocalConfigFile attempts to load config from a local file
203150
// This is useful for local testing and development
204151
func loadLocalConfigFile(filename string) (string, error) {

examples-copier/services/main_config_loader.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,16 @@ func (mcl *DefaultMainConfigLoader) LoadMainConfigFromContent(ctx context.Contex
7575
return nil, fmt.Errorf("main config file is empty")
7676
}
7777

78-
// Try to parse as MainConfig first
78+
// Parse as MainConfig
7979
var mainConfig types.MainConfig
8080
err := yaml.Unmarshal([]byte(content), &mainConfig)
8181
if err != nil {
82-
// If it fails, try parsing as legacy YAMLConfig
83-
LogInfoCtx(ctx, "failed to parse as MainConfig, trying legacy YAMLConfig format", map[string]interface{}{
84-
"error": err.Error(),
85-
})
86-
return mcl.configLoader.LoadConfigFromContent(content, config.ConfigFile)
82+
return nil, fmt.Errorf("failed to parse main config: %w", err)
8783
}
8884

89-
// Check if this is actually a MainConfig (has workflow_configs)
85+
// Validate that workflow_configs is present
9086
if len(mainConfig.WorkflowConfigs) == 0 {
91-
// This is a legacy YAMLConfig format
92-
LogInfoCtx(ctx, "detected legacy YAMLConfig format (no workflow_configs)", nil)
93-
return mcl.configLoader.LoadConfigFromContent(content, config.ConfigFile)
87+
return nil, fmt.Errorf("main config must have at least one workflow_config entry")
9488
}
9589

9690
// Set defaults for main config

0 commit comments

Comments
 (0)