Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,6 @@ golint:
exit 1; \
fi

# Validate auto-compile workflow template
.PHONY: validate-template
validate-template:
@echo "Validating auto-compile workflow template..."
@if command -v actionlint >/dev/null 2>&1; then \
actionlint pkg/cli/templates/auto-compile-workflow.yml; \
else \
echo "actionlint is not installed. Installing..."; \
go install github.com/rhysd/actionlint/cmd/actionlint@latest; \
actionlint pkg/cli/templates/auto-compile-workflow.yml; \
fi
@echo "✓ Auto-compile workflow template is valid"

# Validate compiled workflow lock files (models: read not supported yet)
.PHONY: validate-workflows
validate-workflows:
Expand Down Expand Up @@ -128,7 +115,7 @@ fmt-check:

# Validate all project files
.PHONY: lint
lint: fmt-check golint validate-template
lint: fmt-check golint
@echo "✓ All validations passed"

# Install the binary locally
Expand Down Expand Up @@ -236,9 +223,8 @@ help:
@echo " lint - Run linter"
@echo " fmt - Format code"
@echo " fmt-check - Check code formatting"
@echo " validate-template - Validate auto-compile workflow template"
@echo " validate-workflows - Validate compiled workflow lock files"
@echo " validate - Run all validations (fmt-check, lint, validate-template, validate-workflows)"
@echo " validate - Run all validations (fmt-check, lint, validate-workflows)"
@echo " install - Install binary locally"
@echo " recompile - Recompile all workflow files (depends on build)"
@echo " copy-copilot-to-claude - Copy copilot instructions to Claude instructions file"
Expand Down
4 changes: 1 addition & 3 deletions cmd/gh-aw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,13 @@ var compileCmd = &cobra.Command{
}
engineOverride, _ := cmd.Flags().GetString("engine")
validate, _ := cmd.Flags().GetBool("validate")
autoCompile, _ := cmd.Flags().GetBool("auto-compile")
watch, _ := cmd.Flags().GetBool("watch")
instructions, _ := cmd.Flags().GetBool("instructions")
if err := validateEngine(engineOverride); err != nil {
fmt.Fprintln(os.Stderr, console.FormatErrorMessage(err.Error()))
os.Exit(1)
}
if err := cli.CompileWorkflows(file, verbose, engineOverride, validate, autoCompile, watch, instructions); err != nil {
if err := cli.CompileWorkflows(file, verbose, engineOverride, validate, watch, instructions); err != nil {
fmt.Fprintln(os.Stderr, console.FormatErrorMessage(err.Error()))
os.Exit(1)
}
Expand Down Expand Up @@ -333,7 +332,6 @@ func init() {
// Add AI flag to compile and add commands
compileCmd.Flags().StringP("engine", "a", "", "Override AI engine (claude, codex)")
compileCmd.Flags().Bool("validate", false, "Enable GitHub Actions workflow schema validation")
compileCmd.Flags().Bool("auto-compile", false, "Generate auto-compile workflow file for automatic compilation")
compileCmd.Flags().BoolP("watch", "w", false, "Watch for changes to workflow files and recompile automatically")
compileCmd.Flags().Bool("instructions", false, "Generate or update GitHub Copilot instructions file")

Expand Down
24 changes: 0 additions & 24 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ gh aw compile --watch

# Watch with verbose output for detailed compilation feedback
gh aw compile --watch --verbose

# Generate auto-compile workflow for automatic CI/CD integration
gh aw compile --auto-compile

# Combined development setup: watch + auto-compile + verbose
gh aw compile --watch --auto-compile --verbose
```

**Compilation Process:**
Expand Down Expand Up @@ -225,21 +219,6 @@ gh aw mcp-inspect workflow-name --inspector

For detailed MCP debugging and troubleshooting guides, see [MCP Debugging](mcps.md#debugging-and-troubleshooting).

## 🔄 Auto-Compile Workflow Management

The `--auto-compile` flag enables automatic compilation of agentic workflows when markdown files change.

```bash
# Generate auto-compile workflow that triggers on markdown file changes
gh aw compile --auto-compile
```

Auto-compile workflow features:
- Triggers when .github/workflows/*.md files are modified
- Automatically compiles markdown files to .lock.yml files
- Commits and pushes the compiled workflow files
- Uses locally built gh-aw extension for development workflows

## 👀 Watch Mode for Development
The `--watch` flag provides automatic recompilation during workflow development, monitoring for file changes in real-time. See [Authoring in Visual Studio Code](./vscode.md).

Expand All @@ -249,9 +228,6 @@ gh aw compile --watch

# Watch with verbose output for detailed compilation feedback
gh aw compile --watch --verbose

# Watch with auto-compile workflow generation
gh aw compile --watch --auto-compile --verbose
```

## 📦 Package Management
Expand Down
121 changes: 8 additions & 113 deletions pkg/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,80 +30,11 @@
version = "dev"
)

//go:embed templates/auto-compile-workflow.yml
var autoCompileWorkflowTemplate string

Check failure on line 33 in pkg/cli/commands.go

View workflow job for this annotation

GitHub Actions / Lint Code

File is not properly formatted (gofmt)

//go:embed templates/instructions.md
var copilotInstructionsTemplate string

// ensureAutoCompileWorkflow checks if the auto-compile workflow exists and is up-to-date
func ensureAutoCompileWorkflow(verbose bool) error {
// Find git root for consistent behavior
gitRoot, err := findGitRoot()
if err != nil {
return fmt.Errorf("auto-compile workflow management requires being in a git repository: %w", err)
}

workflowsDir := filepath.Join(gitRoot, ".github/workflows")
autoCompileFile := filepath.Join(workflowsDir, "auto-compile-workflows.yml")

// Check if the workflow file exists
needsUpdate := false
existingContent := ""

if content, err := os.ReadFile(autoCompileFile); err != nil {
if os.IsNotExist(err) {
needsUpdate = true
if verbose {
fmt.Println(console.FormatVerboseMessage(fmt.Sprintf("Auto-compile workflow not found, will create: %s", autoCompileFile)))
}
} else {
return fmt.Errorf("failed to read auto-compile workflow: %w", err)
}
} else {
existingContent = string(content)

// Always use the fast install template (no rebuild)
expectedTemplate := autoCompileWorkflowTemplate

// Check if content matches our expected template
if strings.TrimSpace(existingContent) != strings.TrimSpace(expectedTemplate) {
needsUpdate = true
if verbose {
fmt.Println(console.FormatVerboseMessage(fmt.Sprintf("Auto-compile workflow is outdated, will update: %s", autoCompileFile)))
}
} else if verbose {
fmt.Println(console.FormatVerboseMessage(fmt.Sprintf("Auto-compile workflow is up-to-date: %s", autoCompileFile)))
}
}

// Update the workflow if needed
if needsUpdate {
// Always use the fast install template (no rebuild)
templateToWrite := autoCompileWorkflowTemplate

// Ensure the workflows directory exists
if err := os.MkdirAll(workflowsDir, 0755); err != nil {
return fmt.Errorf("failed to create workflows directory: %w", err)
}

// Write the auto-compile workflow
if err := os.WriteFile(autoCompileFile, []byte(templateToWrite), 0644); err != nil {
return fmt.Errorf("failed to write auto-compile workflow: %w", err)
}

if verbose {
if existingContent == "" {
fmt.Println(console.FormatSuccessMessage(fmt.Sprintf("Created auto-compile workflow: %s", autoCompileFile)))
} else {
fmt.Println(console.FormatSuccessMessage(fmt.Sprintf("Updated auto-compile workflow: %s", autoCompileFile)))
}
}
}

return nil
}

// SetVersionInfo sets the version information for the CLI
func SetVersionInfo(v string) {
version = v
Expand Down Expand Up @@ -531,7 +462,7 @@
}

// CompileWorkflows compiles markdown files into GitHub Actions workflow files
func CompileWorkflows(markdownFile string, verbose bool, engineOverride string, validate bool, autoCompile bool, watch bool, writeInstructions bool) error {
func CompileWorkflows(markdownFile string, verbose bool, engineOverride string, validate bool, watch bool, writeInstructions bool) error {
// Create compiler with verbose flag and AI engine override
compiler := workflow.NewCompiler(verbose, engineOverride, GetVersion())

Expand All @@ -540,7 +471,7 @@

if watch {
// Watch mode: watch for file changes and recompile automatically
return watchAndCompileWorkflows(markdownFile, compiler, verbose, autoCompile)
return watchAndCompileWorkflows(markdownFile, compiler, verbose)
}

if markdownFile != "" {
Expand All @@ -557,15 +488,6 @@
return err
}

// Ensure auto-compile workflow is present and up-to-date if requested
if autoCompile {
if err := ensureAutoCompileWorkflow(verbose); err != nil {
if verbose {
fmt.Println(console.FormatWarningMessage(fmt.Sprintf("Failed to manage auto-compile workflow: %v", err)))
}
}
}

// Ensure .gitattributes marks .lock.yml files as generated
if err := ensureGitAttributes(); err != nil {
if verbose {
Expand All @@ -591,15 +513,6 @@
return fmt.Errorf("compile without arguments requires being in a git repository: %w", err)
}

// Ensure auto-compile workflow is present and up-to-date if requested
if autoCompile {
if err := ensureAutoCompileWorkflow(verbose); err != nil {
if verbose {
fmt.Println(console.FormatWarningMessage(fmt.Sprintf("Failed to manage auto-compile workflow: %v", err)))
}
}
}

// Compile all markdown files in .github/workflows relative to git root
workflowsDir := filepath.Join(gitRoot, ".github/workflows")
if _, err := os.Stat(workflowsDir); os.IsNotExist(err) {
Expand Down Expand Up @@ -658,7 +571,7 @@
}

// watchAndCompileWorkflows watches for changes to workflow files and recompiles them automatically
func watchAndCompileWorkflows(markdownFile string, compiler *workflow.Compiler, verbose bool, autoCompile bool) error {
func watchAndCompileWorkflows(markdownFile string, compiler *workflow.Compiler, verbose bool) error {
// Find git root for consistent behavior
gitRoot, err := findGitRoot()
if err != nil {
Expand Down Expand Up @@ -718,7 +631,7 @@
if verbose {
fmt.Println("🔨 Initial compilation of all workflow files...")
}
if err := compileAllWorkflowFiles(compiler, workflowsDir, verbose, autoCompile); err != nil {
if err := compileAllWorkflowFiles(compiler, workflowsDir, verbose); err != nil {
// Always show initial compilation errors, not just in verbose mode
fmt.Println(console.FormatWarningMessage(fmt.Sprintf("Initial compilation failed: %v", err)))
}
Expand Down Expand Up @@ -779,7 +692,7 @@
modifiedFiles = make(map[string]struct{})

// Compile the modified files
compileModifiedFiles(compiler, filesToCompile, verbose, autoCompile)
compileModifiedFiles(compiler, filesToCompile, verbose)
})
}

Expand All @@ -804,7 +717,7 @@
}

// compileAllWorkflowFiles compiles all markdown files in the workflows directory
func compileAllWorkflowFiles(compiler *workflow.Compiler, workflowsDir string, verbose bool, autoCompile bool) error {
func compileAllWorkflowFiles(compiler *workflow.Compiler, workflowsDir string, verbose bool) error {
// Find all markdown files
mdFiles, err := filepath.Glob(filepath.Join(workflowsDir, "*.md"))
if err != nil {
Expand All @@ -831,15 +744,6 @@
}
}

// Handle auto-compile workflow if requested
if autoCompile {
if err := ensureAutoCompileWorkflow(verbose); err != nil {
if verbose {
fmt.Printf("⚠️ Failed to manage auto-compile workflow: %v\n", err)
}
}
}

// Ensure .gitattributes marks .lock.yml files as generated
if err := ensureGitAttributes(); err != nil {
if verbose {
Expand All @@ -851,7 +755,7 @@
}

// compileModifiedFiles compiles a list of modified markdown files
func compileModifiedFiles(compiler *workflow.Compiler, files []string, verbose bool, autoCompile bool) {
func compileModifiedFiles(compiler *workflow.Compiler, files []string, verbose bool) {
if len(files) == 0 {
return
}
Expand Down Expand Up @@ -882,15 +786,6 @@
}
}

// Handle auto-compile workflow if requested
if autoCompile {
if err := ensureAutoCompileWorkflow(verbose); err != nil {
if verbose {
fmt.Printf("⚠️ Failed to manage auto-compile workflow: %v\n", err)
}
}
}

// Ensure .gitattributes marks .lock.yml files as generated
if err := ensureGitAttributes(); err != nil {
if verbose {
Expand Down
Loading
Loading