Compare commits
No commits in common. "f7805184a065f17bf4d12dcff6897bbf0d3bb47b" and "07549bdffbfa9a51395ee165d1bc661452cff22b" have entirely different histories.
f7805184a0
...
07549bdffb
2 changed files with 11 additions and 19 deletions
|
@ -26,9 +26,6 @@ func run(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
|
|
||||||
client = client.Pipeline("Greet Build Pipeline")
|
|
||||||
cache := client.CacheVolume("go-mod-cache")
|
|
||||||
|
|
||||||
projectRoot, err := filepath.Abs("../..")
|
projectRoot, err := filepath.Abs("../..")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to get the project's root directory, %w", err)
|
return fmt.Errorf("unable to get the project's root directory, %w", err)
|
||||||
|
@ -48,7 +45,7 @@ func run(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range stages {
|
for i := range stages {
|
||||||
if err := stages[i].run(ctx, client, cache); err != nil {
|
if err := stages[i].run(ctx, client); err != nil {
|
||||||
return fmt.Errorf("error running pipeline; %w", err)
|
return fmt.Errorf("error running pipeline; %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,33 +1,30 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
|
|
||||||
"dagger.io/dagger"
|
"dagger.io/dagger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type stage struct {
|
type stage struct {
|
||||||
name string
|
name string
|
||||||
projectRoot string
|
projectRoot string
|
||||||
stageFunc func(ctx context.Context, client *dagger.Client, projectRoot string, cache *dagger.CacheVolume) error
|
stageFunc func(ctx context.Context, client *dagger.Client, projectRoot string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stage) run(ctx context.Context, client *dagger.Client, cache *dagger.CacheVolume) error {
|
func (s *stage) run(ctx context.Context, client *dagger.Client) error {
|
||||||
log.Printf("Running stage: %s", s.name)
|
log.Printf("Running stage: %s", s.name)
|
||||||
|
|
||||||
pipeline := client.Pipeline(s.name)
|
if err := s.stageFunc(ctx, client, s.projectRoot); err != nil {
|
||||||
|
|
||||||
if err := s.stageFunc(ctx, pipeline, s.projectRoot, cache); err != nil {
|
|
||||||
return fmt.Errorf("error running stage '%s'; %w", s.name, err)
|
return fmt.Errorf("error running stage '%s'; %w", s.name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// test is a stage that runs the test suite using mage.
|
// test is a stage that runs the test suite using mage
|
||||||
func test(ctx context.Context, client *dagger.Client, projectRoot string, cache *dagger.CacheVolume) error {
|
func test(ctx context.Context, client *dagger.Client, projectRoot string) error {
|
||||||
image := "golang:1.20.4"
|
image := "golang:1.20.4"
|
||||||
containerWorkspace := "/workspace"
|
containerWorkspace := "/workspace"
|
||||||
containerWorkdir := containerWorkspace + "/internal/build"
|
containerWorkdir := containerWorkspace + "/internal/build"
|
||||||
|
@ -38,16 +35,15 @@ func test(ctx context.Context, client *dagger.Client, projectRoot string, cache
|
||||||
WithWorkdir(containerWorkdir).
|
WithWorkdir(containerWorkdir).
|
||||||
WithEnvVariable("GO_TEST_VERBOSE", "1").
|
WithEnvVariable("GO_TEST_VERBOSE", "1").
|
||||||
WithEnvVariable("GO_TEST_COVER", "1").
|
WithEnvVariable("GO_TEST_COVER", "1").
|
||||||
WithExec([]string{"go", "run", "magefiles/main.go", "-v", "test"}).
|
WithExec([]string{"go", "run", "magefiles/main.go", "-v", "test"})
|
||||||
WithMountedCache("/go/pkg/mod", cache)
|
|
||||||
|
|
||||||
_, err := runner.Stdout(ctx)
|
_, err := runner.Stdout(ctx)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// lint is a stage that runs the linter using mage.
|
// lint is a stage that runs the linter using mage
|
||||||
func lint(ctx context.Context, client *dagger.Client, projectRoot string, cache *dagger.CacheVolume) error {
|
func lint(ctx context.Context, client *dagger.Client, projectRoot string) error {
|
||||||
image := "golangci/golangci-lint:v1.52.2-alpine"
|
image := "golangci/golangci-lint:v1.52.2-alpine"
|
||||||
containerWorkspace := "/workspace"
|
containerWorkspace := "/workspace"
|
||||||
containerWorkdir := containerWorkspace + "/internal/build"
|
containerWorkdir := containerWorkspace + "/internal/build"
|
||||||
|
@ -56,8 +52,7 @@ func lint(ctx context.Context, client *dagger.Client, projectRoot string, cache
|
||||||
From(image).
|
From(image).
|
||||||
WithMountedDirectory(containerWorkspace, client.Host().Directory(projectRoot)).
|
WithMountedDirectory(containerWorkspace, client.Host().Directory(projectRoot)).
|
||||||
WithWorkdir(containerWorkdir).
|
WithWorkdir(containerWorkdir).
|
||||||
WithExec([]string{"go", "run", "magefiles/main.go", "-v", "lint"}).
|
WithExec([]string{"go", "run", "magefiles/main.go", "-v", "lint"})
|
||||||
WithMountedCache("/go/pkg/mod", cache)
|
|
||||||
|
|
||||||
_, err := runner.Stdout(ctx)
|
_, err := runner.Stdout(ctx)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue