Documentation
¶
Index ¶
- func AllModules(directory string) *[]string
- func CheckStages(module *Module) error
- func HandleStages(ctx context.Context, stages []string, m *Module, logger interfaces.Logger, ...) (err error)
- func NewModuleBuilder(m *Module, logger interfaces.Logger) interfaces.Builder
- func ValidateLastVersion(steps []string, filter func(string) (types.Stage, error)) error
- func ValidateRelease(steps []string, filter func(string) (types.Stage, error)) error
- func ValidateRun(m *Module) error
- func ValidateVariables(m *Module) error
- type Module
- func (m *Module) FindStage(name string) (types.Stage, error)
- func (m *Module) GetChanges() *types.Changes
- func (m *Module) GetIgnore() []string
- func (m *Module) GetLabel() types.VersionLabel
- func (m *Module) GetRun() map[string][]string
- func (m *Module) GetStages() []types.Stage
- func (m *Module) GetVariables() map[string]string
- func (m *Module) GetVersion() string
- func (m *Module) IsLastVersion() bool
- func (m *Module) IsValid() error
- func (m *Module) NormalizeStages() error
- func (m *Module) PasswordEnv() string
- func (m *Module) SourceCount() int
- func (m *Module) StageCallback(stageName string) (interfaces.Runnable, error)
- func (m *Module) ToYAML() ([]byte, error)
- func (m *Module) ValidateChangelog() error
- func (m *Module) ZipPath() (string, error)
- type ModuleBuilder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllModules ¶
AllModules returns a list of module names found in the specified directory.
The function reads the directory, checks for files (skipping directories), and attempts to read each file as a module using the ReadModule function. If a file can be successfully read as a module, its name is added to the list.
Parameters:
- directory (string): The path to the directory to scan for modules.
Returns:
- *[]string: A pointer to a slice of strings containing the names of all successfully read modules.
func CheckStages ¶
CheckStages validates the paths in the stages of the given module.
This function iterates over the stages in the provided module and concurrently checks the paths defined in each stage using goroutines. If any errors are encountered, they are collected in a channel and returned as a combined error.
Parameters:
- module (*Module): The module containing stages to be validated.
Returns:
- error: Returns an error if any validation fails in any stage's paths. If no errors are found, it returns nil.
func HandleStages ¶
func HandleStages( ctx context.Context, stages []string, m *Module, logger interfaces.Logger, customCommandMode bool, ) (err error)
HandleStages executes a sequence of stages defined in the provided module.
For each stage name in the `stages` slice, the corresponding stage is resolved from the module `m` and processed concurrently via the `handleStage` function. Each stage may produce file copy tasks, which are sent to a shared channel (`filesCh`) and handled by a pool of worker goroutines. Log messages are sent asynchronously to a logging worker via `logCh`.
The function manages synchronization using multiple WaitGroups and coordinates shutdown via context cancellation. If any error occurs in stage processing or file copying, the first error is captured and the context is canceled.
Parameters:
- ctx: base context used for cancellation.
- stages: list of stage names to execute.
- m: the module containing the stage definitions.
- log: implementation of Logger for reporting progress and messages.
- customCommandMode: if true, skips versioned output directory creation.
Returns:
- err: the first error encountered during execution, or nil if all stages completed successfully.
func NewModuleBuilder ¶
func NewModuleBuilder(m *Module, logger interfaces.Logger) interfaces.Builder
func ValidateLastVersion ¶
func ValidateRelease ¶
func ValidateRun ¶
func ValidateVariables ¶
Types ¶
type Module ¶
type Module struct {
Variables map[string]string `yaml:"variables,omitempty"`
Run map[string][]string `yaml:"run,omitempty"`
Log *types.Log `yaml:"log,omitempty"`
Name string `yaml:"name"`
Version string `yaml:"version"`
Description string `yaml:"description,omitempty"`
Repository string `yaml:"repository,omitempty"`
Account string `yaml:"account"`
BuildDirectory string `yaml:"buildDirectory,omitempty"`
Label types.VersionLabel `yaml:"label,omitempty"`
Builds types.Builds `yaml:"builds"`
Ignore []string `yaml:"ignore"`
Stages []types.Stage `yaml:"stages"`
Callbacks []callback.Callback `yaml:"callbacks,omitempty"`
Changelog changelog.Changelog `yaml:"changelog,omitempty"`
LastVersion bool `yaml:"-"`
// contains filtered or unexported fields
}
func ReadModule ¶
ReadModule reads a module from a YAML file or directory path and returns a Module object.
This function attempts to read a module from the specified path. If the `file` flag is true, the function treats `path` as the file path directly. Otherwise, it expects a YAML file with the name of the module, combining the `path` and `name` parameters to form the file path.
Parameters:
- path (string): The directory or file path where the module file is located.
- name (string): The name of the module. Used to construct the file path when `file` is false.
- file (bool): Flag indicating whether the `path` is a direct file path or a directory where a module file should be looked for.
Returns:
- *Module: A pointer to a `Module` object if the file can be successfully read and unmarshalled.
- error: An error if reading or unmarshalling the file fails.
func (*Module) FindStage ¶
FindStage searches for a stage with the specified name in the module. It iterates through the module's stages and returns the matching stage if found. If no stage with the given name exists, it returns an empty Stage and an error with the message "stage not found".
name - the name of the stage to search for.
Returns:
- Stage: the stage with the matching name.
- error: nil if the stage is found; otherwise, an error indicating that the stage was not found.
func (*Module) GetChanges ¶
func (*Module) GetLabel ¶ added in v1.5.0
func (m *Module) GetLabel() types.VersionLabel
func (*Module) GetVariables ¶
func (*Module) GetVersion ¶
func (*Module) IsLastVersion ¶
func (*Module) IsValid ¶
IsValid validates the fields of the Module struct.
It checks the following conditions:
- The `Name` field must not be an empty string and must not contain spaces.
- The `Version` field must be a valid version, validated by the `ValidateVersion` function.
- The `Account` field must not be empty.
- If the `Variables` map is not nil, it checks that each key and value in the map is non-empty.
- The `Stages` field must contain at least one stage. Each stage must have a valid `Name`, `To` field, and an `ActionIfFileExists` field. Additionally, each `From` path in a stage must be non-empty.
- If the `Ignore` field is not empty, each rule must be non-empty.
- The `NormalizeStages` function is called to ensure the validity of the stages after other checks.
If any of these conditions are violated, the method returns an error with a detailed message. If all validations pass, it returns nil.
func (*Module) NormalizeStages ¶
NormalizeStages processes and normalizes the stages in the Module by replacing any variables within the stage fields (Name, To, From) with values from the Module's Variables map.
The method iterates over each stage in the Module's Stages slice, and for each field (Name, To, From), it uses the `ReplaceVariables` function to replace any placeholders with corresponding variable values.
If any error occurs while replacing variables or processing the stages, it returns the error. If no errors are encountered, it returns nil.
Returns:
- error: Any error that occurred during the variable replacement process. If successful, returns nil.
func (*Module) PasswordEnv ¶
PasswordEnv returns the environment variable name that stores the password for the module.
The variable name is generated based on the module's name:
- Converted to uppercase
- All dots (".") are replaced with underscores ("_")
- The suffix "_PASSWORD" is appended
For example, for a module named "my.module", the function will return "MY_MODULE_PASSWORD".
func (*Module) SourceCount ¶ added in v1.5.2
func (*Module) StageCallback ¶
func (m *Module) StageCallback(stageName string) (interfaces.Runnable, error)
StageCallback returns the callback associated with the given stage. If no matching callback is found, an error is returned.
stageName - the name of the stage to find the callback for.
Returns:
- Runnable - the found callback if it exists.
- error - an error if the callback is not found.
func (*Module) ToYAML ¶
ToYAML converts the Module struct to its YAML representation.
It uses the `yaml.Marshal` function to serialize the `Module` struct into a YAML format. If the conversion is successful, it returns the resulting YAML as a byte slice. If an error occurs during marshaling, it returns the error.
Returns:
- []byte: The YAML representation of the Module struct.
- error: Any error that occurred during the marshaling process.
func (*Module) ValidateChangelog ¶
ValidateChangelog validates the changelog configuration of the module. It checks for the presence and correctness of required fields:
- Ensures 'repository' is specified if 'from' or 'to' types are defined.
- Validates that 'from' and 'to' types are either 'commit' or 'tag'.
- Confirms 'from' and 'to' values are non-empty.
- If 'condition' is specified, checks that:
- a Condition type is either 'include' or 'exclude'.
- Condition values are non-empty and valid regular expressions.
Returns an error detailing the first encountered validation issue, or nil if the configuration is valid.
func (*Module) ZipPath ¶
ZipPath generates the absolute path for the ZIP file associated with the Module.
The method constructs a path by combining the Module's BuildDirectory and Version fields, appending the ".zip" extension. It then checks if the path exists and is valid using the `CheckPath` function.
If the path is valid, it returns the cleaned absolute path of the ZIP file. If any error occurs during path creation or validation, it returns an empty string along with the error.
Returns:
- string: The absolute path of the ZIP file.
- error: Any error encountered during path creation or validation, otherwise nil.
type ModuleBuilder ¶
type ModuleBuilder struct {
// contains filtered or unexported fields
}
func (*ModuleBuilder) Build ¶
func (m *ModuleBuilder) Build(ctx context.Context) error
Build orchestrates the entire build process for the module. It logs the progress of each phase, such as preparation, collection, and Cleanup. If any of these phases fails, the build will be rolled back to ensure a clean state.
The method returns an error if any of the steps (Prepare, Collect, or Cleanup) fail.
func (*ModuleBuilder) Cleanup ¶
func (m *ModuleBuilder) Cleanup()
Cleanup removes any temporary files and directories created during the build process. It ensures the environment is cleaned up by deleting the version-specific build directory.
func (*ModuleBuilder) Collect ¶
func (m *ModuleBuilder) Collect(ctx context.Context) error
Collect gathers the necessary files for the build. It processes each stage in parallel using goroutines to handle file copying. The function creates the necessary directories for each stage and copies files as defined in the stage configuration.
The method returns an error if any stage fails or if there are issues zipping the collected files.
func (*ModuleBuilder) Prepare ¶
func (m *ModuleBuilder) Prepare() error
Prepare sets up the environment for the build process. It validates the module, checks the stages, and creates the necessary directories for the build output and logs. If any validation or directory creation fails, an error will be returned.
The method returns an error if the module is invalid or if directories cannot be created.
func (*ModuleBuilder) Rollback ¶
func (m *ModuleBuilder) Rollback() error
Rollback reverts any changes made during the build process. It deletes the generated zip file and version-specific directories created during the build. This function ensures that any temporary build files are removed and that the environment is restored to its previous state.
The method returns an error if the rollback process fails.