commands

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2023 License: MPL-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Build = cli.LeafCommand("build", "run a build", func(opts *buildOpts) error {
	build, err := opts.build("Running build")
	if err != nil {
		return err
	}
	result, err := build.Result()
	if err != nil {
		return err
	}
	return opts.output.result(opts.desc, result)
})
View Source
var Config = cli.LeafCommand("config", "print config and export to GITHUB_ENV if set", func(opts *configOpts) error {
	cfg, err := config.FromEnvironment(tool, wd)
	if err != nil {
		return err
	}
	if opts.github {
		return cfg.ExportToGitHubEnv()
	}
	return dumpConfig(cfg)
}).WithHelp(`
Print the current configuration, determined by the environment and repository context.

Use the -github flag to export the full configuration to GITHUB_ENV. This is used by the
action to gather configuration from all the inputs as well as the repository context, and
to store that config so that subsequent steps can use it.
`)
View Source
var Inspect = cli.LeafCommand("inspect", "inspect things", func(opts *inspectOpts) error {
	bm, err := opts.build("Inspecting build")
	if err != nil {
		return err
	}

	p := printer{w: os.Stdout, build: bm.Build()}

	if opts.reproducible {
		return p.line("%t", bm.Build().Config().Reproducible)
	}

	if opts.goVersion {
		return p.line(bm.Build().Config().Parameters.GoVersion)
	}

	if opts.buildConfig {
		return json.Write(os.Stdout, bm.Build().Config())
	}

	if opts.buildEnv {
		return p.buildEnv()
	}

	if opts.buildEnvDesc {
		return p.buildEnvDesc()
	}

	if opts.zipInfo {
		return p.zipDetails()
	}

	if opts.worktree {
		return p.worktreeStatus()
	}

	return p.printAll()
})
View Source
var PrimaryBuild = cli.LeafCommand("primary", "run the primary build", func(opts *pbOpts) error {
	pb, err := opts.build()
	if err != nil {
		return err
	}

	result, err := pb.Result()
	if err != nil {
		return err
	}

	return opts.output.result("Primary build", result)

}).WithHelp(primaryBuildHelp)

PrimaryBuild runs the primary build, in the current directory.

View Source
var Root = cli.RootCommand("go-build", "go build and related functions", Build, Verify, Config)

Root is the root command of the whole CLI. It is given the name "go" so that when this CLI is incorporated into a parent CLI, the commands within will be rooted at "go". E.g. "go-build", "go-build primary", "go-build verification".

View Source
var Verify = cli.LeafCommand("verify", "verify a build's reproducibility", func(opts *verifyOpts) error {
	result, err := opts.runVerification()
	if err != nil {
		return err
	}
	if opts.outFile != "" {
		if err := json.WriteFile(opts.outFile, result); err != nil {
			return err
		}
		opts.log("Result written to %s", opts.outFile)
	}
	if opts.stepSummary != "" {
		opts.log("Writing GitHub Step Summary to %s", opts.stepSummary)
		f, err := fs.Append(opts.stepSummary)
		if err != nil {
			return err
		}
		defer f.Close()
		funcs := template.FuncMap{
			"json": func(a any) string {
				s, err := json.String(a)
				if err != nil {
					return fmt.Sprintf("<error: %v>", err)
				}
				return s
			},
		}
		if err := template.Must(template.New("").Funcs(funcs).Parse(stepSummaryTemplate)).Execute(f, result); err != nil {
			return err
		}
	}
	return opts.output.result("Reproducibility verification", result)
})

Functions

func MakeVersionCommand

func MakeVersionCommand(p crt.Product) (*cli.Command, string)

MakeVersionCommand makes the version command and returns that along with the default version string. This pattern is used so that the main package can inject the version info and receive a copy of the default version string that will be returned by this command. This is needed to satisfy the --version flag for mitchellh/cli.

Types

type Result

type Result interface {
	Error() error
	IsFromCache() bool
}

Jump to

Keyboard shortcuts

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