Help us shape the future of Go! Take the 2026 Go Developer Survey

workflow

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Delete = app.Register(&app.Command[app.Empty, app.Empty]{
	Use:    "workflow {name}",
	Desc:   "Delete a workflow",
	Action: "Delete",

	PrepareNoFlag: func(cmd *cobra.Command) {
		cmd.Args = cobra.ExactArgs(1)
		cmd.ValidArgsFunction = app.Comp(app.CompWorkflow)
	},

	Run: func(ctx *app.Context[app.Empty, app.Empty]) error {
		name := ctx.Arg(0)
		path := config.GetDir("workflows", name+".yaml")
		return app.Delete(ctx.Arg(0), path)
	},
})
View Source
var Edit = app.Register(&app.Command[app.Empty, app.Empty]{
	Use:    "workflow {workflow}",
	Desc:   "Edit workflow file",
	Action: "Edit",

	PrepareNoFlag: func(cmd *cobra.Command) {
		cmd.Args = cobra.ExactArgs(1)
		cmd.ValidArgsFunction = app.Comp(app.CompWorkflow)
	},

	Run: func(ctx *app.Context[app.Empty, app.Empty]) error {
		name := fmt.Sprintf("%s.yaml", ctx.Arg(0))
		path := config.GetDir("workflows", name)
		return app.Edit(path, config.DefaultWorkflow, name, func(s string) error {
			data := []byte(s)
			var wf core.Workflow
			err := yaml.Unmarshal(data, &wf)
			if err != nil {
				return errors.Trace(err, "parse yaml")
			}
			return validate.Do(&wf)
		})
	},
})
View Source
var Workflow = app.Register(&app.Command[WorkflowFlags, app.Empty]{
	Use:  "run [-y] [-c] {workflow}",
	Desc: "Run workflow",

	Prepare: func(cmd *cobra.Command, flags *WorkflowFlags) {
		cmd.Flags().BoolVarP(&flags.Current, "current", "c", false, "run workflow on current repo")
		cmd.Flags().BoolVarP(&flags.Edit, "edit", "e", false, "edit repo to run")
		cmd.Flags().StringVarP(&flags.LogPath, "log-path", "", "", "log file path")

		cmd.Args = cobra.ExactArgs(1)
		cmd.ValidArgsFunction = app.Comp(app.CompWorkflow)
	},

	Run: func(ctx *app.Context[WorkflowFlags, app.Empty]) error {
		wf, err := core.GetWorkflow(ctx.Arg(0))
		if err != nil {
			return err
		}
		store, err := core.NewRepositoryStorage()
		if err != nil {
			return err
		}
		store.ReadOnly()

		if ctx.Flags.Current {
			return workflowRunCurrent(store, wf)
		}

		if wf.Select == nil {
			term.Println("nothing to do")
			return nil
		}

		items, err := wf.Select.Match(store)
		if err != nil {
			return err
		}
		if len(items) == 0 {
			term.Println("no repo selected")
			return nil
		}
		if ctx.Flags.Edit {
			items, err = term.EditItems(config.Get().Editor, items,
				func(item *core.WorkflowMatchItem) string {
					return item.Path
				})
			if err != nil {
				return err
			}
		}

		repoWord := english.Plural(len(items), "repo", "repos")
		term.ConfirmExit("Do you want to run workflow %s for %s", ctx.Arg(0), repoWord)

		return workflowRun(ctx, wf.Jobs, items)
	},
})

Functions

This section is empty.

Types

type WorkflowFlags

type WorkflowFlags struct {
	Edit bool

	Current bool

	LogPath string
}

Jump to

Keyboard shortcuts

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