script

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ScriptInitRepo script path for init repo script
	ScriptInitRepo = "git/init_repo.sh"
	// ScriptCreateBranch script path for create branch script
	ScriptCreateBranch = "git/create_branch.sh"
	// ScriptCreateCommit script path for create commit script
	ScriptCreateCommit = "git/create_commit.sh"
	// ScriptCreateMultiCommit script path for create multi commit script
	ScriptCreateMultiCommit = "git/create_multi_commit.sh"
	// ScriptCreateTag script path for create tag script
	ScriptCreateTag = "git/create_tag.sh"
)
View Source
const DefaultScriptOutputPrefix = "##output##"

DefaultScriptOutputPrefix the prefix of script output

Variables

This section is empty.

Functions

func CreateMultiCommit

func CreateMultiCommit(ctx context.Context, branchName, message string, quantity int) (err error)

CreateMultiCommit create new commit using a bash script and vanila git cli returns an error if any

func CreateNewBranch

func CreateNewBranch(ctx context.Context, branchName string) (err error)

CreateNewBranch create new branch using a bash script and vanila git cli returns an error if any

func CreateNewCommit

func CreateNewCommit(ctx context.Context, branchName, message string) (commitId string, err error)

CreateNewCommit create new commit using a bash script and vanila git cli returns an error if any

func CreateNewTag

func CreateNewTag(ctx context.Context, branchName, message, tag string) (err error)

CreateNewTag create new tag using a bash script and vanila git cli returns an error if any

func InitRepo

func InitRepo(ctx context.Context, repoUrl, username, password string) (repoPath string, err error)

InitRepo init repo, e.g: create default branch, submit some files TODO: move to use script builder

func RestoreDirectories

func RestoreDirectories(fs embed.FS, dirName string, targetDir string)

RestoreDirectories restore directories from embed.FS to targetDir

Types

type ScriptBuilder

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

ScriptBuilder script runner for easier initializing of data using scripts while providing option for asserting and processing the result

func NewScript

func NewScript(ctx context.Context, scriptName string, args ...string) *ScriptBuilder

NewScript starts creating a script runner for the given script and args which can be customized by chaining other methods and be finally executed by calling the Result or Error methods

func (*ScriptBuilder) Error

func (r *ScriptBuilder) Error() error

Error runs the script and returns an error if any. This method will discard the ScriptResult object but the output can be written providing a writer using WithOutput method

func (*ScriptBuilder) Result

func (r *ScriptBuilder) Result() *ScriptResult

Result runs the script and returns a ScriptResult object. If and output writer was provided will automatically write the output of the script into the writer.

func (*ScriptBuilder) WithErrorOutput

func (r *ScriptBuilder) WithErrorOutput(writer io.Writer) *ScriptBuilder

WithErrorOutput

func (*ScriptBuilder) WithLocalRepoPath

func (r *ScriptBuilder) WithLocalRepoPath() *ScriptBuilder

WithLocalRepoPath set the repo path from the LocalRepoPathFromCtx function, which normally is already present inside context when adding repo conditions like

func (*ScriptBuilder) WithOutput

func (r *ScriptBuilder) WithOutput(writer io.Writer, prefix ...string) *ScriptBuilder

WithOutput adds an output writer to write text output from script into. The second argument accepts an output prefix from the script which defaults to "##output##

func (*ScriptBuilder) WithRepoPath

func (r *ScriptBuilder) WithRepoPath(repoPath string) *ScriptBuilder

WithRepoPath changes the repository path. By default this value is already initiated using WithLocalRepoPath which will fetch a LocalRepoPath from the context

func (*ScriptBuilder) WithRootFolder

func (r *ScriptBuilder) WithRootFolder(rootFolder string) *ScriptBuilder

WithRootFolder changes the root folder of the scripts. By default this value is already initiated using a variable that can be customized using the E2E_TEMP_DIR environment variable

func (*ScriptBuilder) WithScript

func (r *ScriptBuilder) WithScript(scriptName string, args ...string) *ScriptBuilder

WithScript changes the script initialized by the builder

type ScriptResult

type ScriptResult struct {
	OutputDataPrefix string
	// contains filtered or unexported fields
}

ScriptResult the result of script execution

func ExecBashScript

func ExecBashScript(script string, params ...string) *ScriptResult

ExecBashScript exec bash script with params

func ExecScript

func ExecScript(name string, arg ...string) *ScriptResult

ExecScript exec script with params

func (*ScriptResult) Error

func (p *ScriptResult) Error() error

Error get the error of a script execution

func (*ScriptResult) ExitCode

func (p *ScriptResult) ExitCode() int

ExitCode get the exit code of a script execution

func (*ScriptResult) ExitMessage

func (p *ScriptResult) ExitMessage() string

ExitMessage get the exit message of a script execution

func (*ScriptResult) OutputData

func (p *ScriptResult) OutputData(dataPrefix string) string

OutputData get the output of a script execution, it can be a structured data, e.g: json string

func (*ScriptResult) Stderr

func (p *ScriptResult) Stderr() string

Stderr get the error output of a script execution

func (*ScriptResult) Stdout

func (p *ScriptResult) Stdout() string

Stdout get the output of a script execution

Jump to

Keyboard shortcuts

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