shell

package
v0.999.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DryRunVariableName specifies the environment variable used within shell script to detect if we are in dryrun mode
	DryRunVariableName = "DRY_RUN"
	// CurrentStageVariableName is the environment variable containing the current pipeline stage such as source, condition, target
	CurrentStageVariableName = "UPDATECLI_PIPELINE_STAGE"
)
View Source
const (
	WINOS string = "windows"
)

Variables

View Source
var (
	MappingSpecChangedIf = map[string]interface{}{
		"console/output": nil,
		"exitcode":       &exitcode.Spec{},
		"file/checksum":  &checksum.Spec{},
	}
)

Functions

This section is empty.

Types

type Environment added in v0.28.0

type Environment struct {
	// Name defines the environment variable name
	Name string `yaml:",omitempty" jsonschema:"required"`
	// Value defines the environment variable value
	Value *string `yaml:",omitempty"`
}

Environment is a struct containing information for an environment variable such as its name and its value

func (*Environment) Load added in v0.28.0

func (e *Environment) Load(ignoreNotFound bool) error

Load updates the environment value based on Updatecli environment variables, if the value is not defined yet

func (Environment) String added in v0.28.0

func (e Environment) String() string

func (Environment) Validate added in v0.28.0

func (e Environment) Validate() error

Validate ensures that required parameter are set

type Environments added in v0.28.0

type Environments []Environment
var (
	// DefaultWinEnvVariables is a list of environment variables that are commonly used on Windows
	DefaultWinEnvVariables Environments = Environments{
		{Name: "PATH"},
		{Name: "PSModulePath"},
		{Name: "PSModuleAnalysisCachePath"},
		{Name: "PATHEXT"},
		{Name: "TEMP"},
		{Name: "HOME"},
		{Name: "USERPROFILE"},
		{Name: "PROFILE"},
	}

	DefaultUnixEnvVariables Environments = Environments{
		{Name: "PATH"},
		{Name: "HOME"},
		{Name: "USER"},
		{Name: "LOGNAME"},
		{Name: "SHELL"},
		{Name: "LANG"},
		{Name: "LC_ALL"},
	}
)

func (*Environments) Load added in v0.28.0

func (e *Environments) Load(ignoreNotFound bool) error

Load updates all environment value based on Updatecli environment variables, at the condition that the value is not defined yet

func (Environments) ToStringSlice added in v0.28.0

func (e Environments) ToStringSlice() []string

ToStringSlice return all environment variable key=value as a slice of string

func (Environments) Validate added in v0.28.0

func (e Environments) Validate() error

Validate ensures that we don't have duplicated value for a variable and that the user is not attempting to override the DRY_RUN reserved variable.

type ErrEmptyCommand

type ErrEmptyCommand struct{}

func (*ErrEmptyCommand) Error

func (e *ErrEmptyCommand) Error() string

type ExecutionFailedError

type ExecutionFailedError struct{}

func (*ExecutionFailedError) Error

func (e *ExecutionFailedError) Error() string

type MockCommandExecutor

type MockCommandExecutor struct {
	GotCommand command
	Result     commandResult
	Err        error
}

MockCommandExecutor is a stub implementation of the `commandExecutor` interface to be used in our test suite. It stores the received `command` and returns the preconfigured `result` and `err`.

func (*MockCommandExecutor) ExecuteCommand

func (mce *MockCommandExecutor) ExecuteCommand(cmd command) (commandResult, error)

type Shell

type Shell struct {
	// contains filtered or unexported fields
}

Shell defines a resource of kind "shell"

func New

func New(spec interface{}) (*Shell, error)

New returns a reference to a newly initialized Shell object from a ShellSpec or an error if the provided ShellSpec triggers a validation error.

func (*Shell) Changelog

func (s *Shell) Changelog(from, to string) *result.Changelogs

Changelog returns the changelog for this resource, or an empty string if not supported

func (*Shell) Condition

func (s *Shell) Condition(source string, scm scm.ScmHandler) (pass bool, message string, err error)

Condition tests if the provided command (concatenated with the source) is executed with success

func (*Shell) InitChangedIf added in v0.44.0

func (s *Shell) InitChangedIf() error

func (*Shell) ReportConfig added in v0.99.0

func (s *Shell) ReportConfig() interface{}

ReportConfig returns a new configuration object with only the necessary fields to identify the resource without any sensitive information or context specific data.

func (*Shell) Source

func (s *Shell) Source(workingDir string, resultSource *result.Source) error

Source returns the stdout of the shell command if its exit code is 0 otherwise an error is returned with the content of stderr

func (*Shell) Target

func (s *Shell) Target(source string, scm scm.ScmHandler, dryRun bool, resultTarget *result.Target) error

type Spec

type Spec struct {
	Command string `yaml:",omitempty" jsonschema:"required"`
	// environments allows to pass environment variable(s) to the shell script.
	//
	//  default:
	//     If environments is unset then it depends on the operating system.
	//       - Windows: ["PATH","", "PSModulePath", "PSModuleAnalysisCachePath", "", "PATHEXT", "", "TEMP", "", "HOME", "", "USERPROFILE", "", "PROFILE"]
	//       - Darwin/Linux: ["PATH", "", "HOME", "", "USER", "", "LOGNAME", "", "SHELL", "", "LANG", "", "LC_ALL"]
	//
	// remark:
	//   For security reason, Updatecli doesn't pass the entire environment to the shell command but instead works
	//   with an allow list of environment variables.
	//
	Environments *Environments `yaml:",omitempty"`
	// ChangedIf defines how to interpret shell command execution.
	// What a success means, what an error means, and what a warning would mean in the context of Updatecli.
	//
	// Please note that in the context of Updatecli,
	//  - a success means nothing changed
	//  - a warning means something changed
	//  - an error means something went wrong
	//
	// Changedif can be of kind "exitcode", "console/output", or "file/checksum"
	//
	//   "console/output" (default)
	//     Check the output of the command to identify if Updatecli should report a success, a warning, or an error.
	//     If a target returns anything to stdout, Updatecli interprets it as a something changed, otherwise it's a success.
	//
	//     example:
	//
	//
	//     ---
	//     targets:
	//       default:
	//         name: 'doc: synchronize release note'
	//         kind: 'shell'
	//         disablesourceinput: true
	//         spec:
	//           command: 'releasepost --dry-run="$DRY_RUN" --config {{ .config }} --clean'
	//     ---
	//
	//   "exitcode":
	//     Check the exit code of the command to identify if Updatecli should report a success, a warning, or an error.
	//
	//     example:
	//
	//     ---
	//     targets:
	//       default:
	//         name: 'doc: synchronize release note'
	//         kind: 'shell'
	//         disablesourceinput: true
	//         spec:
	//           command: 'releasepost --dry-run="$DRY_RUN" --config {{ .config }} --clean'
	//           environments:
	//             - name: 'GITHUB_TOKEN'
	//             - name: 'PATH'
	//           changedif:
	//             kind: 'exitcode'
	//             spec:
	//               warning: 0
	//               success: 1
	//               failure: 2
	//     ---
	//
	//
	//   "file/checksum":
	//     Check the checksum of file(s) to identify if Updatecli should report a success, a warning, or an error.
	//
	//     example:
	//
	//     ---
	//     targets:
	//       default:
	//         disablesourceinput: true
	//         name: Example of a shell command with a checksum success criteria
	//         kind: shell
	//         spec:
	//           command: |
	//     	  	   yq -i '.a.b[0].c = "cool"' file.yaml
	//           changedif:
	//             kind: file/checksum
	//             spec:
	//               files:
	//                 - file.yaml
	//     ---
	//
	//
	//
	ChangedIf SpecChangedIf `yaml:",omitempty" json:",omitempty"`
	// Shell specifies which shell interpreter to use.
	//
	// default:
	//   Depends on the operating system:
	//     - Windows: "powershell"
	//     - Darwin/Linux: "/bin/sh"
	//
	Shell string `yaml:",omitempty"`
	// workdir specifies the working directory path from where to execute the command. It defaults to the current context path (scm or current shell). Updatecli join the current path and the one specified in parameter if the parameter one contains a relative path.
	//
	// default: If a scmid is specified then the default
	WorkDir string `yaml:",omitempty"`
}

Spec defines a specification for a "shell" resource parsed from an updatecli manifest file

type SpecChangedIf added in v0.44.0

type SpecChangedIf struct {
	// Kind specifies the success criteria kind, accepted answer ["console/output","exitcode","file/checksum"]
	Kind string `yaml:",omitempty"`
	// Spec specifies the parameter for a specific success criteria kind
	Spec interface{} `yaml:",omitempty"`
}

func (SpecChangedIf) JSONSchema added in v0.44.0

func (SpecChangedIf) JSONSchema() *jschema.Schema

JSONSchema implements the json schema interface to generate the "condition" jsonschema.

type Successer added in v0.44.0

type Successer interface {
	PreCommand(workingDir string) error
	PostCommand(workingDir string) error
	SourceResult(resultSource *result.Source) error
	ConditionResult() (bool, error)
	TargetResult() (bool, error)
}

Directories

Path Synopsis
success

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL