MCPcopy Create free account
hub / github.com/github/gh-aw / generateActionYml

Function generateActionYml

pkg/cli/generate_action_metadata_command.go:320–369  ·  view source on GitHub ↗

generateActionYml generates an action.yml file

(actionDir string, metadata *ActionMetadata)

Source from the content-addressed store, hash-verified

318
319// generateActionYml generates an action.yml file
320func generateActionYml(actionDir string, metadata *ActionMetadata) error {
321 generateActionMetadataLog.Printf("Generating action.yml: action=%s, inputs=%d, outputs=%d", metadata.ActionName, len(metadata.Inputs), len(metadata.Outputs))
322 var content strings.Builder
323
324 fmt.Fprintf(&content, "name: '%s'\n", metadata.Name)
325 fmt.Fprintf(&content, "description: '%s'\n", metadata.Description)
326 content.WriteString("author: 'GitHub Next'\n\n")
327
328 // Add inputs
329 if len(metadata.Inputs) > 0 {
330 content.WriteString("inputs:\n")
331 for _, input := range metadata.Inputs {
332 fmt.Fprintf(&content, " %s:\n", input.Name)
333 fmt.Fprintf(&content, " description: '%s'\n", input.Description)
334 fmt.Fprintf(&content, " required: %t\n", input.Required)
335 if input.Default != "" {
336 fmt.Fprintf(&content, " default: '%s'\n", input.Default)
337 }
338 }
339 content.WriteString("\n")
340 }
341
342 // Add outputs
343 if len(metadata.Outputs) > 0 {
344 content.WriteString("outputs:\n")
345 for _, output := range metadata.Outputs {
346 fmt.Fprintf(&content, " %s:\n", output.Name)
347 fmt.Fprintf(&content, " description: '%s'\n", output.Description)
348 }
349 content.WriteString("\n")
350 }
351
352 // Add runs section
353 content.WriteString("runs:\n")
354 content.WriteString(" using: 'node20'\n")
355 content.WriteString(" main: 'index.js'\n\n")
356
357 // Add branding
358 content.WriteString("branding:\n")
359 content.WriteString(" icon: 'package'\n")
360 content.WriteString(" color: 'blue'\n")
361
362 // Write to file with owner-only read/write permissions (0600) for security best practices
363 ymlPath := filepath.Join(actionDir, "action.yml")
364 if err := os.WriteFile(ymlPath, []byte(content.String()), constants.FilePermSensitive); err != nil {
365 return fmt.Errorf("failed to write action.yml: %w", err)
366 }
367
368 return nil
369}
370
371// generateReadme generates a README.md file
372func generateReadme(actionDir string, metadata *ActionMetadata) error {

Callers 2

TestGenerateActionYmlFunction · 0.85

Calls 3

PrintfMethod · 0.45
StringMethod · 0.45
ErrorfMethod · 0.45

Tested by 1

TestGenerateActionYmlFunction · 0.68