This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Overhaul with multiplatform build, nicer API, and embedded KO build (#9)
* A rework of the library structure * Project builds and passes golangci-lint * Binary builds are working * In fact build for various platforms. * Tweaking the output * KO build works, tests as well * Basic KO publisher * Publishing works * LDflags for images works * Minor UI fixes * Remove changes for ko-build/ko#476
- Loading branch information
Showing
63 changed files
with
3,070 additions
and
622 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,44 @@ | ||
run: | ||
timeout: 5m | ||
build-tags: | ||
- e2e | ||
- mage | ||
|
||
linters: | ||
disable-all: false | ||
presets: | ||
- bugs | ||
- unused | ||
- complexity | ||
- format | ||
- performance | ||
- style | ||
enable: | ||
- bodyclose | ||
- deadcode | ||
- depguard | ||
- dogsled | ||
- dupl | ||
- errcheck | ||
- exhaustive | ||
- funlen | ||
- goconst | ||
- gocritic | ||
- gocyclo | ||
- gofmt | ||
- goimports | ||
- golint | ||
- gomnd | ||
- goprintffuncname | ||
- gosec | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- interfacer | ||
- lll | ||
- misspell | ||
- nakedret | ||
- noctx | ||
- nolintlint | ||
- rowserrcheck | ||
- scopelint | ||
- staticcheck | ||
- structcheck | ||
- stylecheck | ||
- typecheck | ||
- unconvert | ||
- unparam | ||
- unused | ||
- varcheck | ||
- asciicheck | ||
- gocognit | ||
- godot | ||
- godox | ||
- goerr113 | ||
- maligned | ||
- nestif | ||
- prealloc | ||
- testpackage | ||
- gci | ||
disable: | ||
- whitespace | ||
- paralleltest | ||
- nlreturn | ||
- exhaustivestruct | ||
- wsl | ||
- godox | ||
- scopelint | ||
- maligned | ||
- interfacer | ||
- golint | ||
- deadcode | ||
- gochecknoglobals | ||
- wrapcheck | ||
|
||
issues: | ||
exclude-rules: | ||
- path: _test\.go | ||
linters: | ||
- wrapcheck | ||
|
||
|
||
linters-settings: | ||
gomoddirectives: | ||
# List of allowed `replace` directives. Default is empty. | ||
replace-allow-list: | ||
# FIXME: remove after https://github.com/google/ko/issues/476 | ||
- github.com/google/ko |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package magetasks | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/magefile/mage/mg" | ||
"github.com/wavesoftware/go-magetasks/config" | ||
"github.com/wavesoftware/go-magetasks/pkg/artifact" | ||
"github.com/wavesoftware/go-magetasks/pkg/files" | ||
"github.com/wavesoftware/go-magetasks/pkg/tasks" | ||
) | ||
|
||
// ErrNoBuilderForArtifact when no builder for artifact is found. | ||
var ErrNoBuilderForArtifact = errors.New("no builder for artifact found") | ||
|
||
// Build will build project artifacts, binaries and images. | ||
func Build() { | ||
mg.Deps(Test, files.EnsureBuildDir) | ||
t := tasks.Start("🔨", "Building", len(config.Actual().Artifacts) > 0) | ||
for _, art := range config.Actual().Artifacts { | ||
p := t.Part(fmt.Sprintf("%s %s", art.GetType(), art.GetName())) | ||
pp := p.Starting() | ||
|
||
buildArtifact(art, pp) | ||
} | ||
t.End() | ||
} | ||
|
||
func buildArtifact(art config.Artifact, pp tasks.PartProcessing) { | ||
found := false | ||
for _, builder := range config.Actual().Builders { | ||
if !builder.Accepts(art) { | ||
continue | ||
} | ||
found = true | ||
result := builder.Build(art, pp) | ||
if result.Failed() { | ||
pp.Done(result.Error) | ||
return | ||
} | ||
config.WithContext(func(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, artifact.BuildKey(art), result) | ||
}) | ||
} | ||
var err error | ||
if !found { | ||
err = ErrNoBuilderForArtifact | ||
} | ||
pp.Done(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package config | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/fatih/color" | ||
) | ||
|
||
var ( | ||
// DefaultBuilders is a list of default builders. | ||
DefaultBuilders = make([]Builder, 0) | ||
// DefaultPublishers is a list of default publishers. | ||
DefaultPublishers = make([]Publisher, 0) | ||
) | ||
|
||
// FillInDefaultValues in provided config and returns a filled one. | ||
func FillInDefaultValues(cfg Config) Config { | ||
if len(cfg.BuildDirPath) == 0 { | ||
cfg.BuildDirPath = []string{"build", "_output"} | ||
} | ||
empty := &MageTag{} | ||
if cfg.MageTag == *empty { | ||
cfg.MageTag = MageTag{ | ||
Color: color.FgCyan, | ||
Label: "[MAGE]", | ||
} | ||
} | ||
if cfg.Dependencies == nil { | ||
cfg.Dependencies = NewDependencies("github.com/kyoh86/richgo") | ||
} | ||
if cfg.Context == nil { | ||
cfg.Context = context.TODO() | ||
} | ||
if cfg.Artifacts == nil { | ||
cfg.Artifacts = make([]Artifact, 0) | ||
} | ||
if len(cfg.Builders) == 0 { | ||
cfg.Builders = append(cfg.Builders, DefaultBuilders...) | ||
} | ||
if len(cfg.Publishers) == 0 { | ||
cfg.Publishers = append(cfg.Publishers, DefaultPublishers...) | ||
} | ||
return cfg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package config | ||
|
||
type Dependencies interface { | ||
Configurator | ||
Installs() []string | ||
merge(other Dependencies) | ||
} | ||
|
||
func NewDependencies(deps ...string) Dependencies { | ||
s := make(map[string]bool, len(deps)) | ||
for _, dep := range deps { | ||
s[dep] = exists | ||
} | ||
return dependencies{ | ||
set: s, | ||
} | ||
} | ||
|
||
const exists = true | ||
|
||
type dependencies struct { | ||
set map[string]bool | ||
} | ||
|
||
func (d dependencies) Installs() []string { | ||
keys := make([]string, len(d.set)) | ||
|
||
i := 0 | ||
for k := range d.set { | ||
keys[i] = k | ||
i++ | ||
} | ||
|
||
return keys | ||
} | ||
|
||
func (d dependencies) Configure(cfg Configurable) { | ||
cfg.Config().Dependencies.merge(d) | ||
} | ||
|
||
func (d dependencies) merge(other Dependencies) { | ||
for _, dep := range other.Installs() { | ||
d.set[dep] = exists | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.