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
6 changes: 3 additions & 3 deletions .github/workflows/release.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions pkg/cli/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,46 @@ func stageGitAttributesIfChanged() error {
return exec.Command("git", "-C", gitRoot, "add", gitAttributesPath).Run()
}

// ensureLogsGitignore ensures that .github/aw/logs/.gitignore exists to ignore log files
func ensureLogsGitignore() error {
gitLog.Print("Ensuring .github/aw/logs/.gitignore exists")
gitRoot, err := findGitRoot()
if err != nil {
return err // Not in a git repository, skip
}

logsDir := filepath.Join(gitRoot, ".github", "aw", "logs")
gitignorePath := filepath.Join(logsDir, ".gitignore")

// Check if .gitignore already exists
if _, err := os.Stat(gitignorePath); err == nil {
gitLog.Print(".github/aw/logs/.gitignore already exists")
return nil
}

gitLog.Print("Creating .github/aw/logs directory and .gitignore")
// Create the logs directory if it doesn't exist
if err := os.MkdirAll(logsDir, 0755); err != nil {
gitLog.Printf("Failed to create logs directory: %v", err)
return fmt.Errorf("failed to create .github/aw/logs directory: %w", err)
}

// Write the .gitignore file
gitignoreContent := `# Ignore all downloaded workflow logs
*

# But keep the .gitignore file itself
!.gitignore
`
if err := os.WriteFile(gitignorePath, []byte(gitignoreContent), 0644); err != nil {
gitLog.Printf("Failed to write .gitignore: %v", err)
return fmt.Errorf("failed to write .github/aw/logs/.gitignore: %w", err)
}

gitLog.Print("Successfully created .github/aw/logs/.gitignore")
return nil
}

// getCurrentBranch gets the current git branch name
func getCurrentBranch() (string, error) {
gitLog.Print("Getting current git branch")
Expand Down
10 changes: 10 additions & 0 deletions pkg/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ func InitRepository(verbose bool, mcp bool) error {
fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("Configured .gitattributes"))
}

// Ensure .github/aw/logs/.gitignore exists
initLog.Print("Ensuring .github/aw/logs/.gitignore exists")
if err := ensureLogsGitignore(); err != nil {
initLog.Printf("Failed to ensure logs .gitignore: %v", err)
return fmt.Errorf("failed to ensure logs .gitignore: %w", err)
}
if verbose {
fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("Configured .github/aw/logs/.gitignore"))
}

// Write copilot instructions
initLog.Print("Writing GitHub Copilot instructions")
if err := ensureCopilotInstructions(verbose, false); err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/init_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func NewInitCommand() *cobra.Command {

This command:
- Configures .gitattributes to mark .lock.yml files as generated
- Creates .github/aw/logs/.gitignore to ignore downloaded workflow logs
- Creates GitHub Copilot custom instructions at .github/aw/github-agentic-workflows.md
- Creates the agent for workflow creation at .github/agents/create-agentic-workflow.agent.md
- Creates the debug agentic workflow agent at .github/agents/debug-agentic-workflow.agent.md
Expand Down
6 changes: 6 additions & 0 deletions pkg/cli/init_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ func TestInitRepositoryBasic(t *testing.T) {
if !strings.Contains(string(content), expectedEntry) {
t.Errorf("Expected .gitattributes to contain %q", expectedEntry)
}

// Verify logs .gitignore was created
logsGitignorePath := filepath.Join(".github", "aw", "logs", ".gitignore")
if _, err := os.Stat(logsGitignorePath); os.IsNotExist(err) {
t.Error("Expected .github/aw/logs/.gitignore to be created")
}
}

func TestInitRepositoryWithMCP(t *testing.T) {
Expand Down
28 changes: 28 additions & 0 deletions pkg/cli/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,28 @@ func TestInitRepository(t *testing.T) {
t.Errorf("Expected copilot instructions file to exist")
}

// Verify logs .gitignore was created
logsGitignorePath := filepath.Join(tempDir, ".github", "aw", "logs", ".gitignore")
if _, err := os.Stat(logsGitignorePath); os.IsNotExist(err) {
t.Errorf("Expected .github/aw/logs/.gitignore file to exist")
}

// Verify logs .gitignore content
if content, err := os.ReadFile(logsGitignorePath); err == nil {
contentStr := string(content)
if !strings.Contains(contentStr, "# Ignore all downloaded workflow logs") {
t.Errorf("Expected .gitignore to contain comment about ignoring logs")
}
if !strings.Contains(contentStr, "*") {
t.Errorf("Expected .gitignore to contain wildcard pattern")
}
if !strings.Contains(contentStr, "!.gitignore") {
t.Errorf("Expected .gitignore to keep itself")
}
} else {
t.Errorf("Failed to read .github/aw/logs/.gitignore: %v", err)
}

// Verify agentic workflow agent was created
agenticWorkflowAgentPath := filepath.Join(tempDir, ".github", "agents", "create-agentic-workflow.agent.md")
if _, err := os.Stat(agenticWorkflowAgentPath); os.IsNotExist(err) {
Expand Down Expand Up @@ -158,6 +180,12 @@ func TestInitRepository_Idempotent(t *testing.T) {
if _, err := os.Stat(debugAgenticWorkflowAgentPath); os.IsNotExist(err) {
t.Errorf("Expected debug agentic workflow agent file to exist after second call")
}

// Verify logs .gitignore still exists after second call
logsGitignorePath := filepath.Join(tempDir, ".github", "aw", "logs", ".gitignore")
if _, err := os.Stat(logsGitignorePath); os.IsNotExist(err) {
t.Errorf("Expected .github/aw/logs/.gitignore file to exist after second call")
}
}

func TestInitRepository_Verbose(t *testing.T) {
Expand Down