Skip to content

Commit

Permalink
Merge pull request #1165 from xnox/subpackage-range-scriplets
Browse files Browse the repository at this point in the history
config: allow scriplets in subpackages with range replacements
  • Loading branch information
xnox committed Apr 24, 2024
2 parents 2074468 + f611e9a commit 0a50317
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 22 deletions.
31 changes: 22 additions & 9 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ import (
"chainguard.dev/melange/pkg/util"
)

type Trigger struct {
// Optional: The script to run
Script string `json:"script,omitempty"`
// Optional: The list of paths to monitor to trigger the script
Paths []string `json:"paths,omitempty"`
}

type Scriptlets struct {
// Optional: A script to run on a custom trigger
Trigger struct {
// Optional: The script to run
Script string `json:"script,omitempty"`
// Optional: The list of paths to monitor to trigger the script
Paths []string `json:"paths,omitempty"`
} `json:"trigger,omitempty" yaml:"trigger,omitempty"`

Trigger Trigger `json:"trigger,omitempty" yaml:"trigger,omitempty"`
// Optional: The script to run pre install. The script should contain the
// shebang interpreter.
PreInstall string `json:"pre-install,omitempty" yaml:"pre-install,omitempty"`
Expand Down Expand Up @@ -764,8 +765,20 @@ func ParseConfiguration(ctx context.Context, configurationFilePath string, opts
ProviderPriority: sp.Dependencies.ProviderPriority,
},
Options: sp.Options,
URL: replacer.Replace(sp.URL),
If: replacer.Replace(sp.If),
Scriptlets: Scriptlets{
Trigger: Trigger{
Script: replacer.Replace(sp.Scriptlets.Trigger.Script),
Paths: replaceAll(replacer, sp.Scriptlets.Trigger.Paths),
},
PreInstall: replacer.Replace(sp.Scriptlets.PreInstall),
PostInstall: replacer.Replace(sp.Scriptlets.PostInstall),
PreDeinstall: replacer.Replace(sp.Scriptlets.PreDeinstall),
PostDeinstall: replacer.Replace(sp.Scriptlets.PostDeinstall),
PreUpgrade: replacer.Replace(sp.Scriptlets.PreUpgrade),
PostUpgrade: replacer.Replace(sp.Scriptlets.PostUpgrade),
},
URL: replacer.Replace(sp.URL),
If: replacer.Replace(sp.If),
}
for _, p := range sp.Pipeline {
// take a copy of the with map, so we can replace the values
Expand Down
31 changes: 18 additions & 13 deletions pkg/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -717,19 +717,7 @@
"Scriptlets": {
"properties": {
"trigger": {
"properties": {
"script": {
"type": "string"
},
"paths": {
"items": {
"type": "string"
},
"type": "array"
}
},
"additionalProperties": false,
"type": "object",
"$ref": "#/$defs/Trigger",
"description": "Optional: A script to run on a custom trigger"
},
"pre-install": {
Expand Down Expand Up @@ -840,6 +828,23 @@
"pipeline"
]
},
"Trigger": {
"properties": {
"script": {
"type": "string",
"description": "Optional: The script to run"
},
"paths": {
"items": {
"type": "string"
},
"type": "array",
"description": "Optional: The list of paths to monitor to trigger the script"
}
},
"additionalProperties": false,
"type": "object"
},
"Update": {
"properties": {
"enabled": {
Expand Down

0 comments on commit 0a50317

Please sign in to comment.