Skip to content

Commit

Permalink
feat: update POC
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Mar 3, 2024
1 parent 6fb922a commit 0b14054
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions pkg/experimental/commands/.mygcl.reference.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
version: v1.56.2
name: custom-golangci-lint # optional, default: gcl-custom
destination: ./my/path/ # optional, default: .
plugins:
# a plugin from a Go proxy
- module: 'github.com/example/plugin3'
Expand Down
9 changes: 8 additions & 1 deletion pkg/experimental/commands/custom/internal/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,14 @@ func (b Builder) copyBinary(binaryName string) error {
return fmt.Errorf("stat source file: %w", err)
}

dst, err := os.OpenFile(filepath.Clean(binaryName), os.O_RDWR|os.O_CREATE|os.O_TRUNC, info.Mode())
if b.cfg.Destination != "" {
err = os.MkdirAll(b.cfg.Destination, os.ModePerm)
if err != nil {
return fmt.Errorf("create destination directory: %w", err)
}
}

dst, err := os.OpenFile(filepath.Join(b.cfg.Destination, binaryName), os.O_RDWR|os.O_CREATE|os.O_TRUNC, info.Mode())
if err != nil {
return fmt.Errorf("create destination file: %w", err)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/experimental/commands/custom/internal/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type Configuration struct {
// Name of the binary.
Name string `yaml:"name,omitempty"`

// Destination is the path to a directory to store the binary.
Destination string `yaml:"destination,omitempty"`

// Plugins information.
Plugins []*Plugin `yaml:"plugins,omitempty"`
}
Expand Down
11 changes: 2 additions & 9 deletions pkg/experimental/commands/custom/internal/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
func (b Builder) updatePluginsFile() error {
importsDest := filepath.Join(b.repo, "cmd", "golangci-lint", "plugins.go")

_, err := os.Stat(importsDest)
info, err := os.Stat(importsDest)
if err != nil {
return fmt.Errorf("file %s not found: %w", importsDest, err)
}
Expand All @@ -34,14 +34,7 @@ func (b Builder) updatePluginsFile() error {

b.log.Infof("generated imports info %s:\n%s\n", importsDest, source)

file, err := os.Open(filepath.Clean(importsDest))
if err != nil {
return fmt.Errorf("open file %s: %w", importsDest, err)
}

defer func() { _ = file.Close() }()

_, err = file.Write(source)
err = os.WriteFile(filepath.Clean(importsDest), source, info.Mode())
if err != nil {
return fmt.Errorf("write file %s: %w", importsDest, err)
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/experimental/commands/mygcl.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
"type": "string",
"description": "Name of the binary."
},
"destination": {
"type": "string",
"description": "Destination is the path to a directory to store the binary."
},
"plugins": {
"items": {
"$ref": "#/$defs/Plugin"
Expand Down Expand Up @@ -69,4 +73,4 @@
}
},
"description": "mygcl configuration definition file"
}
}

0 comments on commit 0b14054

Please sign in to comment.