Skip to content

Commit

Permalink
fix: use single source instead of a list
Browse files Browse the repository at this point in the history
  • Loading branch information
majori committed Feb 6, 2024
1 parent d4f62a9 commit 40d453b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/docs/templates/_schema.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
| `name` | `string` | | Name of the recipe. |
| `version` | `string` | | Version of the recipe. Must be valid [semver](https://semver.org/). |
| `description` | `string` | | Description of what the recipe does |
| `sources` | `[]string` | | A list of URLs to source code for this recipe. |
| `source` | `string` | | URL to source code for this recipe. |
| `templateExtension` | `string` | | File extension of files in "templates" directory which should be templated. Files not matched by this extension will be copied as-is. If left empty (the default), all files will be templated. |
| `initHelp` | `string` | | A message which will be showed to an user after a succesful recipe execution. Can be used to guide the user what should be done next in the project directory. |
| `ignorePatterns` | `[]string` | | Glob patterns for ignoring generated files from future recipe upgrades. Ignored files will not be regenerated even if their templates change in future versions of the recipe. |
Expand Down
1 change: 1 addition & 0 deletions docs/site/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ The following context is available on the templates:
- `.Recipe.APIVersion`: The API version which the recipe file uses
- `.Recipe.Name`: The name of the recipe
- `.Recipe.Version`: The current version of the recipe
- `.Recipe.Source`: URL to source code for this recipe
- `.ID`: UUID which is generated after the first execution of the recipe. It will keep its value over upgrades. Can be used to generate unique pseudo-random values which stays the same over the upgrades, for example `my-resource-{{ sha1sum .ID | trunc 5 }}`
- `.Variables`: Object which contains the values of the variables defined for the recipe. Example: `{{ .Variables.FOO }}`

Expand Down
3 changes: 2 additions & 1 deletion pkg/recipe/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ func (re *Recipe) Execute(engine RenderEngine, values VariableValues, id uuid.UU
// Define the context which is available on templates
context := map[string]interface{}{
"ID": sauce.ID.String(),
"Recipe": struct{ APIVersion, Name, Version string }{
"Recipe": struct{ APIVersion, Name, Version, Source string }{
re.APIVersion,
re.Name,
re.Version,
re.Source,
},
"Variables": mappedValues,
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/recipe/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ type Metadata struct {
// Description of what the recipe does
Description string `yaml:"description"`

// A list of URLs to source code for this recipe
Sources []string `yaml:"sources,omitempty"`
// URL to source code for this recipe
Source string `yaml:"source,omitempty"`

// A message which will be showed to an user after a succesful recipe execution.
// Can be used to guide the user what should be done next in the project directory.
Expand Down Expand Up @@ -64,8 +64,8 @@ func (m *Metadata) Validate() error {
return fmt.Errorf("template extension must start with a dot")
}

for _, sourceURL := range m.Sources {
if _, err := url.ParseRequestURI(sourceURL); err != nil {
if m.Source != "" {
if _, err := url.ParseRequestURI(m.Source); err != nil {
return fmt.Errorf("source url is invalid: %w", err)
}
}
Expand Down

0 comments on commit 40d453b

Please sign in to comment.