SubstituteImportInputs replaces ${{ github.aw.inputs. }} and ${{ github.aw.import-inputs. }} expressions with the corresponding values from the importInputs map. This is called before expression extraction to inject import input values.
(content string, importInputs map[string]any)
| 479 | // values from the importInputs map. |
| 480 | // This is called before expression extraction to inject import input values. |
| 481 | func SubstituteImportInputs(content string, importInputs map[string]any) string { |
| 482 | if len(importInputs) == 0 { |
| 483 | return content |
| 484 | } |
| 485 | |
| 486 | expressionExtractionLog.Printf("Substituting import inputs: %d inputs available", len(importInputs)) |
| 487 | |
| 488 | substituteFunc := func(regex *regexp.Regexp, inputCategory string) func(string) string { |
| 489 | return func(match string) string { |
| 490 | matches := regex.FindStringSubmatch(match) |
| 491 | if len(matches) < 2 { |
| 492 | return match |
| 493 | } |
| 494 | path := matches[1] |
| 495 | // Resolve potentially dotted path (e.g. "config.apiKey" for object inputs) |
| 496 | if value, found := resolveImportInputPath(importInputs, path); found { |
| 497 | strValue := marshalImportInputValue(value) |
| 498 | expressionExtractionLog.Printf("Substituting github.aw.%s.%s with value: %s", inputCategory, path, strValue) |
| 499 | return strValue |
| 500 | } |
| 501 | expressionExtractionLog.Printf("Import input path not found: %s", path) |
| 502 | return match |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | // Substitute ${{ github.aw.inputs.<key> }} (legacy form) |
| 507 | result := AWInputsExpressionPattern.ReplaceAllStringFunc(content, substituteFunc(AWInputsExpressionPattern, "inputs")) |
| 508 | // Substitute ${{ github.aw.import-inputs.<key> }} (import-schema form) |
| 509 | result = AWImportInputsExpressionPattern.ReplaceAllStringFunc(result, substituteFunc(AWImportInputsExpressionPattern, "import-inputs")) |
| 510 | |
| 511 | return result |
| 512 | } |
| 513 | |
| 514 | // marshalImportInputValue serializes an import input value to a string suitable for |
| 515 | // substitution into both YAML frontmatter and markdown prose. |
no test coverage detected