buildAction builds a single action by bundling its dependencies
(actionsDir, actionName string)
| 200 | |
| 201 | // buildAction builds a single action by bundling its dependencies |
| 202 | func buildAction(actionsDir, actionName string) error { |
| 203 | actionsBuildLog.Printf("Building action: %s", actionName) |
| 204 | |
| 205 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage("\n📦 Building action: "+actionName)) |
| 206 | |
| 207 | actionPath := filepath.Join(actionsDir, actionName) |
| 208 | |
| 209 | // Validate action.yml |
| 210 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage(" ✓ Validating action.yml")) |
| 211 | if err := validateActionYml(actionPath); err != nil { |
| 212 | return err |
| 213 | } |
| 214 | |
| 215 | // Special handling for setup: build shell script with embedded files |
| 216 | if actionName == "setup" { |
| 217 | return buildSetupAction(actionsDir, actionName) |
| 218 | } |
| 219 | |
| 220 | // Check if this is a composite action (doesn't need JavaScript bundling) |
| 221 | isComposite, err := isCompositeAction(actionPath) |
| 222 | if err != nil { |
| 223 | return fmt.Errorf("failed to check action type: %w", err) |
| 224 | } |
| 225 | |
| 226 | if isComposite { |
| 227 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage(" ✓ Composite action - no JavaScript bundling needed")) |
| 228 | return nil |
| 229 | } |
| 230 | |
| 231 | srcPath := filepath.Join(actionPath, "src", "index.js") |
| 232 | outputPath := filepath.Join(actionPath, "index.js") |
| 233 | |
| 234 | // Check if source file exists |
| 235 | if _, err := os.Stat(srcPath); os.IsNotExist(err) { |
| 236 | return fmt.Errorf("source file not found: %s", srcPath) |
| 237 | } |
| 238 | |
| 239 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage(" ✓ Reading source file")) |
| 240 | sourceContent, err := os.ReadFile(srcPath) |
| 241 | if err != nil { |
| 242 | return fmt.Errorf("failed to read source file: %w", err) |
| 243 | } |
| 244 | |
| 245 | // Get dependencies for this action |
| 246 | dependencies := getActionDependencies(actionName) |
| 247 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf(" ✓ Found %d dependencies", len(dependencies)))) |
| 248 | |
| 249 | // Get all JavaScript sources |
| 250 | sources := workflow.GetJavaScriptSources() |
| 251 | |
| 252 | // Read dependency files |
| 253 | files := make(map[string]string) |
| 254 | for _, dep := range dependencies { |
| 255 | if content, ok := sources[dep]; ok { |
| 256 | files[dep] = content |
| 257 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage(" - "+dep)) |
| 258 | } else { |
| 259 | fmt.Fprintln(os.Stderr, console.FormatWarningMessage(" ⚠ Warning: Could not find "+dep)) |