-
-
Notifications
You must be signed in to change notification settings - Fork 0
Env Command #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Env Command #3
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b2d7872
feat(env): basic commands
8bitAlex 67aef96
store active env
8bitAlex dbae14f
remove strings (for now)
8bitAlex 1f2d25b
Write env variables to repo
8bitAlex 14c4adf
cleanup
8bitAlex 3885a5e
add copilot instructions
8bitAlex c3e0361
remove use command
8bitAlex b6816ee
update readme
8bitAlex d0dd538
Update src/internal/lib/profile.go
8bitAlex d35f72b
Update src/internal/lib/env.go
8bitAlex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| # Raid - Distributed Development Orchestration | ||
|
|
||
| ## Project Overview | ||
|
|
||
| Raid is a Go-based CLI tool that orchestrates development tasks, environments, and dependencies across distributed repositories. It uses YAML/JSON profile configurations to define multi-repo environments and automates setup/execution workflows. | ||
|
|
||
| ## Architecture | ||
|
|
||
| ### Core Components | ||
| - **CLI Layer**: `src/cmd/` - Cobra-based command structure with subcommands for profiles, installation, and environments | ||
| - **Business Logic**: `src/raid/` - High-level API layer that delegates to internal libraries | ||
| - **Internal Implementation**: `src/internal/lib/` - Core functionality for profiles, repositories, environments, and task execution | ||
| - **System Utilities**: `src/internal/sys/` and `src/utils/` - System-level operations and shared utilities | ||
|
|
||
| ### Key Design Patterns | ||
|
|
||
| #### Configuration Management | ||
| - Uses **Viper** for configuration with global state in `src/internal/lib/config.go` | ||
| - **Context singleton** pattern: `lib.Context` struct caches active profile and environment | ||
| - **Lazy loading**: `Load()` uses cached context, `ForceLoad()` rebuilds from scratch | ||
| - Configuration path customizable via `--config/-c` flag | ||
|
|
||
| #### Profile System | ||
| - Profiles define collections of repositories and environments | ||
| - **Multi-document YAML** support using `---` separators for multiple profiles per file | ||
| - **JSON Schema validation** against `schemas/raid-profile.schema.json` | ||
| - Profile state managed in Viper config under `"profiles"` key | ||
|
|
||
| #### Repository Management | ||
| - Concurrent cloning with optional thread limits (`--threads/-t` flag) | ||
| - Uses Go routines with semaphore pattern for concurrency control | ||
| - Repository validation and error aggregation across parallel operations | ||
|
|
||
| #### Environment Execution | ||
| - Environments contain tasks (Shell commands or Script files) and environment variables | ||
| - Task execution supports concurrent execution flag per task | ||
| - Environment variables set globally during environment execution | ||
|
|
||
| ### Key Files & Patterns | ||
|
|
||
| #### Entry Points | ||
| - `main.go` - Simple delegator to `cmd.Execute()` | ||
| - `src/cmd/raid.go` - Root Cobra command with initialization lifecycle | ||
|
|
||
| #### Command Structure | ||
| ``` | ||
| src/cmd/ | ||
| ├── raid.go # Root command, global flags, initialization | ||
| ├── profile/ # Profile management (add, list, use, remove) | ||
| ├── install/ # Repository installation | ||
| └── env/ # Environment execution | ||
| ``` | ||
|
|
||
| #### Core Business Logic Flow | ||
| 1. **Initialize**: `raid.Initialize()` → `lib.InitConfig()` → `lib.Load()` | ||
| 2. **Profile Management**: Viper-backed persistence with JSON schema validation | ||
| 3. **Repository Installation**: Concurrent git cloning with error aggregation | ||
| 4. **Environment Execution**: Task orchestration with variable setting | ||
|
|
||
| ### Development Workflows | ||
|
|
||
| #### Building & Testing | ||
| ```bash | ||
| go build -o raid # Build binary | ||
| go test ./... # Run tests | ||
| go test -coverprofile=coverage.out ./... # Generate coverage | ||
| ``` | ||
|
|
||
| #### JSON Schema Integration | ||
| - Schemas in `schemas/` directory define validation rules | ||
| - Use `github.com/santhosh-tekuri/jsonschema/v6` for validation | ||
| - YAML language server integration with `# yaml-language-server: $schema=...` comments | ||
|
|
||
| #### Configuration Files | ||
| - **Profile configs**: YAML/JSON files following `schemas/raid-profile.schema.json` | ||
| - **Multi-profile files**: Use YAML `---` document separators | ||
| - **Examples**: See `docs/examples/` for reference configurations | ||
|
|
||
| ### Common Patterns | ||
|
|
||
| #### Error Handling | ||
| - Use `fmt.Errorf()` for wrapped errors with context | ||
| - Aggregate errors from concurrent operations into slices | ||
| - CLI commands print errors to stderr via `cmd.PrintErrln()` | ||
|
|
||
| #### Concurrent Operations | ||
| ```go | ||
| // Semaphore pattern for limiting concurrency | ||
| semaphore := make(chan struct{}, maxThreads) | ||
| var wg sync.WaitGroup | ||
| errorChan := make(chan error, len(items)) | ||
|
|
||
| // In goroutine: | ||
| semaphore <- struct{}{} | ||
| defer func() { <-semaphore }() | ||
| ``` | ||
|
|
||
| #### Viper Configuration | ||
| - Global config management via `viper.GetString()`, `viper.Set()` | ||
| - Nested keys accessed with dot notation: `viper.GetStringMapString("profiles")` | ||
| - Automatic config file discovery and loading | ||
|
|
||
| ### Testing & Quality | ||
| - Uses standard Go testing with coverage reporting | ||
| - GitHub Actions CI/CD pipeline defined (`.github/workflows/build.yml`) | ||
| - Codecov integration for coverage tracking |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |
| *.dll | ||
| *.so | ||
| *.dylib | ||
| raid | ||
| /raid | ||
|
|
||
| # Test binary, built with `go test -c` | ||
| *.test | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,46 @@ | ||
| package env | ||
|
|
||
| import ( | ||
| "github.com/8bitalex/raid/src/raid" | ||
| "github.com/8bitalex/raid/src/raid/env" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var ( | ||
| concurrency int | ||
| ) | ||
|
|
||
| func init() { | ||
| Command.Flags().IntVarP(&concurrency, "threads", "t", 0, "Maximum number of concurrent task executions (0 = unlimited)") | ||
| Command.AddCommand(ListEnvCmd) | ||
| } | ||
|
|
||
| var Command = &cobra.Command{ | ||
| Use: "env [environment-name]", | ||
| Short: "Execute an environment", | ||
| Long: "Execute an environment by name. The environment will be searched for in the active profile and all repository configurations. Tasks are executed concurrently and environment variables are set globally.", | ||
| Args: cobra.ExactArgs(1), | ||
| Args: cobra.RangeArgs(0, 1), | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
|
|
||
| if len(args) == 0 { | ||
| env := env.Get() | ||
| if env == "" { | ||
| cmd.PrintErrln("No active environment set.") | ||
| } else { | ||
| cmd.Println("Active environment:", env) | ||
| } | ||
| } else if len(args) == 1 { | ||
| name := args[0] | ||
| if !env.Contains(name) { | ||
| cmd.PrintErrln("Environment not found:", name) | ||
| } else { | ||
| cmd.Println("Setting up environment:", name) | ||
| if err := env.Set(name); err != nil { | ||
| cmd.PrintErrln("Failed to switch environment:", err) | ||
| } | ||
| raid.ForceLoad() | ||
| if err := env.Execute(env.Get()); err != nil { | ||
| cmd.PrintErrln("Failed to execute environment:", err) | ||
| } else { | ||
| cmd.Println("Environment executed successfully.") | ||
| } | ||
| } | ||
| } else { | ||
| cmd.PrintErrln("Invalid number of arguments.") | ||
| } | ||
| }, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package env | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/8bitalex/raid/src/raid/env" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var ListEnvCmd = &cobra.Command{ | ||
| Use: "list", | ||
| Short: "List environments", | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| envs := env.ListAll() | ||
| if len(envs) == 0 { | ||
| fmt.Println("No environments found.") | ||
| return | ||
| } | ||
| fmt.Println("Available environments:") | ||
| for _, env := range envs { | ||
| fmt.Printf("\t%s\n", env) | ||
| } | ||
| fmt.Print() | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Environment Variable Conflict and Execution Order Issues
The
envcommand's new logic for setting an environment introduces a localenvvariable that shadows the imported package, causing compilation errors forenv.Contains,env.Set, andenv.Execute. Additionally,env.Set()runs beforeraid.ForceLoad(), which it depends on for context. The command also continues execution without handling errors fromraid.ForceLoad()or a failedenv.Set().