From 78110323782d53f6e2b3a0e6bd09feb77c8cfdee Mon Sep 17 00:00:00 2001 From: Will Roden Date: Thu, 1 Jun 2023 08:14:31 -0500 Subject: [PATCH 01/22] format --- bindown.yml | 484 ++++++++++++++++++++++++++-------------------------- 1 file changed, 242 insertions(+), 242 deletions(-) diff --git a/bindown.yml b/bindown.yml index 47a48d05..1e680318 100644 --- a/bindown.yml +++ b/bindown.yml @@ -1,10 +1,10 @@ cache: ./bin/.bindown install_dir: ./bin systems: -- darwin/amd64 -- darwin/arm64 -- linux/amd64 -- windows/amd64 + - darwin/amd64 + - darwin/arm64 + - linux/amd64 + - windows/amd64 dependencies: gh: template: origin#gh @@ -55,7 +55,7 @@ templates: url: https://github.com/WillAbides/bindown/releases/download/{{.tag}}/checksums.txt bin: checksums.txt required_vars: - - tag + - tag origin#gh: url: https://github.com/cli/cli/releases/download/v{{.version}}/gh_{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: gh_{{.version}}_{{.os}}_{{.arch}}/bin/gh{{.archivePathSuffix}} @@ -63,42 +63,42 @@ templates: vars: archivePathSuffix: "" urlSuffix: .zip - required_vars: - - version overrides: - - matcher: - os: - - windows - dependency: - archive_path: bin/gh{{.archivePathSuffix}} - vars: - archivePathSuffix: .exe - - matcher: - os: - - linux - dependency: - vars: - urlSuffix: .tar.gz - - matcher: - os: - - darwin - version: - - < 2.28.0 - dependency: - vars: - urlSuffix: .tar.gz + - matcher: + os: + - windows + dependency: + archive_path: bin/gh{{.archivePathSuffix}} + vars: + archivePathSuffix: .exe + - matcher: + os: + - linux + dependency: + vars: + urlSuffix: .tar.gz + - matcher: + os: + - darwin + version: + - < 2.28.0 + dependency: + vars: + urlSuffix: .tar.gz substitutions: os: darwin: macOS systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - windows/386 - - windows/amd64 - - windows/arm64 + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 + - windows/arm64 + required_vars: + - version origin#go: url: https://dl.google.com/go/go{{.version}}.{{.os}}-{{.arch}}{{.urlSuffix}} archive_path: go/bin/go{{.archivePathSuffix}} @@ -107,29 +107,29 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz - required_vars: - - version overrides: - - matcher: - os: - - windows - dependency: - vars: - archivePathSuffix: .exe - urlSuffix: .zip + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe + urlSuffix: .zip systems: - - darwin/amd64 - - darwin/arm64 - - freebsd/386 - - freebsd/amd64 - - linux/386 - - linux/amd64 - - linux/arm64 - - linux/ppc64le - - linux/s390x - - windows/386 - - windows/amd64 - - windows/arm64 + - darwin/amd64 + - darwin/arm64 + - freebsd/386 + - freebsd/amd64 + - linux/386 + - linux/amd64 + - linux/arm64 + - linux/ppc64le + - linux/s390x + - windows/386 + - windows/amd64 + - windows/arm64 + required_vars: + - version origin#gofumpt: url: https://github.com/mvdan/gofumpt/releases/download/v{{.version}}/gofumpt_v{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: gofumpt_v{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} @@ -137,23 +137,23 @@ templates: vars: archivePathSuffix: "" urlSuffix: "" - required_vars: - - version overrides: - - matcher: - os: - - windows - dependency: - vars: - urlSuffix: .exe + - matcher: + os: + - windows + dependency: + vars: + urlSuffix: .exe systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - windows/386 - - windows/amd64 + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 + required_vars: + - version origin#golangci-lint: url: https://github.com/golangci/golangci-lint/releases/download/v{{.version}}/golangci-lint-{{.version}}-{{.os}}-{{.arch}}{{.urlSuffix}} archive_path: golangci-lint-{{.version}}-{{.os}}-{{.arch}}/golangci-lint{{.archivePathSuffix}} @@ -161,35 +161,35 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz - required_vars: - - version overrides: - - matcher: - os: - - windows - dependency: - vars: - archivePathSuffix: .exe - urlSuffix: .zip + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe + urlSuffix: .zip systems: - - darwin/amd64 - - darwin/arm64 - - freebsd/386 - - freebsd/amd64 - - linux/386 - - linux/amd64 - - linux/arm64 - - linux/loong64 - - linux/mips64 - - linux/mips64le - - linux/ppc64le - - linux/riscv64 - - linux/s390x - - netbsd/386 - - netbsd/amd64 - - windows/386 - - windows/amd64 - - windows/arm64 + - darwin/amd64 + - darwin/arm64 + - freebsd/386 + - freebsd/amd64 + - linux/386 + - linux/amd64 + - linux/arm64 + - linux/loong64 + - linux/mips64 + - linux/mips64le + - linux/ppc64le + - linux/riscv64 + - linux/s390x + - netbsd/386 + - netbsd/amd64 + - windows/386 + - windows/amd64 + - windows/arm64 + required_vars: + - version origin#goreleaser: url: https://github.com/goreleaser/goreleaser/releases/download/v{{.version}}/goreleaser_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: goreleaser{{.archivePathSuffix}} @@ -197,22 +197,20 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz - required_vars: - - version overrides: - - matcher: - os: - - windows - dependency: - vars: - archivePathSuffix: .exe - urlSuffix: .zip - substitutions: - arch: - "386": i386 - amd64: x86_64 + - matcher: os: - windows: Windows + - windows + dependency: + vars: + archivePathSuffix: .exe + urlSuffix: .zip + substitutions: + arch: + "386": i386 + amd64: x86_64 + os: + windows: Windows substitutions: arch: "386": i386 @@ -221,39 +219,39 @@ templates: darwin: Darwin linux: Linux systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - linux/ppc64 - - windows/386 - - windows/amd64 - - windows/arm64 + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - linux/ppc64 + - windows/386 + - windows/amd64 + - windows/arm64 + required_vars: + - version origin#jq: url: https://github.com/stedolan/jq/releases/download/jq-{{.version}}/jq-{{.os}}{{.arch}}{{.extension}} archive_path: jq-{{.os}}{{.arch}}{{.extension}} bin: jq vars: extension: "" - required_vars: - - version overrides: - - matcher: - arch: - - amd64 - - arm64 - os: - - darwin - dependency: - url: https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64 - archive_path: jq-osx-amd64 - - matcher: - os: - - windows - dependency: - vars: - extension: .exe + - matcher: + arch: + - amd64 + - arm64 + os: + - darwin + dependency: + url: https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64 + archive_path: jq-osx-amd64 + - matcher: + os: + - windows + dependency: + vars: + extension: .exe substitutions: arch: "386": "32" @@ -261,12 +259,14 @@ templates: os: windows: win systems: - - linux/386 - - linux/amd64 - - darwin/amd64 - - darwin/arm64 - - windows/386 - - windows/amd64 + - linux/386 + - linux/amd64 + - darwin/amd64 + - darwin/arm64 + - windows/386 + - windows/amd64 + required_vars: + - version origin#semver-next: url: https://github.com/WillAbides/semver-next/releases/download/v{{.version}}/semver-next_{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: semver-next{{.archivePathSuffix}} @@ -274,24 +274,24 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz - required_vars: - - version overrides: - - matcher: - os: - - windows - dependency: - vars: - archivePathSuffix: .exe + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - windows/386 - - windows/amd64 - - windows/arm64 + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 + - windows/arm64 + required_vars: + - version origin#semver-prev: url: https://github.com/WillAbides/semver-prev/releases/download/v{{.version}}/semver-prev_{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: semver-prev{{.archivePathSuffix}} @@ -299,24 +299,24 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz - required_vars: - - version overrides: - - matcher: - os: - - windows - dependency: - vars: - archivePathSuffix: .exe + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - windows/386 - - windows/amd64 - - windows/arm64 + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 + - windows/arm64 + required_vars: + - version origin#shellcheck: url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.{{.os}}.{{.arch}}{{.urlSuffix}} archive_path: shellcheck-v{{.version}}/shellcheck{{.archivePathSuffix}} @@ -324,33 +324,33 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.xz - required_vars: - - version overrides: - - matcher: - os: - - windows - dependency: - url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.zip - archive_path: shellcheck.exe - - matcher: - arch: - - arm64 - os: - - darwin - dependency: - substitutions: + - matcher: + os: + - windows + dependency: + url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.zip + archive_path: shellcheck.exe + - matcher: arch: - arm64: x86_64 + - arm64 + os: + - darwin + dependency: + substitutions: + arch: + arm64: x86_64 substitutions: arch: amd64: x86_64 arm64: aarch64 systems: - - darwin/amd64 - - darwin/arm64 - - linux/amd64 - - linux/arm64 + - darwin/amd64 + - darwin/arm64 + - linux/amd64 + - linux/arm64 + required_vars: + - version origin#shfmt: url: https://github.com/mvdan/sh/releases/download/v{{.version}}/shfmt_v{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: shfmt_v{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} @@ -358,23 +358,23 @@ templates: vars: archivePathSuffix: "" urlSuffix: "" - required_vars: - - version overrides: - - matcher: - os: - - windows - dependency: - vars: - urlSuffix: .exe + - matcher: + os: + - windows + dependency: + vars: + urlSuffix: .exe systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - windows/386 - - windows/amd64 + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 + required_vars: + - version origin#yq: url: https://github.com/mikefarah/yq/releases/download/v{{.version}}/yq_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: ./yq_{{.os}}_{{.arch}}{{.archivePathSuffix}} @@ -382,38 +382,38 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz - required_vars: - - version overrides: - - matcher: - os: - - windows - dependency: - archive_path: yq_{{.os}}_{{.arch}}{{.archivePathSuffix}} - vars: - archivePathSuffix: .exe - urlSuffix: .zip + - matcher: + os: + - windows + dependency: + archive_path: yq_{{.os}}_{{.arch}}{{.archivePathSuffix}} + vars: + archivePathSuffix: .exe + urlSuffix: .zip systems: - - darwin/amd64 - - darwin/arm64 - - freebsd/386 - - freebsd/amd64 - - linux/386 - - linux/amd64 - - linux/arm64 - - linux/mips - - linux/mips64 - - linux/mips64le - - linux/mipsle - - linux/ppc64 - - linux/ppc64le - - linux/s390x - - netbsd/386 - - netbsd/amd64 - - openbsd/386 - - openbsd/amd64 - - windows/386 - - windows/amd64 + - darwin/amd64 + - darwin/arm64 + - freebsd/386 + - freebsd/amd64 + - linux/386 + - linux/amd64 + - linux/arm64 + - linux/mips + - linux/mips64 + - linux/mips64le + - linux/mipsle + - linux/ppc64 + - linux/ppc64le + - linux/s390x + - netbsd/386 + - netbsd/amd64 + - openbsd/386 + - openbsd/amd64 + - windows/386 + - windows/amd64 + required_vars: + - version template_sources: origin: https://raw.githubusercontent.com/WillAbides/bindown-templates/main/bindown.yml url_checksums: From ea91911e3924237ce6b9aa0bfbccb46494b09429 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Thu, 1 Jun 2023 08:41:46 -0500 Subject: [PATCH 02/22] on `dependency add` make tmpl default to the same as name. --- bindown.yml | 2 ++ cmd/bindown/dependency.go | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/bindown.yml b/bindown.yml index 1e680318..9965665a 100644 --- a/bindown.yml +++ b/bindown.yml @@ -57,6 +57,8 @@ templates: required_vars: - tag origin#gh: + homepage: https://github.com/cli/cli + description: GitHub’s official command line tool url: https://github.com/cli/cli/releases/download/v{{.version}}/gh_{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: gh_{{.version}}_{{.os}}_{{.arch}}/bin/gh{{.archivePathSuffix}} bin: gh diff --git a/cmd/bindown/dependency.go b/cmd/bindown/dependency.go index 056756cb..fb86fbb6 100644 --- a/cmd/bindown/dependency.go +++ b/cmd/bindown/dependency.go @@ -157,10 +157,10 @@ func (c *dependencyRemoveCmd) Run(ctx *runContext) error { type dependencyAddCmd struct { Name string `kong:"arg"` - Template string `kong:"arg,predictor=template"` + Template string `kong:"arg,optional,predictor=template"` TemplateSource string `kong:"name=source,help='template source',predictor=templateSource"` Vars map[string]string `kong:"name=var"` - SkipRequiredVars bool `kong:"name=skipvars,help='do not prompt for required vars'"` + SkipRequiredVars bool `kong:"name=skipvars,help='do not prompt for required vars. implies --skipchecksums'"` SkipChecksums bool `kong:"name=skipchecksums,help='do not add checksums for this dependency'"` } @@ -170,12 +170,14 @@ func (c *dependencyAddCmd) Run(ctx *runContext) error { return err } tmpl := c.Template + if tmpl == "" { + tmpl = c.Name + } tmplSrc := c.TemplateSource if tmplSrc == "" { - tmplParts := strings.SplitN(tmpl, "#", 2) - if len(tmplParts) == 2 { - tmpl = tmplParts[1] - tmplSrc = tmplParts[0] + ts, t, ok := strings.Cut(tmpl, "#") + if ok { + tmplSrc, tmpl = ts, t } } @@ -194,9 +196,7 @@ func (c *dependencyAddCmd) Run(ctx *runContext) error { if err != nil { return err } - hasMissingVars := len(missingVars) > 0 - if hasMissingVars && !c.SkipRequiredVars { - hasMissingVars = false + if len(missingVars) > 0 && !c.SkipRequiredVars { scanner := bufio.NewScanner(ctx.stdin) for _, missingVar := range missingVars { fmt.Fprintf(ctx.stdout, "Please enter a value for required variable %q:\t", missingVar) @@ -209,7 +209,8 @@ func (c *dependencyAddCmd) Run(ctx *runContext) error { config.Dependencies[c.Name].Vars[missingVar] = val } } - if !hasMissingVars && !c.SkipChecksums { + skipChecksums := c.SkipChecksums || c.SkipRequiredVars + if !skipChecksums { err = config.AddChecksums([]string{c.Name}, nil) if err != nil { return err From 4800409b253c8f0eaa49ffedc055fa74726a24df Mon Sep 17 00:00:00 2001 From: Will Roden Date: Thu, 1 Jun 2023 13:04:13 -0500 Subject: [PATCH 03/22] output known versions --- bindown.yml | 2 + cmd/bindown/dependency.go | 40 +++++++++++++++- cmd/bindown/dependency_test.go | 15 +++++- internal/bindown/config.go | 58 ++++++++++++++--------- internal/bindown/config_test.go | 18 +++---- internal/build-bootstrapper/build_test.go | 3 ++ 6 files changed, 103 insertions(+), 33 deletions(-) diff --git a/bindown.yml b/bindown.yml index 9965665a..4612abff 100644 --- a/bindown.yml +++ b/bindown.yml @@ -233,6 +233,8 @@ templates: required_vars: - version origin#jq: + homepage: https://github.com/stedolan/jq + description: Command-line JSON processor url: https://github.com/stedolan/jq/releases/download/jq-{{.version}}/jq-{{.os}}{{.arch}}{{.extension}} archive_path: jq-{{.os}}{{.arch}}{{.extension}} bin: jq diff --git a/cmd/bindown/dependency.go b/cmd/bindown/dependency.go index fb86fbb6..e4866a6b 100644 --- a/cmd/bindown/dependency.go +++ b/cmd/bindown/dependency.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "regexp" + "sort" "strings" "github.com/willabides/bindown/v4/internal/bindown" @@ -184,7 +185,7 @@ func (c *dependencyAddCmd) Run(ctx *runContext) error { if c.Vars == nil { c.Vars = map[string]string{} } - err = config.AddDependencyFromTemplate(ctx, tmpl, &bindown.AddDependencyFromTemplateOpts{ + dep, varVals, err := config.AddDependencyFromTemplate(ctx, tmpl, &bindown.AddDependencyFromTemplateOpts{ DependencyName: c.Name, TemplateSource: tmplSrc, Vars: c.Vars, @@ -192,13 +193,50 @@ func (c *dependencyAddCmd) Run(ctx *runContext) error { if err != nil { return err } + // This shouldn't be possible, but just in case + if dep.Template == nil || config.Templates == nil || config.Templates[*dep.Template] == nil { + return fmt.Errorf("template not found: %q", tmpl) + } + if varVals == nil { + varVals = map[string][]string{} + } missingVars, err := config.MissingDependencyVars(c.Name) if err != nil { return err } + tmplCfg := config.Templates[*dep.Template] + // Don't need to output the list of systems + systems := tmplCfg.Systems + tmplCfg.Systems = nil + fmt.Fprintf(ctx.stdout, "Adding dependency %q from template ", c.Name) + err = bindown.EncodeYaml(ctx.stdout, map[string]bindown.Dependency{ + *dep.Template: *tmplCfg, + }) + if err != nil { + return err + } + tmplCfg.Systems = systems + if len(missingVars) > 0 && !c.SkipRequiredVars { + for _, d := range config.Dependencies { + if d.Template == nil || dep.Template == nil || *d.Template != *dep.Template { + continue + } + for k, v := range d.Vars { + varVals[k] = append([]string{v}, varVals[k]...) + } + } + scanner := bufio.NewScanner(ctx.stdin) for _, missingVar := range missingVars { + knownVals := varVals[missingVar] + sort.Strings(knownVals) + if len(knownVals) > 0 { + fmt.Fprintf(ctx.stdout, "Known values for %q:\n", missingVar) + for _, v := range knownVals { + fmt.Fprintf(ctx.stdout, " %s\n", v) + } + } fmt.Fprintf(ctx.stdout, "Please enter a value for required variable %q:\t", missingVar) scanner.Scan() err = scanner.Err() diff --git a/cmd/bindown/dependency_test.go b/cmd/bindown/dependency_test.go index db4dcdfd..41415875 100644 --- a/cmd/bindown/dependency_test.go +++ b/cmd/bindown/dependency_test.go @@ -463,6 +463,12 @@ dependencies: runner := newCmdRunner(t) runner.writeConfigYaml(` systems: ["linux/amd64", "darwin/amd64"] +dependencies: + dep2: + template: tmpl + vars: + version: "1.2.3" + foo: bar templates: tmpl: url: foo-{{ .os }}-{{ .arch }}-{{ .version }} @@ -475,7 +481,11 @@ url_checksums: runner.stdin = strings.NewReader("1.2.3\nbar") result := runner.run("dependency", "add", "dep1", "tmpl") result.assertState(resultState{ - stdout: `Please enter a value for required variable "version": Please enter a value for required variable "foo":`, + stdout: `Known values for "version": + 1.2.3 +Please enter a value for required variable "version": Known values for "foo": + bar +Please enter a value for required variable "foo":`, }) cfg := runner.getConfigFile() wantDep := mustConfigFromYAML(t, ` @@ -506,7 +516,8 @@ systems: ["darwin/amd64", "darwin/arm64", "linux/amd64", "windows/amd64"] template_sources: origin: %q `, srcPath)) - wantStdout := `Please enter a value for required variable "version": Please enter a value for required variable "addr": ` + wantStdout := `Missing required vars from template "tmpl1" +Please enter a value for required variable "version": Please enter a value for required variable "addr": ` runner.stdin = strings.NewReader(fmt.Sprintf("%s\n%s", "1.2.3", server.URL)) result := runner.run("dependency", "add", "foo", "tmpl1", "--source", "origin") require.Equal(t, 0, result.exitVal) diff --git a/internal/bindown/config.go b/internal/bindown/config.go index 48a88bcc..baaee9ba 100644 --- a/internal/bindown/config.go +++ b/internal/bindown/config.go @@ -454,10 +454,10 @@ type AddDependencyFromTemplateOpts struct { Vars map[string]string } -// AddDependencyFromTemplate adds a dependency to the config -func (c *Config) AddDependencyFromTemplate(ctx context.Context, templateName string, opts *AddDependencyFromTemplateOpts) error { +// AddDependencyFromTemplate adds a dependency to the config. Returns a map of known values for template vars +func (c *Config) AddDependencyFromTemplate(ctx context.Context, templateName string, opts *AddDependencyFromTemplateOpts) (*Dependency, map[string][]string, error) { if opts == nil { - opts = new(AddDependencyFromTemplateOpts) + opts = &AddDependencyFromTemplateOpts{} } dependencyName := opts.DependencyName if dependencyName == "" { @@ -467,29 +467,32 @@ func (c *Config) AddDependencyFromTemplate(ctx context.Context, templateName str c.Dependencies = map[string]*Dependency{} } if c.Dependencies[dependencyName] != nil { - return fmt.Errorf("dependency named %q already exists", dependencyName) + return nil, nil, fmt.Errorf("dependency named %q already exists", dependencyName) } - templateName, err := c.addOrGetTemplate(ctx, templateName, opts.TemplateSource) + templateName, varVals, err := c.addOrGetTemplate(ctx, templateName, opts.TemplateSource) if err != nil { - return err + return nil, nil, err + } + dep := &Dependency{ + Overrideable: Overrideable{ + Vars: opts.Vars, + }, + Template: &templateName, } - dep := new(Dependency) - dep.Vars = opts.Vars - dep.Template = &templateName c.Dependencies[dependencyName] = dep - return nil + return dep, varVals, nil } -func (c *Config) addOrGetTemplate(ctx context.Context, name, src string) (string, error) { - destName := name +func (c *Config) addOrGetTemplate(ctx context.Context, name, src string) (destName string, varVals map[string][]string, _ error) { + destName = name if src != "" { destName = fmt.Sprintf("%s#%s", src, name) } if _, ok := c.Templates[destName]; ok { - return destName, nil + return destName, nil, nil } if src == "" { - return "", fmt.Errorf("no template named %q", name) + return "", nil, fmt.Errorf("no template named %q", name) } tmplSrc := src tmplSrcs := c.TemplateSources @@ -499,11 +502,12 @@ func (c *Config) addOrGetTemplate(ctx context.Context, name, src string) (string if _, ok := tmplSrcs[tmplSrc]; ok { tmplSrc = tmplSrcs[tmplSrc] } - err := c.addTemplateFromSource(ctx, tmplSrc, name, destName) + var err error + varVals, err = c.addTemplateFromSource(ctx, tmplSrc, name, destName) if err != nil { - return "", err + return "", nil, err } - return destName, nil + return destName, varVals, nil } // CopyTemplateFromSource copies a template from source @@ -515,24 +519,34 @@ func (c *Config) CopyTemplateFromSource(ctx context.Context, src, srcTemplate, d if tmplSrc == "" { return fmt.Errorf("no template source named %q", src) } - return c.addTemplateFromSource(ctx, tmplSrc, srcTemplate, destName) + _, err := c.addTemplateFromSource(ctx, tmplSrc, srcTemplate, destName) + return err } // addTemplateFromSource copies a template from another config file -func (c *Config) addTemplateFromSource(ctx context.Context, src, srcTemplate, destName string) error { +func (c *Config) addTemplateFromSource(ctx context.Context, src, srcTemplate, destName string) (map[string][]string, error) { srcCfg, err := NewConfig(ctx, src, true) if err != nil { - return err + return nil, err } tmpl := srcCfg.Templates[srcTemplate] if tmpl == nil { - return fmt.Errorf("source has no template named %q", srcTemplate) + return nil, fmt.Errorf("source has no template named %q", srcTemplate) + } + varVals := map[string][]string{} + for _, dep := range srcCfg.Dependencies { + if dep.Template == nil || *dep.Template != srcTemplate { + continue + } + for k, v := range dep.Vars { + varVals[k] = append(varVals[k], v) + } } if c.Templates == nil { c.Templates = map[string]*Dependency{} } c.Templates[destName] = tmpl - return nil + return varVals, nil } func (c *Config) templatesList() []string { diff --git a/internal/bindown/config_test.go b/internal/bindown/config_test.go index f2eb4bce..e4336f30 100644 --- a/internal/bindown/config_test.go +++ b/internal/bindown/config_test.go @@ -152,26 +152,27 @@ func TestConfig_addTemplateFromSource(t *testing.T) { ctx := context.Background() t.Run("file", func(t *testing.T) { t.Run("success", func(t *testing.T) { - cfg := new(Config) + cfg := &Config{} src := filepath.Join("testdata", "configs", "ex1.yaml") srcCfg, err := NewConfig(ctx, src, true) require.NoError(t, err) - err = cfg.addTemplateFromSource(ctx, src, "goreleaser", "mygoreleaser") + varVals, err := cfg.addTemplateFromSource(ctx, src, "goreleaser", "mygoreleaser") require.NoError(t, err) require.Equal(t, srcCfg.Templates["goreleaser"], cfg.Templates["mygoreleaser"]) + require.Equal(t, map[string][]string{"version": {"0.120.7"}}, varVals) }) t.Run("missing template", func(t *testing.T) { - cfg := new(Config) + cfg := &Config{} src := filepath.Join("testdata", "configs", "ex1.yaml") - err := cfg.addTemplateFromSource(ctx, src, "fake", "myfake") + _, err := cfg.addTemplateFromSource(ctx, src, "fake", "myfake") require.EqualError(t, err, `source has no template named "fake"`) }) t.Run("missing file", func(t *testing.T) { - cfg := new(Config) + cfg := &Config{} src := filepath.Join("testdata", "configs", "thisdoesnotexist.yaml") - err := cfg.addTemplateFromSource(ctx, src, "fake", "myfake") + _, err := cfg.addTemplateFromSource(ctx, src, "fake", "myfake") require.Error(t, err) require.True(t, os.IsNotExist(err)) }) @@ -180,13 +181,14 @@ func TestConfig_addTemplateFromSource(t *testing.T) { t.Run("http", func(t *testing.T) { srcFile := filepath.Join("testdata", "configs", "ex1.yaml") ts := testutil.ServeFile(t, srcFile, "/ex1.yaml", "") - cfg := new(Config) + cfg := &Config{} src := ts.URL + "/ex1.yaml" srcCfg, err := NewConfig(ctx, srcFile, true) require.NoError(t, err) - err = cfg.addTemplateFromSource(ctx, src, "goreleaser", "mygoreleaser") + varVals, err := cfg.addTemplateFromSource(ctx, src, "goreleaser", "mygoreleaser") require.NoError(t, err) require.Equal(t, srcCfg.Templates["goreleaser"], cfg.Templates["mygoreleaser"]) + require.Equal(t, map[string][]string{"version": {"0.120.7"}}, varVals) }) } diff --git a/internal/build-bootstrapper/build_test.go b/internal/build-bootstrapper/build_test.go index 361cdc18..a7687092 100644 --- a/internal/build-bootstrapper/build_test.go +++ b/internal/build-bootstrapper/build_test.go @@ -11,6 +11,9 @@ import ( ) func TestBuild(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode.") + } // This doesn't work on windows, and for now I don't care because it is only used in CI if runtime.GOOS == "windows" { t.Skip("skipping on windows") From 032e8f445be85da51425543d4da11078f4f2dd14 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Thu, 1 Jun 2023 13:18:29 -0500 Subject: [PATCH 04/22] fix tests --- cmd/bindown/dependency_test.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/cmd/bindown/dependency_test.go b/cmd/bindown/dependency_test.go index 41415875..59805b49 100644 --- a/cmd/bindown/dependency_test.go +++ b/cmd/bindown/dependency_test.go @@ -362,7 +362,9 @@ url_checksums: foo-darwin-amd64-1.2.3: deadbeef `) result := runner.run("dependency", "add", "dep1", "tmpl", "--var=version=1.2.3") - result.assertState(resultState{}) + result.assertState(resultState{ + stdout: `Adding dependency "dep1" from template tmpl`, + }) cfg := runner.getConfigFile() wantDep := mustConfigFromYAML(t, ` dependencies: @@ -417,7 +419,9 @@ templates: `), 0o600) require.NoError(t, err) result := runner.run("dependency", "add", "dep1", "tmpl", "--var=version=1.2.3", "--source=origin") - result.assertState(resultState{}) + result.assertState(resultState{ + stdout: `Adding dependency "dep1" from template origin#tmpl`, + }) wantDep := mustConfigFromYAML(t, ` dependencies: dep1: @@ -448,7 +452,9 @@ templates: `), 0o600) require.NoError(t, err) result := runner.run("dependency", "add", "dep1", "origin#tmpl", "--var=version=1.2.3") - result.assertState(resultState{}) + result.assertState(resultState{ + stdout: `Adding dependency "dep1" from template origin#tmpl`, + }) wantDep := mustConfigFromYAML(t, ` dependencies: dep1: @@ -516,12 +522,11 @@ systems: ["darwin/amd64", "darwin/arm64", "linux/amd64", "windows/amd64"] template_sources: origin: %q `, srcPath)) - wantStdout := `Missing required vars from template "tmpl1" -Please enter a value for required variable "version": Please enter a value for required variable "addr": ` runner.stdin = strings.NewReader(fmt.Sprintf("%s\n%s", "1.2.3", server.URL)) result := runner.run("dependency", "add", "foo", "tmpl1", "--source", "origin") - require.Equal(t, 0, result.exitVal) - require.Equal(t, wantStdout, result.stdOut.String()) + result.assertState(resultState{ + stdout: `Adding dependency "foo" from template origin#tmpl`, + }) gotCfg := runner.getConfigFile() wantDep := mustConfigFromYAML(t, fmt.Sprintf(` dependencies: From c72442eab69811dde099c320bdeb2c682efd53b2 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Thu, 1 Jun 2023 13:39:52 -0500 Subject: [PATCH 05/22] SortBySemverOrString --- cmd/bindown/dependency.go | 3 +-- internal/bindown/util.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/cmd/bindown/dependency.go b/cmd/bindown/dependency.go index e4866a6b..836e454b 100644 --- a/cmd/bindown/dependency.go +++ b/cmd/bindown/dependency.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "regexp" - "sort" "strings" "github.com/willabides/bindown/v4/internal/bindown" @@ -230,7 +229,7 @@ func (c *dependencyAddCmd) Run(ctx *runContext) error { scanner := bufio.NewScanner(ctx.stdin) for _, missingVar := range missingVars { knownVals := varVals[missingVar] - sort.Strings(knownVals) + bindown.SortBySemverOrString(knownVals) if len(knownVals) > 0 { fmt.Fprintf(ctx.stdout, "Known values for %q:\n", missingVar) for _, v := range knownVals { diff --git a/internal/bindown/util.go b/internal/bindown/util.go index cd844d39..8db3c023 100644 --- a/internal/bindown/util.go +++ b/internal/bindown/util.go @@ -14,7 +14,9 @@ import ( "strings" "text/template" + "github.com/Masterminds/semver/v3" "golang.org/x/exp/maps" + "golang.org/x/exp/slices" "gopkg.in/yaml.v3" ) @@ -188,3 +190,29 @@ func EncodeYaml(w io.Writer, v any) (errOut error) { encoder.SetIndent(2) return encoder.Encode(v) } + +func SortBySemverOrString(vals []string) { + semvers := make(map[string]*semver.Version) + for _, val := range vals { + ver, err := semver.NewVersion(val) + if err == nil { + semvers[val] = ver + } + } + + // descending order only if all values are semvers + if len(vals) == len(semvers) { + slices.SortFunc(vals, func(a, b string) bool { + return semvers[a].GreaterThan(semvers[b]) + }) + return + } + + slices.SortFunc(vals, func(a, b string) bool { + aVer, bVer := semvers[a], semvers[b] + if aVer == nil || bVer == nil { + return a < b + } + return aVer.LessThan(bVer) + }) +} From 12a7e3599d6181d4a3c750becbb0ceb6c1dbea42 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 2 Jun 2023 13:05:03 -0500 Subject: [PATCH 06/22] test with expect --- bindown.yml | 25 +++++ cmd/bindown/cli.go | 38 ++++++- cmd/bindown/dependency.go | 105 ++++++++++++------ cmd/bindown/dependency_test.go | 37 ++++-- cmd/bindown/testutil_test.go | 40 ++++++- go.mod | 3 + go.sum | 3 +- .../bindown/testdata/expecttest/expecttest.go | 81 ++++++++++++++ internal/bindown/util.go | 12 ++ 9 files changed, 291 insertions(+), 53 deletions(-) create mode 100644 internal/bindown/testdata/expecttest/expecttest.go diff --git a/bindown.yml b/bindown.yml index 4612abff..a25669b9 100644 --- a/bindown.yml +++ b/bindown.yml @@ -9,7 +9,23 @@ dependencies: gh: template: origin#gh vars: + foo: asdf + version: 2.27.0 + gh1: + template: origin#gh + vars: + foo: asdf version: 2.29.0 + gh2: + template: origin#gh + vars: + foo: asdf + version: 2.27.0 + gh3: + template: origin#gh + vars: + foo: asdf + version: 1.2.3 go: template: origin#go vars: @@ -101,6 +117,7 @@ templates: - windows/arm64 required_vars: - version + - foo origin#go: url: https://dl.google.com/go/go{{.version}}.{{.os}}-{{.arch}}{{.urlSuffix}} archive_path: go/bin/go{{.archivePathSuffix}} @@ -433,6 +450,14 @@ url_checksums: https://github.com/WillAbides/semver-prev/releases/download/v0.0.1/semver-prev_0.0.1_darwin_arm64.tar.gz: 367eaccc368bec6119d47cc78d0ad743cc8709dc1900e8f170c5314418c3a14e https://github.com/WillAbides/semver-prev/releases/download/v0.0.1/semver-prev_0.0.1_linux_amd64.tar.gz: 1c1ab5926e9548659bdc1786cf1da9f62f80ae5314c5ccdf71123767e4f4da1d https://github.com/WillAbides/semver-prev/releases/download/v0.0.1/semver-prev_0.0.1_windows_amd64.tar.gz: 31bc3527ad74cdfda9d5868287141f44e72e8fbd1709c4f6af05205f9eb8bb8b + https://github.com/cli/cli/releases/download/v2.27.0/gh_2.27.0_linux_amd64.tar.gz: a3e2987e49ede4e90e0192f64c5e1480d6a1ee3196d51a4fcfbe0ccd0a627747 + https://github.com/cli/cli/releases/download/v2.27.0/gh_2.27.0_macOS_amd64.tar.gz: de452c922f166f89f4c23908782c6fc5d3219bb118fdc4cccea7eed907733196 + https://github.com/cli/cli/releases/download/v2.27.0/gh_2.27.0_macOS_arm64.tar.gz: 5a3754c34da645b61d58d38315206607182395d1ce3cca3114068d61441303bd + https://github.com/cli/cli/releases/download/v2.27.0/gh_2.27.0_windows_amd64.zip: 271db54f3f9ff8f1e34839cf0c517b2957c1d76ec1e0d818ebae2cf530292ebb + https://github.com/cli/cli/releases/download/v2.28.0/gh_2.28.0_linux_amd64.tar.gz: 532633d851557d1da80d59addcb3f7ba20ba0341c8990d32d13f4af73ebfb3f0 + https://github.com/cli/cli/releases/download/v2.28.0/gh_2.28.0_macOS_amd64.zip: 1e50a63ceee4ecd5749184daaeab9f769ad39aa1f42af069a33760d694e4420f + https://github.com/cli/cli/releases/download/v2.28.0/gh_2.28.0_macOS_arm64.zip: bc6ae4efbf2eebcbfa7db17207e72ae33519ec240ffcc19f81b858a94612b04c + https://github.com/cli/cli/releases/download/v2.28.0/gh_2.28.0_windows_amd64.zip: 12c33a13c72300c54f1ac2c926d879cec8ed65dda778cf53f6cb20a4de1d1ad2 https://github.com/cli/cli/releases/download/v2.29.0/gh_2.29.0_linux_amd64.tar.gz: 9fe05f43a11a7bf8eacf731422452d1997e6708d4160ef0efcb13c103320390e https://github.com/cli/cli/releases/download/v2.29.0/gh_2.29.0_macOS_amd64.zip: e116d0f9c310450482cdcd7f4d2d1c7c4cab8d4f025a340260ce3f15329c5145 https://github.com/cli/cli/releases/download/v2.29.0/gh_2.29.0_macOS_arm64.zip: 38ca9a355376abd1475362cf8b3cacf2a757198fe5fe70349cb1767666abacc6 diff --git a/cmd/bindown/cli.go b/cmd/bindown/cli.go index 463df7f7..cf4ca720 100644 --- a/cmd/bindown/cli.go +++ b/cmd/bindown/cli.go @@ -93,10 +93,38 @@ func loadConfigFile(ctx *runContext, noDefaultDirs bool) (*bindown.Config, error return configFile, nil } +// fileWriter covers terminal.FileWriter. Needed for survey +type fileWriter interface { + io.Writer + Fd() uintptr +} + +type SimpleFileWriter struct { + io.Writer +} + +func (s SimpleFileWriter) Fd() uintptr { + return 0 +} + +// fileReader covers terminal.FileReader. Needed for survey +type fileReader interface { + io.Reader + Fd() uintptr +} + +type SimpleFileReader struct { + io.Reader +} + +func (s SimpleFileReader) Fd() uintptr { + return 0 +} + type runContext struct { parent context.Context - stdin io.Reader - stdout io.Writer + stdin fileReader + stdout fileWriter rootCmd *rootCmd } @@ -123,8 +151,8 @@ func (r *runContext) Value(key any) any { } type runOpts struct { - stdin io.Reader - stdout io.Writer + stdin fileReader + stdout fileWriter stderr io.Writer cmdName string exitHandler func(int) @@ -171,7 +199,7 @@ func Run(ctx context.Context, args []string, opts *runOpts) { kongCtx, err := parser.Parse(args) parser.FatalIfErrorf(err) if root.Quiet { - runCtx.stdout = io.Discard + runCtx.stdout = SimpleFileWriter{io.Discard} kongCtx.Stdout = io.Discard } err = kongCtx.Run() diff --git a/cmd/bindown/dependency.go b/cmd/bindown/dependency.go index 836e454b..637e7d9e 100644 --- a/cmd/bindown/dependency.go +++ b/cmd/bindown/dependency.go @@ -1,12 +1,12 @@ package main import ( - "bufio" "encoding/json" "fmt" "regexp" "strings" + "github.com/AlecAivazis/survey/v2" "github.com/willabides/bindown/v4/internal/bindown" "github.com/willabides/bindown/v4/internal/builddep" ) @@ -199,10 +199,6 @@ func (c *dependencyAddCmd) Run(ctx *runContext) error { if varVals == nil { varVals = map[string][]string{} } - missingVars, err := config.MissingDependencyVars(c.Name) - if err != nil { - return err - } tmplCfg := config.Templates[*dep.Template] // Don't need to output the list of systems systems := tmplCfg.Systems @@ -216,36 +212,11 @@ func (c *dependencyAddCmd) Run(ctx *runContext) error { } tmplCfg.Systems = systems - if len(missingVars) > 0 && !c.SkipRequiredVars { - for _, d := range config.Dependencies { - if d.Template == nil || dep.Template == nil || *d.Template != *dep.Template { - continue - } - for k, v := range d.Vars { - varVals[k] = append([]string{v}, varVals[k]...) - } - } - - scanner := bufio.NewScanner(ctx.stdin) - for _, missingVar := range missingVars { - knownVals := varVals[missingVar] - bindown.SortBySemverOrString(knownVals) - if len(knownVals) > 0 { - fmt.Fprintf(ctx.stdout, "Known values for %q:\n", missingVar) - for _, v := range knownVals { - fmt.Fprintf(ctx.stdout, " %s\n", v) - } - } - fmt.Fprintf(ctx.stdout, "Please enter a value for required variable %q:\t", missingVar) - scanner.Scan() - err = scanner.Err() - if err != nil { - return err - } - val := scanner.Text() - config.Dependencies[c.Name].Vars[missingVar] = val - } + err = c.promptForVars(ctx, config, dep, varVals) + if err != nil { + return err } + skipChecksums := c.SkipChecksums || c.SkipRequiredVars if !skipChecksums { err = config.AddChecksums([]string{c.Name}, nil) @@ -256,6 +227,70 @@ func (c *dependencyAddCmd) Run(ctx *runContext) error { return config.WriteFile(ctx.rootCmd.JSONConfig) } +func (c *dependencyAddCmd) promptForVars(ctx *runContext, config *bindown.Config, dep *bindown.Dependency, varVals map[string][]string) error { + if c.SkipRequiredVars { + return nil + } + missingVars, err := config.MissingDependencyVars(c.Name) + if err != nil { + return err + } + if len(missingVars) == 0 { + return nil + } + for _, d := range config.Dependencies { + if d.Template == nil || dep.Template == nil || *d.Template != *dep.Template { + continue + } + for k, v := range d.Vars { + varVals[k] = append([]string{v}, varVals[k]...) + } + } + + questions := make([]*survey.Question, 0, len(missingVars)) + for _, missingVar := range missingVars { + prompt := survey.Input{ + Message: missingVar, + // Help: `The thing you need to do is...`, + } + knownVals := varVals[missingVar] + bindown.SortBySemverOrString(knownVals) + knownVals = bindown.Unique(knownVals, knownVals[:0]) + if len(knownVals) > 0 { + prompt.Default = knownVals[0] + prompt.Suggest = func(toComplete string) []string { + suggestions := make([]string, 0, len(knownVals)) + for _, v := range knownVals { + if strings.HasPrefix(v, toComplete) { + suggestions = append(suggestions, v) + } + } + return suggestions + } + } + questions = append(questions, &survey.Question{ + Name: missingVar, + Prompt: &prompt, + }) + } + answers := map[string]any{} + err = survey.Ask(questions, &answers, survey.WithStdio(ctx.stdin, ctx.stdout, nil), survey.WithShowCursor(true)) + if err != nil { + return err + } + for k, v := range answers { + s, ok := v.(string) + if !ok { + return fmt.Errorf("expected string for %q, got %T", k, v) + } + config.Dependencies[c.Name].Vars[k] = s + } + + fmt.Fprintf(ctx.stdout, "Adding dependency %q from template\n", c.Name) + + return nil +} + type dependencyAddByUrlsCmd struct { Name string `kong:"arg,help='dependency name'"` Version string `kong:"arg,help='dependency version'"` @@ -294,7 +329,7 @@ type dependencyAddByGithubReleaseCmd struct { var ( releaseShortExp = regexp.MustCompile(`^([^/]+)/([^/^@]+)@?(.+)?$`) - releaseURLExp = regexp.MustCompile(`^https://github\.com/([^/]+)/([^/]+)/releases/tag/([^/]+)`) + releaseURLExp = regexp.MustCompile(`^https: //github\.com/([^/]+)/([^/]+)/releases/tag/([^/]+)`) ) func (c *dependencyAddByGithubReleaseCmd) Run(ctx *runContext) error { diff --git a/cmd/bindown/dependency_test.go b/cmd/bindown/dependency_test.go index 59805b49..20368cf0 100644 --- a/cmd/bindown/dependency_test.go +++ b/cmd/bindown/dependency_test.go @@ -5,9 +5,9 @@ import ( "os" "path/filepath" "runtime" - "strings" "testing" + "github.com/Netflix/go-expect" "github.com/stretchr/testify/require" "github.com/willabides/bindown/v4/internal/testutil" ) @@ -484,15 +484,24 @@ url_checksums: foo-darwin-amd64-1.2.3: deadbeef foo-windows-amd64-1.2.3: deadbeef `) - runner.stdin = strings.NewReader("1.2.3\nbar") - result := runner.run("dependency", "add", "dep1", "tmpl") + + // runner.stdin = strings.NewReader("1.2.3\nbar") + // result := runner.run("dependency", "add", q"dep1", "tmpl") + ex := func(console *expect.Console) { + _, err := console.ExpectString("(bar) ") + require.NoError(t, err) + _, err = console.SendLine("") + require.NoError(t, err) + _, err = console.ExpectString("template") + require.NoError(t, err) + _, err = console.ExpectEOF() + require.NoError(t, err) + } + result := runner.runExpect(ex, "dependency", "add", "dep1", "tmpl", "--var=version=1.2.3") result.assertState(resultState{ - stdout: `Known values for "version": - 1.2.3 -Please enter a value for required variable "version": Known values for "foo": - bar -Please enter a value for required variable "foo":`, + stdout: `.*`, }) + fmt.Println(result.stdOut.String()) cfg := runner.getConfigFile() wantDep := mustConfigFromYAML(t, ` dependencies: @@ -522,8 +531,16 @@ systems: ["darwin/amd64", "darwin/arm64", "linux/amd64", "windows/amd64"] template_sources: origin: %q `, srcPath)) - runner.stdin = strings.NewReader(fmt.Sprintf("%s\n%s", "1.2.3", server.URL)) - result := runner.run("dependency", "add", "foo", "tmpl1", "--source", "origin") + cmdLine := []string{ + "dependency", "add", "foo", "tmpl1", + "--source", "origin", + "--var", "version=1.2.3", + "--var", "addr=" + server.URL, + } + fmt.Println(cmdLine) + result := runner.run( + cmdLine..., + ) result.assertState(resultState{ stdout: `Adding dependency "foo" from template origin#tmpl`, }) diff --git a/cmd/bindown/testutil_test.go b/cmd/bindown/testutil_test.go index 1dbe0c0c..d5f656b9 100644 --- a/cmd/bindown/testutil_test.go +++ b/cmd/bindown/testutil_test.go @@ -12,9 +12,11 @@ import ( "strings" "testing" + "github.com/Netflix/go-expect" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/willabides/bindown/v4/internal/bindown" + "github.com/willabides/bindown/v4/internal/bindown/testdata/expecttest" "gopkg.in/yaml.v3" ) @@ -58,8 +60,8 @@ func (c *cmdRunner) run(commandLine ...string) *runCmdResult { ctx, commandLine, &runOpts{ - stdin: c.stdin, - stdout: &result.stdOut, + stdin: SimpleFileReader{c.stdin}, + stdout: SimpleFileWriter{&result.stdOut}, stderr: &result.stdErr, cmdName: "cmd", exitHandler: func(i int) { @@ -71,6 +73,40 @@ func (c *cmdRunner) run(commandLine ...string) *runCmdResult { return &result } +func (c *cmdRunner) runExpect(expectFunc func(*expect.Console), commandLine ...string) *runCmdResult { + t := c.t + t.Helper() + ctx := context.Background() + + if c.configFile != "" { + commandLine = append(commandLine, "--configfile", c.configFile) + } + if c.cache != "" { + commandLine = append(commandLine, "--cache", c.cache) + } + + result := runCmdResult{t: t} + + expecttest.MustNew(expectFunc).Run(t, func(console *expect.Console) { + Run( + ctx, + commandLine, + &runOpts{ + stdin: console.Tty(), + stdout: console.Tty(), + stderr: &result.stdErr, + cmdName: "cmd", + exitHandler: func(i int) { + result.exited = true + result.exitVal = i + }, + }, + ) + }) + + return &result +} + func mustConfigFromYAML(t *testing.T, yml string) *bindown.Config { t.Helper() got, err := bindown.ConfigFromYAML(context.Background(), []byte(yml)) diff --git a/go.mod b/go.mod index 5aebffd8..f111a403 100644 --- a/go.mod +++ b/go.mod @@ -5,9 +5,12 @@ go 1.20 require ( github.com/AlecAivazis/survey/v2 v2.3.6 github.com/Masterminds/semver/v3 v3.1.1 + github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 github.com/alecthomas/kong v0.7.1 + github.com/creack/pty v1.1.18 github.com/google/go-cmp v0.5.9 github.com/google/go-github/v52 v52.0.0 + github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec github.com/invopop/jsonschema v0.7.0 github.com/mholt/archiver/v3 v3.5.1 github.com/mholt/archiver/v4 v4.0.0-alpha.8 diff --git a/go.sum b/go.sum index 294da681..1eb73541 100644 --- a/go.sum +++ b/go.sum @@ -49,8 +49,9 @@ github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEM github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= github.com/connesc/cipherio v0.2.1 h1:FGtpTPMbKNNWByNrr9aEBtaJtXjqOzkIXNYJp6OEycw= github.com/connesc/cipherio v0.2.1/go.mod h1:ukY0MWJDFnJEbXMQtOcn2VmTpRfzcTz4OoVrWGGJZcA= -github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI= github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= +github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= +github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/internal/bindown/testdata/expecttest/expecttest.go b/internal/bindown/testdata/expecttest/expecttest.go new file mode 100644 index 00000000..3739a1d2 --- /dev/null +++ b/internal/bindown/testdata/expecttest/expecttest.go @@ -0,0 +1,81 @@ +package expecttest + +import ( + "fmt" + "github.com/Netflix/go-expect" + pseudotty "github.com/creack/pty" + "github.com/hinshun/vt10x" + "github.com/stretchr/testify/assert" + "sync" + "testing" +) + +type Test struct { + console *expect.Console + expectFunc func(*expect.Console) + wg sync.WaitGroup + started bool +} + +func (x *Test) Start() error { + if x.started { + return fmt.Errorf("already started") + } + x.started = true + x.wg.Add(1) + go func() { + defer x.wg.Done() + x.expectFunc(x.console) + }() + return nil +} + +func (x *Test) Wait() { + x.wg.Wait() +} + +func (x *Test) Close() error { + return x.console.Close() +} + +func New(expectFunc func(*expect.Console), opt ...expect.ConsoleOpt) (*Test, error) { + pty, tty, err := pseudotty.Open() + if err != nil { + return nil, err + } + opt = append([]expect.ConsoleOpt{ + expect.WithStdout(vt10x.New(vt10x.WithWriter(tty))), + expect.WithStdin(pty), + expect.WithCloser(pty, tty), + }, opt...) + console, err := expect.NewConsole(opt...) + if err != nil { + return nil, err + } + return &Test{ + console: console, + expectFunc: expectFunc, + }, nil +} + +func MustNew(expectFunc func(*expect.Console), opt ...expect.ConsoleOpt) *Test { + x, err := New(expectFunc, opt...) + if err != nil { + panic(err) + } + return x +} + +func (x *Test) Run(t testing.TB, fn func(*expect.Console)) bool { + err := x.Start() + if !assert.NoError(t, err) { + return false + } + fn(x.console) + err = x.Close() + if !assert.NoError(t, err) { + return false + } + x.Wait() + return true +} diff --git a/internal/bindown/util.go b/internal/bindown/util.go index 8db3c023..d8f15ca0 100644 --- a/internal/bindown/util.go +++ b/internal/bindown/util.go @@ -216,3 +216,15 @@ func SortBySemverOrString(vals []string) { return aVer.LessThan(bVer) }) } + +// Unique appends unique values from vals to buf and returns buf +func Unique[V comparable](vals, buf []V) []V { + seen := make(map[V]bool) + for _, val := range vals { + if !seen[val] { + seen[val] = true + buf = append(buf, val) + } + } + return buf +} From e892c79f3a4cc85066aec30fde041b51f12aaf3f Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 2 Jun 2023 13:10:33 -0500 Subject: [PATCH 07/22] cleanup --- cmd/bindown/dependency_test.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/cmd/bindown/dependency_test.go b/cmd/bindown/dependency_test.go index 20368cf0..864cbc82 100644 --- a/cmd/bindown/dependency_test.go +++ b/cmd/bindown/dependency_test.go @@ -485,8 +485,6 @@ url_checksums: foo-windows-amd64-1.2.3: deadbeef `) - // runner.stdin = strings.NewReader("1.2.3\nbar") - // result := runner.run("dependency", "add", q"dep1", "tmpl") ex := func(console *expect.Console) { _, err := console.ExpectString("(bar) ") require.NoError(t, err) @@ -501,7 +499,6 @@ url_checksums: result.assertState(resultState{ stdout: `.*`, }) - fmt.Println(result.stdOut.String()) cfg := runner.getConfigFile() wantDep := mustConfigFromYAML(t, ` dependencies: @@ -531,15 +528,10 @@ systems: ["darwin/amd64", "darwin/arm64", "linux/amd64", "windows/amd64"] template_sources: origin: %q `, srcPath)) - cmdLine := []string{ - "dependency", "add", "foo", "tmpl1", + result := runner.run("dependency", "add", "foo", "tmpl1", "--source", "origin", "--var", "version=1.2.3", - "--var", "addr=" + server.URL, - } - fmt.Println(cmdLine) - result := runner.run( - cmdLine..., + "--var", "addr="+server.URL, ) result.assertState(resultState{ stdout: `Adding dependency "foo" from template origin#tmpl`, From abcc2e97c40748d3304c86495e89c240486fd1de Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 2 Jun 2023 13:22:45 -0500 Subject: [PATCH 08/22] go-test2action --- bindown.yml | 36 ++++++++++++++++++++++++++++++ internal/builddep/builddep_test.go | 1 - script/test | 9 +++++++- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/bindown.yml b/bindown.yml index a25669b9..e2a8f8aa 100644 --- a/bindown.yml +++ b/bindown.yml @@ -30,6 +30,10 @@ dependencies: template: origin#go vars: version: 1.20.2 + go-test2action: + template: go-test2action + vars: + version: 0.0.0 gofumpt: template: origin#gofumpt vars: @@ -72,6 +76,35 @@ templates: bin: checksums.txt required_vars: - tag + go-test2action: + homepage: https://github.com/WillAbides/go-test2action + description: formats go test failures as errors in github action workflows + url: https://github.com/WillAbides/go-test2action/releases/download/v{{.version}}/go-test2action_{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} + archive_path: go-test2action{{.archivePathSuffix}} + bin: go-test2action + vars: + archivePathSuffix: "" + urlSuffix: .tar.gz + overrides: + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe + substitutions: + arch: + arm64: amd64 + substitutions: + arch: + arm64: amd64 + systems: + - darwin/amd64 + - darwin/arm64 + - linux/amd64 + - windows/amd64 + required_vars: + - version origin#gh: homepage: https://github.com/cli/cli description: GitHub’s official command line tool @@ -442,6 +475,9 @@ url_checksums: https://dl.google.com/go/go1.20.2.darwin-arm64.tar.gz: 7343c87f19e79c0063532e82e1c4d6f42175a32d99f7a4d15e658e88bf97f885 https://dl.google.com/go/go1.20.2.linux-amd64.tar.gz: 4eaea32f59cde4dc635fbc42161031d13e1c780b87097f4b4234cfce671f1768 https://dl.google.com/go/go1.20.2.windows-amd64.zip: fe439f0e438f7555a7f5f7194ddb6f4a07b0de1fa414385d19f2aeb26d9f43db + https://github.com/WillAbides/go-test2action/releases/download/v0.0.0/go-test2action_0.0.0_darwin_amd64.tar.gz: 8cbb8eecdc257c0c92bc784fdad349e4d4bcd9c541485f6ea5f495c9ebe66718 + https://github.com/WillAbides/go-test2action/releases/download/v0.0.0/go-test2action_0.0.0_linux_amd64.tar.gz: 4b45f44f339f5a0139b7a82267fabb47a4685ac183f5f41b5121c080ca94ca1e + https://github.com/WillAbides/go-test2action/releases/download/v0.0.0/go-test2action_0.0.0_windows_amd64.tar.gz: 8ad522ae71d08ec11612b96ba00f3f71600d8762818dab9c876daf14fea4ef5a https://github.com/WillAbides/semver-next/releases/download/v2.0.0/semver-next_2.0.0_darwin_amd64.tar.gz: 2bb0e3a6fda58689c7c983c33f131b44298484ea42c95455f711b16e3a93d033 https://github.com/WillAbides/semver-next/releases/download/v2.0.0/semver-next_2.0.0_darwin_arm64.tar.gz: d86b2a7e0cb21cd56b9168913994b4470be2c1a0d724d91c85d91aa3e8c63755 https://github.com/WillAbides/semver-next/releases/download/v2.0.0/semver-next_2.0.0_linux_amd64.tar.gz: 336beb1eb6ce340a6dfbb61b7f3ffd8af821414112479a38f9b10db03dc7a6ea diff --git a/internal/builddep/builddep_test.go b/internal/builddep/builddep_test.go index b5af8ba5..1a2adc8a 100644 --- a/internal/builddep/builddep_test.go +++ b/internal/builddep/builddep_test.go @@ -45,7 +45,6 @@ systems: require.NoError(t, err) got, err := yaml.Marshal(&cfg) require.NoError(t, err) - fmt.Println(string(got)) want := ` systems: diff --git a/script/test b/script/test index f2c8ea0a..8087d1d8 100755 --- a/script/test +++ b/script/test @@ -4,4 +4,11 @@ set -e CDPATH="" cd -- "$(dirname -- "$(dirname -- "$0")")" -go test -race -covermode=atomic ./... +if [ -z "$CI" ]; then + exec go test -race -covermode=atomic ./... +fi + +script/bindown -q install go-test2action + +go test -race -covermode=atomic -json ./... | + bin/go-test2action --passthrough --root-pkg github.com/willabides/bindown/v4 From e2636229181d889526ed4d9f4bfd0d9bd3b63133 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 2 Jun 2023 13:28:43 -0500 Subject: [PATCH 09/22] fail test --- cmd/bindown/dependency_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/bindown/dependency_test.go b/cmd/bindown/dependency_test.go index 864cbc82..ce8a3451 100644 --- a/cmd/bindown/dependency_test.go +++ b/cmd/bindown/dependency_test.go @@ -514,6 +514,8 @@ dependencies: tar := filepath.Join(downloadablesDir, "runnable.tar.gz") zip := filepath.Join(downloadablesDir, "runnable_windows.zip") + require.True(t, false) + server := testutil.ServeFiles(t, map[string]string{ "/foo/v1.2.3/foo-darwin-amd64.tar.gz": tar, "/foo/v1.2.3/foo-darwin-arm64.tar.gz": tar, From 89f6c5923d27e7b5c357795ac14ebcefa7da2501 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 2 Jun 2023 13:36:40 -0500 Subject: [PATCH 10/22] don't use go-test2action on windows --- script/test | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/script/test b/script/test index 8087d1d8..f6e3e698 100755 --- a/script/test +++ b/script/test @@ -4,7 +4,17 @@ set -e CDPATH="" cd -- "$(dirname -- "$(dirname -- "$0")")" -if [ -z "$CI" ]; then +uname_os() { + os=$(uname -s | tr '[:upper:]' '[:lower:]') + case "$os" in + cygwin_nt*) os="windows" ;; + mingw*) os="windows" ;; + msys_nt*) os="windows" ;; + esac + echo "$os" +} + +if [ -z "$CI" ] || [ "$(uname_os)" = "windows" ]; then exec go test -race -covermode=atomic ./... fi From afc926f12d8bbc6e1bc72bb8a87d861ede47bfca Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 2 Jun 2023 13:42:51 -0500 Subject: [PATCH 11/22] unbreak --- cmd/bindown/dependency_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmd/bindown/dependency_test.go b/cmd/bindown/dependency_test.go index ce8a3451..864cbc82 100644 --- a/cmd/bindown/dependency_test.go +++ b/cmd/bindown/dependency_test.go @@ -514,8 +514,6 @@ dependencies: tar := filepath.Join(downloadablesDir, "runnable.tar.gz") zip := filepath.Join(downloadablesDir, "runnable_windows.zip") - require.True(t, false) - server := testutil.ServeFiles(t, map[string]string{ "/foo/v1.2.3/foo-darwin-amd64.tar.gz": tar, "/foo/v1.2.3/foo-darwin-arm64.tar.gz": tar, From ba23a340b8a6cd463f8dd315b62f13d9644db2e0 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 2 Jun 2023 13:45:13 -0500 Subject: [PATCH 12/22] move expecttest --- cmd/bindown/testutil_test.go | 2 +- internal/{bindown/testdata => }/expecttest/expecttest.go | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename internal/{bindown/testdata => }/expecttest/expecttest.go (100%) diff --git a/cmd/bindown/testutil_test.go b/cmd/bindown/testutil_test.go index d5f656b9..2039a954 100644 --- a/cmd/bindown/testutil_test.go +++ b/cmd/bindown/testutil_test.go @@ -16,7 +16,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/willabides/bindown/v4/internal/bindown" - "github.com/willabides/bindown/v4/internal/bindown/testdata/expecttest" + "github.com/willabides/bindown/v4/internal/expecttest" "gopkg.in/yaml.v3" ) diff --git a/internal/bindown/testdata/expecttest/expecttest.go b/internal/expecttest/expecttest.go similarity index 100% rename from internal/bindown/testdata/expecttest/expecttest.go rename to internal/expecttest/expecttest.go From 3ec8007831c1a861ff499d80b867c94ee2566f82 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 2 Jun 2023 14:05:58 -0500 Subject: [PATCH 13/22] no windows for expecttest --- cmd/bindown/testutil_test.go | 6 +- internal/expecttest/expecttest.go | 83 ++++------------------- internal/expecttest/expecttest_posix.go | 51 ++++++++++++++ internal/expecttest/expecttest_windows.go | 13 ++++ 4 files changed, 83 insertions(+), 70 deletions(-) create mode 100644 internal/expecttest/expecttest_posix.go create mode 100644 internal/expecttest/expecttest_windows.go diff --git a/cmd/bindown/testutil_test.go b/cmd/bindown/testutil_test.go index 2039a954..e0119e8d 100644 --- a/cmd/bindown/testutil_test.go +++ b/cmd/bindown/testutil_test.go @@ -87,7 +87,7 @@ func (c *cmdRunner) runExpect(expectFunc func(*expect.Console), commandLine ...s result := runCmdResult{t: t} - expecttest.MustNew(expectFunc).Run(t, func(console *expect.Console) { + testFunc := func(console *expect.Console) { Run( ctx, commandLine, @@ -102,7 +102,9 @@ func (c *cmdRunner) runExpect(expectFunc func(*expect.Console), commandLine ...s }, }, ) - }) + } + + expecttest.Run(t, expectFunc, testFunc, expecttest.WithConsoleOpt(expect.WithStdout(&result.stdOut))) return &result } diff --git a/internal/expecttest/expecttest.go b/internal/expecttest/expecttest.go index 3739a1d2..1ac19830 100644 --- a/internal/expecttest/expecttest.go +++ b/internal/expecttest/expecttest.go @@ -1,81 +1,28 @@ package expecttest import ( - "fmt" - "github.com/Netflix/go-expect" - pseudotty "github.com/creack/pty" - "github.com/hinshun/vt10x" - "github.com/stretchr/testify/assert" - "sync" "testing" -) - -type Test struct { - console *expect.Console - expectFunc func(*expect.Console) - wg sync.WaitGroup - started bool -} -func (x *Test) Start() error { - if x.started { - return fmt.Errorf("already started") - } - x.started = true - x.wg.Add(1) - go func() { - defer x.wg.Done() - x.expectFunc(x.console) - }() - return nil -} - -func (x *Test) Wait() { - x.wg.Wait() -} + "github.com/Netflix/go-expect" +) -func (x *Test) Close() error { - return x.console.Close() +type option struct { + consoleOpts []expect.ConsoleOpt } -func New(expectFunc func(*expect.Console), opt ...expect.ConsoleOpt) (*Test, error) { - pty, tty, err := pseudotty.Open() - if err != nil { - return nil, err - } - opt = append([]expect.ConsoleOpt{ - expect.WithStdout(vt10x.New(vt10x.WithWriter(tty))), - expect.WithStdin(pty), - expect.WithCloser(pty, tty), - }, opt...) - console, err := expect.NewConsole(opt...) - if err != nil { - return nil, err - } - return &Test{ - console: console, - expectFunc: expectFunc, - }, nil -} +type Option func(*option) -func MustNew(expectFunc func(*expect.Console), opt ...expect.ConsoleOpt) *Test { - x, err := New(expectFunc, opt...) - if err != nil { - panic(err) +func WithConsoleOpt(opt ...expect.ConsoleOpt) Option { + return func(o *option) { + o.consoleOpts = append(o.consoleOpts, opt...) } - return x } -func (x *Test) Run(t testing.TB, fn func(*expect.Console)) bool { - err := x.Start() - if !assert.NoError(t, err) { - return false - } - fn(x.console) - err = x.Close() - if !assert.NoError(t, err) { - return false - } - x.Wait() - return true +func Run( + t testing.TB, + expectFunc func(*expect.Console), + testFunc func(*expect.Console), + opts ...Option, +) bool { + return run(t, expectFunc, testFunc, opts...) } diff --git a/internal/expecttest/expecttest_posix.go b/internal/expecttest/expecttest_posix.go new file mode 100644 index 00000000..379d47bc --- /dev/null +++ b/internal/expecttest/expecttest_posix.go @@ -0,0 +1,51 @@ +//go:build !windows + +package expecttest + +import ( + "sync" + "testing" + + "github.com/Netflix/go-expect" + pseudotty "github.com/creack/pty" + "github.com/hinshun/vt10x" + "github.com/stretchr/testify/assert" +) + +func run( + t testing.TB, + expectFunc func(*expect.Console), + testFunc func(*expect.Console), + opts ...Option, +) bool { + o := option{} + for _, opt := range opts { + opt(&o) + } + pty, tty, err := pseudotty.Open() + if !assert.NoError(t, err) { + return false + } + consoleOpts := append([]expect.ConsoleOpt{ + expect.WithStdout(vt10x.New(vt10x.WithWriter(tty))), + expect.WithStdin(pty), + expect.WithCloser(pty, tty), + }, o.consoleOpts...) + console, err := expect.NewConsole(consoleOpts...) + if !assert.NoError(t, err) { + return false + } + var wg sync.WaitGroup + wg.Add(1) + go func() { + defer wg.Done() + expectFunc(console) + }() + testFunc(console) + err = console.Close() + if !assert.NoError(t, err) { + return false + } + wg.Wait() + return true +} diff --git a/internal/expecttest/expecttest_windows.go b/internal/expecttest/expecttest_windows.go new file mode 100644 index 00000000..bc0de9a4 --- /dev/null +++ b/internal/expecttest/expecttest_windows.go @@ -0,0 +1,13 @@ +//go:build windows + +package expecttest + +func run( + t testing.TB, + expectFunc func(*expect.Console), + testFunc func(*expect.Console), + opts ...Option, +) bool { + t.Skip("expecttest is not supported on Windows") + return false +} From d0d8ea58822db40df7574d6b129684b782e539e5 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 2 Jun 2023 14:11:12 -0500 Subject: [PATCH 14/22] fix imports --- internal/expecttest/expecttest_windows.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/expecttest/expecttest_windows.go b/internal/expecttest/expecttest_windows.go index bc0de9a4..350a989e 100644 --- a/internal/expecttest/expecttest_windows.go +++ b/internal/expecttest/expecttest_windows.go @@ -2,6 +2,12 @@ package expecttest +import ( + "testing" + + "github.com/Netflix/go-expect" +) + func run( t testing.TB, expectFunc func(*expect.Console), From 8562eaa2f78d0352521f7548fad56b3aa5b24da9 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 2 Jun 2023 14:22:16 -0500 Subject: [PATCH 15/22] move console.Close --- cmd/bindown/dependency_test.go | 2 ++ internal/expecttest/expecttest_posix.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/bindown/dependency_test.go b/cmd/bindown/dependency_test.go index 864cbc82..9cea1dd5 100644 --- a/cmd/bindown/dependency_test.go +++ b/cmd/bindown/dependency_test.go @@ -492,6 +492,8 @@ url_checksums: require.NoError(t, err) _, err = console.ExpectString("template") require.NoError(t, err) + err = console.Close() + require.NoError(t, err) _, err = console.ExpectEOF() require.NoError(t, err) } diff --git a/internal/expecttest/expecttest_posix.go b/internal/expecttest/expecttest_posix.go index 379d47bc..1c722cc1 100644 --- a/internal/expecttest/expecttest_posix.go +++ b/internal/expecttest/expecttest_posix.go @@ -42,10 +42,10 @@ func run( expectFunc(console) }() testFunc(console) + wg.Wait() err = console.Close() if !assert.NoError(t, err) { return false } - wg.Wait() return true } From 36e5d35af176de3e21f6c28c363463cc8c1e4107 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 2 Jun 2023 14:22:58 -0500 Subject: [PATCH 16/22] lint --- internal/expecttest/expecttest_posix.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/internal/expecttest/expecttest_posix.go b/internal/expecttest/expecttest_posix.go index 1c722cc1..3ea88a26 100644 --- a/internal/expecttest/expecttest_posix.go +++ b/internal/expecttest/expecttest_posix.go @@ -44,8 +44,5 @@ func run( testFunc(console) wg.Wait() err = console.Close() - if !assert.NoError(t, err) { - return false - } - return true + return assert.NoError(t, err) } From 242a602ca989348683657e5c282a366330ded05c Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 2 Jun 2023 14:25:40 -0500 Subject: [PATCH 17/22] helper --- internal/expecttest/expecttest_posix.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/expecttest/expecttest_posix.go b/internal/expecttest/expecttest_posix.go index 3ea88a26..f267693f 100644 --- a/internal/expecttest/expecttest_posix.go +++ b/internal/expecttest/expecttest_posix.go @@ -18,6 +18,7 @@ func run( testFunc func(*expect.Console), opts ...Option, ) bool { + t.Helper() o := option{} for _, opt := range opts { opt(&o) From 7e88ff454f7819e2171f076578f6341b5ec6c22a Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 2 Jun 2023 14:33:28 -0500 Subject: [PATCH 18/22] stop expecting eof --- cmd/bindown/dependency_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cmd/bindown/dependency_test.go b/cmd/bindown/dependency_test.go index 9cea1dd5..282f4687 100644 --- a/cmd/bindown/dependency_test.go +++ b/cmd/bindown/dependency_test.go @@ -492,10 +492,7 @@ url_checksums: require.NoError(t, err) _, err = console.ExpectString("template") require.NoError(t, err) - err = console.Close() - require.NoError(t, err) - _, err = console.ExpectEOF() - require.NoError(t, err) + require.NoError(t, console.Close()) } result := runner.runExpect(ex, "dependency", "add", "dep1", "tmpl", "--var=version=1.2.3") result.assertState(resultState{ From 25855332fee7f0a8336a85b1af53bdc5f9886b68 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 2 Jun 2023 14:38:46 -0500 Subject: [PATCH 19/22] restore script/test --- script/test | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/script/test b/script/test index f6e3e698..f2c8ea0a 100755 --- a/script/test +++ b/script/test @@ -4,21 +4,4 @@ set -e CDPATH="" cd -- "$(dirname -- "$(dirname -- "$0")")" -uname_os() { - os=$(uname -s | tr '[:upper:]' '[:lower:]') - case "$os" in - cygwin_nt*) os="windows" ;; - mingw*) os="windows" ;; - msys_nt*) os="windows" ;; - esac - echo "$os" -} - -if [ -z "$CI" ] || [ "$(uname_os)" = "windows" ]; then - exec go test -race -covermode=atomic ./... -fi - -script/bindown -q install go-test2action - -go test -race -covermode=atomic -json ./... | - bin/go-test2action --passthrough --root-pkg github.com/willabides/bindown/v4 +go test -race -covermode=atomic ./... From 2930cfec37c0edb39c678363ef7e7af90d9e7f80 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 2 Jun 2023 14:41:11 -0500 Subject: [PATCH 20/22] revert some of bindown.yml --- bindown.yml | 62 ----------------------------------------------------- 1 file changed, 62 deletions(-) diff --git a/bindown.yml b/bindown.yml index e2a8f8aa..6953ca49 100644 --- a/bindown.yml +++ b/bindown.yml @@ -9,31 +9,11 @@ dependencies: gh: template: origin#gh vars: - foo: asdf - version: 2.27.0 - gh1: - template: origin#gh - vars: - foo: asdf version: 2.29.0 - gh2: - template: origin#gh - vars: - foo: asdf - version: 2.27.0 - gh3: - template: origin#gh - vars: - foo: asdf - version: 1.2.3 go: template: origin#go vars: version: 1.20.2 - go-test2action: - template: go-test2action - vars: - version: 0.0.0 gofumpt: template: origin#gofumpt vars: @@ -76,38 +56,7 @@ templates: bin: checksums.txt required_vars: - tag - go-test2action: - homepage: https://github.com/WillAbides/go-test2action - description: formats go test failures as errors in github action workflows - url: https://github.com/WillAbides/go-test2action/releases/download/v{{.version}}/go-test2action_{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} - archive_path: go-test2action{{.archivePathSuffix}} - bin: go-test2action - vars: - archivePathSuffix: "" - urlSuffix: .tar.gz - overrides: - - matcher: - os: - - windows - dependency: - vars: - archivePathSuffix: .exe - substitutions: - arch: - arm64: amd64 - substitutions: - arch: - arm64: amd64 - systems: - - darwin/amd64 - - darwin/arm64 - - linux/amd64 - - windows/amd64 - required_vars: - - version origin#gh: - homepage: https://github.com/cli/cli - description: GitHub’s official command line tool url: https://github.com/cli/cli/releases/download/v{{.version}}/gh_{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: gh_{{.version}}_{{.os}}_{{.arch}}/bin/gh{{.archivePathSuffix}} bin: gh @@ -475,9 +424,6 @@ url_checksums: https://dl.google.com/go/go1.20.2.darwin-arm64.tar.gz: 7343c87f19e79c0063532e82e1c4d6f42175a32d99f7a4d15e658e88bf97f885 https://dl.google.com/go/go1.20.2.linux-amd64.tar.gz: 4eaea32f59cde4dc635fbc42161031d13e1c780b87097f4b4234cfce671f1768 https://dl.google.com/go/go1.20.2.windows-amd64.zip: fe439f0e438f7555a7f5f7194ddb6f4a07b0de1fa414385d19f2aeb26d9f43db - https://github.com/WillAbides/go-test2action/releases/download/v0.0.0/go-test2action_0.0.0_darwin_amd64.tar.gz: 8cbb8eecdc257c0c92bc784fdad349e4d4bcd9c541485f6ea5f495c9ebe66718 - https://github.com/WillAbides/go-test2action/releases/download/v0.0.0/go-test2action_0.0.0_linux_amd64.tar.gz: 4b45f44f339f5a0139b7a82267fabb47a4685ac183f5f41b5121c080ca94ca1e - https://github.com/WillAbides/go-test2action/releases/download/v0.0.0/go-test2action_0.0.0_windows_amd64.tar.gz: 8ad522ae71d08ec11612b96ba00f3f71600d8762818dab9c876daf14fea4ef5a https://github.com/WillAbides/semver-next/releases/download/v2.0.0/semver-next_2.0.0_darwin_amd64.tar.gz: 2bb0e3a6fda58689c7c983c33f131b44298484ea42c95455f711b16e3a93d033 https://github.com/WillAbides/semver-next/releases/download/v2.0.0/semver-next_2.0.0_darwin_arm64.tar.gz: d86b2a7e0cb21cd56b9168913994b4470be2c1a0d724d91c85d91aa3e8c63755 https://github.com/WillAbides/semver-next/releases/download/v2.0.0/semver-next_2.0.0_linux_amd64.tar.gz: 336beb1eb6ce340a6dfbb61b7f3ffd8af821414112479a38f9b10db03dc7a6ea @@ -486,14 +432,6 @@ url_checksums: https://github.com/WillAbides/semver-prev/releases/download/v0.0.1/semver-prev_0.0.1_darwin_arm64.tar.gz: 367eaccc368bec6119d47cc78d0ad743cc8709dc1900e8f170c5314418c3a14e https://github.com/WillAbides/semver-prev/releases/download/v0.0.1/semver-prev_0.0.1_linux_amd64.tar.gz: 1c1ab5926e9548659bdc1786cf1da9f62f80ae5314c5ccdf71123767e4f4da1d https://github.com/WillAbides/semver-prev/releases/download/v0.0.1/semver-prev_0.0.1_windows_amd64.tar.gz: 31bc3527ad74cdfda9d5868287141f44e72e8fbd1709c4f6af05205f9eb8bb8b - https://github.com/cli/cli/releases/download/v2.27.0/gh_2.27.0_linux_amd64.tar.gz: a3e2987e49ede4e90e0192f64c5e1480d6a1ee3196d51a4fcfbe0ccd0a627747 - https://github.com/cli/cli/releases/download/v2.27.0/gh_2.27.0_macOS_amd64.tar.gz: de452c922f166f89f4c23908782c6fc5d3219bb118fdc4cccea7eed907733196 - https://github.com/cli/cli/releases/download/v2.27.0/gh_2.27.0_macOS_arm64.tar.gz: 5a3754c34da645b61d58d38315206607182395d1ce3cca3114068d61441303bd - https://github.com/cli/cli/releases/download/v2.27.0/gh_2.27.0_windows_amd64.zip: 271db54f3f9ff8f1e34839cf0c517b2957c1d76ec1e0d818ebae2cf530292ebb - https://github.com/cli/cli/releases/download/v2.28.0/gh_2.28.0_linux_amd64.tar.gz: 532633d851557d1da80d59addcb3f7ba20ba0341c8990d32d13f4af73ebfb3f0 - https://github.com/cli/cli/releases/download/v2.28.0/gh_2.28.0_macOS_amd64.zip: 1e50a63ceee4ecd5749184daaeab9f769ad39aa1f42af069a33760d694e4420f - https://github.com/cli/cli/releases/download/v2.28.0/gh_2.28.0_macOS_arm64.zip: bc6ae4efbf2eebcbfa7db17207e72ae33519ec240ffcc19f81b858a94612b04c - https://github.com/cli/cli/releases/download/v2.28.0/gh_2.28.0_windows_amd64.zip: 12c33a13c72300c54f1ac2c926d879cec8ed65dda778cf53f6cb20a4de1d1ad2 https://github.com/cli/cli/releases/download/v2.29.0/gh_2.29.0_linux_amd64.tar.gz: 9fe05f43a11a7bf8eacf731422452d1997e6708d4160ef0efcb13c103320390e https://github.com/cli/cli/releases/download/v2.29.0/gh_2.29.0_macOS_amd64.zip: e116d0f9c310450482cdcd7f4d2d1c7c4cab8d4f025a340260ce3f15329c5145 https://github.com/cli/cli/releases/download/v2.29.0/gh_2.29.0_macOS_arm64.zip: 38ca9a355376abd1475362cf8b3cacf2a757198fe5fe70349cb1767666abacc6 From a72584133935f991a94ad5b94c7397b28fd14651 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 2 Jun 2023 14:42:13 -0500 Subject: [PATCH 21/22] revert the rest of bindown.yml --- bindown.yml | 487 ++++++++++++++++++++++++++-------------------------- 1 file changed, 242 insertions(+), 245 deletions(-) diff --git a/bindown.yml b/bindown.yml index 6953ca49..47a48d05 100644 --- a/bindown.yml +++ b/bindown.yml @@ -1,10 +1,10 @@ cache: ./bin/.bindown install_dir: ./bin systems: - - darwin/amd64 - - darwin/arm64 - - linux/amd64 - - windows/amd64 +- darwin/amd64 +- darwin/arm64 +- linux/amd64 +- windows/amd64 dependencies: gh: template: origin#gh @@ -55,7 +55,7 @@ templates: url: https://github.com/WillAbides/bindown/releases/download/{{.tag}}/checksums.txt bin: checksums.txt required_vars: - - tag + - tag origin#gh: url: https://github.com/cli/cli/releases/download/v{{.version}}/gh_{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: gh_{{.version}}_{{.os}}_{{.arch}}/bin/gh{{.archivePathSuffix}} @@ -63,43 +63,42 @@ templates: vars: archivePathSuffix: "" urlSuffix: .zip + required_vars: + - version overrides: - - matcher: - os: - - windows - dependency: - archive_path: bin/gh{{.archivePathSuffix}} - vars: - archivePathSuffix: .exe - - matcher: - os: - - linux - dependency: - vars: - urlSuffix: .tar.gz - - matcher: - os: - - darwin - version: - - < 2.28.0 - dependency: - vars: - urlSuffix: .tar.gz + - matcher: + os: + - windows + dependency: + archive_path: bin/gh{{.archivePathSuffix}} + vars: + archivePathSuffix: .exe + - matcher: + os: + - linux + dependency: + vars: + urlSuffix: .tar.gz + - matcher: + os: + - darwin + version: + - < 2.28.0 + dependency: + vars: + urlSuffix: .tar.gz substitutions: os: darwin: macOS systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - windows/386 - - windows/amd64 - - windows/arm64 - required_vars: - - version - - foo + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 + - windows/arm64 origin#go: url: https://dl.google.com/go/go{{.version}}.{{.os}}-{{.arch}}{{.urlSuffix}} archive_path: go/bin/go{{.archivePathSuffix}} @@ -108,29 +107,29 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz + required_vars: + - version overrides: - - matcher: - os: - - windows - dependency: - vars: - archivePathSuffix: .exe - urlSuffix: .zip + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe + urlSuffix: .zip systems: - - darwin/amd64 - - darwin/arm64 - - freebsd/386 - - freebsd/amd64 - - linux/386 - - linux/amd64 - - linux/arm64 - - linux/ppc64le - - linux/s390x - - windows/386 - - windows/amd64 - - windows/arm64 - required_vars: - - version + - darwin/amd64 + - darwin/arm64 + - freebsd/386 + - freebsd/amd64 + - linux/386 + - linux/amd64 + - linux/arm64 + - linux/ppc64le + - linux/s390x + - windows/386 + - windows/amd64 + - windows/arm64 origin#gofumpt: url: https://github.com/mvdan/gofumpt/releases/download/v{{.version}}/gofumpt_v{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: gofumpt_v{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} @@ -138,23 +137,23 @@ templates: vars: archivePathSuffix: "" urlSuffix: "" + required_vars: + - version overrides: - - matcher: - os: - - windows - dependency: - vars: - urlSuffix: .exe + - matcher: + os: + - windows + dependency: + vars: + urlSuffix: .exe systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - windows/386 - - windows/amd64 - required_vars: - - version + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 origin#golangci-lint: url: https://github.com/golangci/golangci-lint/releases/download/v{{.version}}/golangci-lint-{{.version}}-{{.os}}-{{.arch}}{{.urlSuffix}} archive_path: golangci-lint-{{.version}}-{{.os}}-{{.arch}}/golangci-lint{{.archivePathSuffix}} @@ -162,35 +161,35 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz + required_vars: + - version overrides: - - matcher: - os: - - windows - dependency: - vars: - archivePathSuffix: .exe - urlSuffix: .zip + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe + urlSuffix: .zip systems: - - darwin/amd64 - - darwin/arm64 - - freebsd/386 - - freebsd/amd64 - - linux/386 - - linux/amd64 - - linux/arm64 - - linux/loong64 - - linux/mips64 - - linux/mips64le - - linux/ppc64le - - linux/riscv64 - - linux/s390x - - netbsd/386 - - netbsd/amd64 - - windows/386 - - windows/amd64 - - windows/arm64 - required_vars: - - version + - darwin/amd64 + - darwin/arm64 + - freebsd/386 + - freebsd/amd64 + - linux/386 + - linux/amd64 + - linux/arm64 + - linux/loong64 + - linux/mips64 + - linux/mips64le + - linux/ppc64le + - linux/riscv64 + - linux/s390x + - netbsd/386 + - netbsd/amd64 + - windows/386 + - windows/amd64 + - windows/arm64 origin#goreleaser: url: https://github.com/goreleaser/goreleaser/releases/download/v{{.version}}/goreleaser_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: goreleaser{{.archivePathSuffix}} @@ -198,20 +197,22 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz + required_vars: + - version overrides: - - matcher: + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe + urlSuffix: .zip + substitutions: + arch: + "386": i386 + amd64: x86_64 os: - - windows - dependency: - vars: - archivePathSuffix: .exe - urlSuffix: .zip - substitutions: - arch: - "386": i386 - amd64: x86_64 - os: - windows: Windows + windows: Windows substitutions: arch: "386": i386 @@ -220,41 +221,39 @@ templates: darwin: Darwin linux: Linux systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - linux/ppc64 - - windows/386 - - windows/amd64 - - windows/arm64 - required_vars: - - version + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - linux/ppc64 + - windows/386 + - windows/amd64 + - windows/arm64 origin#jq: - homepage: https://github.com/stedolan/jq - description: Command-line JSON processor url: https://github.com/stedolan/jq/releases/download/jq-{{.version}}/jq-{{.os}}{{.arch}}{{.extension}} archive_path: jq-{{.os}}{{.arch}}{{.extension}} bin: jq vars: extension: "" + required_vars: + - version overrides: - - matcher: - arch: - - amd64 - - arm64 - os: - - darwin - dependency: - url: https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64 - archive_path: jq-osx-amd64 - - matcher: - os: - - windows - dependency: - vars: - extension: .exe + - matcher: + arch: + - amd64 + - arm64 + os: + - darwin + dependency: + url: https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64 + archive_path: jq-osx-amd64 + - matcher: + os: + - windows + dependency: + vars: + extension: .exe substitutions: arch: "386": "32" @@ -262,14 +261,12 @@ templates: os: windows: win systems: - - linux/386 - - linux/amd64 - - darwin/amd64 - - darwin/arm64 - - windows/386 - - windows/amd64 - required_vars: - - version + - linux/386 + - linux/amd64 + - darwin/amd64 + - darwin/arm64 + - windows/386 + - windows/amd64 origin#semver-next: url: https://github.com/WillAbides/semver-next/releases/download/v{{.version}}/semver-next_{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: semver-next{{.archivePathSuffix}} @@ -277,24 +274,24 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz + required_vars: + - version overrides: - - matcher: - os: - - windows - dependency: - vars: - archivePathSuffix: .exe + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - windows/386 - - windows/amd64 - - windows/arm64 - required_vars: - - version + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 + - windows/arm64 origin#semver-prev: url: https://github.com/WillAbides/semver-prev/releases/download/v{{.version}}/semver-prev_{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: semver-prev{{.archivePathSuffix}} @@ -302,24 +299,24 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz + required_vars: + - version overrides: - - matcher: - os: - - windows - dependency: - vars: - archivePathSuffix: .exe + - matcher: + os: + - windows + dependency: + vars: + archivePathSuffix: .exe systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - windows/386 - - windows/amd64 - - windows/arm64 - required_vars: - - version + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 + - windows/arm64 origin#shellcheck: url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.{{.os}}.{{.arch}}{{.urlSuffix}} archive_path: shellcheck-v{{.version}}/shellcheck{{.archivePathSuffix}} @@ -327,33 +324,33 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.xz + required_vars: + - version overrides: - - matcher: - os: - - windows - dependency: - url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.zip - archive_path: shellcheck.exe - - matcher: + - matcher: + os: + - windows + dependency: + url: https://github.com/koalaman/shellcheck/releases/download/v{{.version}}/shellcheck-v{{.version}}.zip + archive_path: shellcheck.exe + - matcher: + arch: + - arm64 + os: + - darwin + dependency: + substitutions: arch: - - arm64 - os: - - darwin - dependency: - substitutions: - arch: - arm64: x86_64 + arm64: x86_64 substitutions: arch: amd64: x86_64 arm64: aarch64 systems: - - darwin/amd64 - - darwin/arm64 - - linux/amd64 - - linux/arm64 - required_vars: - - version + - darwin/amd64 + - darwin/arm64 + - linux/amd64 + - linux/arm64 origin#shfmt: url: https://github.com/mvdan/sh/releases/download/v{{.version}}/shfmt_v{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: shfmt_v{{.version}}_{{.os}}_{{.arch}}{{.urlSuffix}} @@ -361,23 +358,23 @@ templates: vars: archivePathSuffix: "" urlSuffix: "" + required_vars: + - version overrides: - - matcher: - os: - - windows - dependency: - vars: - urlSuffix: .exe + - matcher: + os: + - windows + dependency: + vars: + urlSuffix: .exe systems: - - darwin/amd64 - - darwin/arm64 - - linux/386 - - linux/amd64 - - linux/arm64 - - windows/386 - - windows/amd64 - required_vars: - - version + - darwin/amd64 + - darwin/arm64 + - linux/386 + - linux/amd64 + - linux/arm64 + - windows/386 + - windows/amd64 origin#yq: url: https://github.com/mikefarah/yq/releases/download/v{{.version}}/yq_{{.os}}_{{.arch}}{{.urlSuffix}} archive_path: ./yq_{{.os}}_{{.arch}}{{.archivePathSuffix}} @@ -385,38 +382,38 @@ templates: vars: archivePathSuffix: "" urlSuffix: .tar.gz + required_vars: + - version overrides: - - matcher: - os: - - windows - dependency: - archive_path: yq_{{.os}}_{{.arch}}{{.archivePathSuffix}} - vars: - archivePathSuffix: .exe - urlSuffix: .zip + - matcher: + os: + - windows + dependency: + archive_path: yq_{{.os}}_{{.arch}}{{.archivePathSuffix}} + vars: + archivePathSuffix: .exe + urlSuffix: .zip systems: - - darwin/amd64 - - darwin/arm64 - - freebsd/386 - - freebsd/amd64 - - linux/386 - - linux/amd64 - - linux/arm64 - - linux/mips - - linux/mips64 - - linux/mips64le - - linux/mipsle - - linux/ppc64 - - linux/ppc64le - - linux/s390x - - netbsd/386 - - netbsd/amd64 - - openbsd/386 - - openbsd/amd64 - - windows/386 - - windows/amd64 - required_vars: - - version + - darwin/amd64 + - darwin/arm64 + - freebsd/386 + - freebsd/amd64 + - linux/386 + - linux/amd64 + - linux/arm64 + - linux/mips + - linux/mips64 + - linux/mips64le + - linux/mipsle + - linux/ppc64 + - linux/ppc64le + - linux/s390x + - netbsd/386 + - netbsd/amd64 + - openbsd/386 + - openbsd/amd64 + - windows/386 + - windows/amd64 template_sources: origin: https://raw.githubusercontent.com/WillAbides/bindown-templates/main/bindown.yml url_checksums: From cfbe4b9511b0a6471554e047ef74c45b5ee0a027 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Fri, 2 Jun 2023 14:53:49 -0500 Subject: [PATCH 22/22] revert releaseURLExp --- cmd/bindown/dependency.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/bindown/dependency.go b/cmd/bindown/dependency.go index 637e7d9e..4b193dd2 100644 --- a/cmd/bindown/dependency.go +++ b/cmd/bindown/dependency.go @@ -329,7 +329,7 @@ type dependencyAddByGithubReleaseCmd struct { var ( releaseShortExp = regexp.MustCompile(`^([^/]+)/([^/^@]+)@?(.+)?$`) - releaseURLExp = regexp.MustCompile(`^https: //github\.com/([^/]+)/([^/]+)/releases/tag/([^/]+)`) + releaseURLExp = regexp.MustCompile(`^https://github\.com/([^/]+)/([^/]+)/releases/tag/([^/]+)`) ) func (c *dependencyAddByGithubReleaseCmd) Run(ctx *runContext) error {