Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
Overhaul with multiplatform build, nicer API, and embedded KO build (#9)
Browse files Browse the repository at this point in the history
* 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
cardil authored Oct 14, 2021
1 parent d81ad26 commit 9961ce9
Show file tree
Hide file tree
Showing 63 changed files with 3,070 additions and 622 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: golangci/golangci-lint-action@v2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.35.2
version: latest
editorconfig:
name: EditorConfig
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ jobs:
strategy:
matrix:
go-version:
- '1.15'
- '1.16'
- '1.17'
steps:

- name: Set up Go ${{ matrix.go-version }}
Expand Down
79 changes: 33 additions & 46 deletions .golangci.yml
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
39 changes: 0 additions & 39 deletions binary.go

This file was deleted.

52 changes: 52 additions & 0 deletions build.go
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)
}
12 changes: 6 additions & 6 deletions checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package magetasks
import (
"github.com/magefile/mage/mg"
"github.com/wavesoftware/go-magetasks/config"
"github.com/wavesoftware/go-magetasks/internal"
"github.com/wavesoftware/go-magetasks/pkg/deps"
"github.com/wavesoftware/go-magetasks/pkg/tasks"
)

// Check will run all lints checks.
func Check() {
mg.Deps(internal.BuildDeps)
t := tasks.StartMultiline("🔍", "Checking")
for _, check := range config.Checks {
mg.Deps(deps.Install)
t := tasks.Start("🔍", "Checking", len(config.Actual().Checks) > 0)
for _, check := range config.Actual().Checks {
p := t.Part(check.Name)
ps := p.Starting()
ps.Done(check.Task())
pp := p.Starting()
pp.Done(check.Operation(pp))
}
t.End(nil)
}
11 changes: 6 additions & 5 deletions cleaning.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import (
"os"

"github.com/wavesoftware/go-magetasks/config"
"github.com/wavesoftware/go-magetasks/internal"
"github.com/wavesoftware/go-magetasks/pkg/files"
"github.com/wavesoftware/go-magetasks/pkg/tasks"
)

// Clean will clean project files.
func Clean() {
t := tasks.Start("🚿", "Cleaning")
err := os.RemoveAll(internal.BuildDir())
t := tasks.Start("🚿", "Cleaning", len(config.Actual().Cleaning) > 0)
err := os.RemoveAll(files.BuildDir())
errs := make([]error, 0, 1)
errs = append(errs, err)
for _, task := range config.CleaningTasks {
for _, task := range config.Actual().Cleaning {
p := t.Part(task.Name)
p.Starting().Done(task.Task())
pp := p.Starting()
pp.Done(task.Operation(pp))
}
t.End(errs...)
}
44 changes: 44 additions & 0 deletions config/defaults.go
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
}
45 changes: 45 additions & 0 deletions config/deps.go
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
}
}
34 changes: 0 additions & 34 deletions config/settings.go

This file was deleted.

Loading

0 comments on commit 9961ce9

Please sign in to comment.