Skip to content

Commit 1ad342b

Browse files
authored
Add .github/aw/logs/.gitignore creation to init command (#5712)
1 parent fc84c8e commit 1ad342b

6 files changed

Lines changed: 88 additions & 3 deletions

File tree

.github/workflows/release.lock.yml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cli/git.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,46 @@ func stageGitAttributesIfChanged() error {
113113
return exec.Command("git", "-C", gitRoot, "add", gitAttributesPath).Run()
114114
}
115115

116+
// ensureLogsGitignore ensures that .github/aw/logs/.gitignore exists to ignore log files
117+
func ensureLogsGitignore() error {
118+
gitLog.Print("Ensuring .github/aw/logs/.gitignore exists")
119+
gitRoot, err := findGitRoot()
120+
if err != nil {
121+
return err // Not in a git repository, skip
122+
}
123+
124+
logsDir := filepath.Join(gitRoot, ".github", "aw", "logs")
125+
gitignorePath := filepath.Join(logsDir, ".gitignore")
126+
127+
// Check if .gitignore already exists
128+
if _, err := os.Stat(gitignorePath); err == nil {
129+
gitLog.Print(".github/aw/logs/.gitignore already exists")
130+
return nil
131+
}
132+
133+
gitLog.Print("Creating .github/aw/logs directory and .gitignore")
134+
// Create the logs directory if it doesn't exist
135+
if err := os.MkdirAll(logsDir, 0755); err != nil {
136+
gitLog.Printf("Failed to create logs directory: %v", err)
137+
return fmt.Errorf("failed to create .github/aw/logs directory: %w", err)
138+
}
139+
140+
// Write the .gitignore file
141+
gitignoreContent := `# Ignore all downloaded workflow logs
142+
*
143+
144+
# But keep the .gitignore file itself
145+
!.gitignore
146+
`
147+
if err := os.WriteFile(gitignorePath, []byte(gitignoreContent), 0644); err != nil {
148+
gitLog.Printf("Failed to write .gitignore: %v", err)
149+
return fmt.Errorf("failed to write .github/aw/logs/.gitignore: %w", err)
150+
}
151+
152+
gitLog.Print("Successfully created .github/aw/logs/.gitignore")
153+
return nil
154+
}
155+
116156
// getCurrentBranch gets the current git branch name
117157
func getCurrentBranch() (string, error) {
118158
gitLog.Print("Getting current git branch")

pkg/cli/init.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ func InitRepository(verbose bool, mcp bool) error {
3232
fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("Configured .gitattributes"))
3333
}
3434

35+
// Ensure .github/aw/logs/.gitignore exists
36+
initLog.Print("Ensuring .github/aw/logs/.gitignore exists")
37+
if err := ensureLogsGitignore(); err != nil {
38+
initLog.Printf("Failed to ensure logs .gitignore: %v", err)
39+
return fmt.Errorf("failed to ensure logs .gitignore: %w", err)
40+
}
41+
if verbose {
42+
fmt.Fprintln(os.Stderr, console.FormatSuccessMessage("Configured .github/aw/logs/.gitignore"))
43+
}
44+
3545
// Write copilot instructions
3646
initLog.Print("Writing GitHub Copilot instructions")
3747
if err := ensureCopilotInstructions(verbose, false); err != nil {

pkg/cli/init_command.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func NewInitCommand() *cobra.Command {
1717
1818
This command:
1919
- Configures .gitattributes to mark .lock.yml files as generated
20+
- Creates .github/aw/logs/.gitignore to ignore downloaded workflow logs
2021
- Creates GitHub Copilot custom instructions at .github/aw/github-agentic-workflows.md
2122
- Creates the agent for workflow creation at .github/agents/create-agentic-workflow.agent.md
2223
- Creates the debug agentic workflow agent at .github/agents/debug-agentic-workflow.agent.md

pkg/cli/init_command_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ func TestInitRepositoryBasic(t *testing.T) {
109109
if !strings.Contains(string(content), expectedEntry) {
110110
t.Errorf("Expected .gitattributes to contain %q", expectedEntry)
111111
}
112+
113+
// Verify logs .gitignore was created
114+
logsGitignorePath := filepath.Join(".github", "aw", "logs", ".gitignore")
115+
if _, err := os.Stat(logsGitignorePath); os.IsNotExist(err) {
116+
t.Error("Expected .github/aw/logs/.gitignore to be created")
117+
}
112118
}
113119

114120
func TestInitRepositoryWithMCP(t *testing.T) {

pkg/cli/init_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,28 @@ func TestInitRepository(t *testing.T) {
8080
t.Errorf("Expected copilot instructions file to exist")
8181
}
8282

83+
// Verify logs .gitignore was created
84+
logsGitignorePath := filepath.Join(tempDir, ".github", "aw", "logs", ".gitignore")
85+
if _, err := os.Stat(logsGitignorePath); os.IsNotExist(err) {
86+
t.Errorf("Expected .github/aw/logs/.gitignore file to exist")
87+
}
88+
89+
// Verify logs .gitignore content
90+
if content, err := os.ReadFile(logsGitignorePath); err == nil {
91+
contentStr := string(content)
92+
if !strings.Contains(contentStr, "# Ignore all downloaded workflow logs") {
93+
t.Errorf("Expected .gitignore to contain comment about ignoring logs")
94+
}
95+
if !strings.Contains(contentStr, "*") {
96+
t.Errorf("Expected .gitignore to contain wildcard pattern")
97+
}
98+
if !strings.Contains(contentStr, "!.gitignore") {
99+
t.Errorf("Expected .gitignore to keep itself")
100+
}
101+
} else {
102+
t.Errorf("Failed to read .github/aw/logs/.gitignore: %v", err)
103+
}
104+
83105
// Verify agentic workflow agent was created
84106
agenticWorkflowAgentPath := filepath.Join(tempDir, ".github", "agents", "create-agentic-workflow.agent.md")
85107
if _, err := os.Stat(agenticWorkflowAgentPath); os.IsNotExist(err) {
@@ -158,6 +180,12 @@ func TestInitRepository_Idempotent(t *testing.T) {
158180
if _, err := os.Stat(debugAgenticWorkflowAgentPath); os.IsNotExist(err) {
159181
t.Errorf("Expected debug agentic workflow agent file to exist after second call")
160182
}
183+
184+
// Verify logs .gitignore still exists after second call
185+
logsGitignorePath := filepath.Join(tempDir, ".github", "aw", "logs", ".gitignore")
186+
if _, err := os.Stat(logsGitignorePath); os.IsNotExist(err) {
187+
t.Errorf("Expected .github/aw/logs/.gitignore file to exist after second call")
188+
}
161189
}
162190

163191
func TestInitRepository_Verbose(t *testing.T) {

0 commit comments

Comments
 (0)