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()
|
||||
|
||||
client = client.Pipeline("Greet Build Pipeline")
|
||||
cache := client.CacheVolume("go-mod-cache")
|
||||
|
||||
projectRoot, err := filepath.Abs("../..")
|
||||
if err != nil {
|
||||
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 {
|
||||
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)
|
||||
}
|
||||
}
|
|
@ -1,33 +1,30 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"dagger.io/dagger"
|
||||
)
|
||||
|
||||
type stage struct {
|
||||
name 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)
|
||||
|
||||
pipeline := client.Pipeline(s.name)
|
||||
|
||||
if err := s.stageFunc(ctx, pipeline, s.projectRoot, cache); err != nil {
|
||||
if err := s.stageFunc(ctx, client, s.projectRoot); err != nil {
|
||||
return fmt.Errorf("error running stage '%s'; %w", s.name, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 {
|
||||
// test is a stage that runs the test suite using mage
|
||||
func test(ctx context.Context, client *dagger.Client, projectRoot string) error {
|
||||
image := "golang:1.20.4"
|
||||
containerWorkspace := "/workspace"
|
||||
containerWorkdir := containerWorkspace + "/internal/build"
|
||||
|
@ -38,16 +35,15 @@ func test(ctx context.Context, client *dagger.Client, projectRoot string, cache
|
|||
WithWorkdir(containerWorkdir).
|
||||
WithEnvVariable("GO_TEST_VERBOSE", "1").
|
||||
WithEnvVariable("GO_TEST_COVER", "1").
|
||||
WithExec([]string{"go", "run", "magefiles/main.go", "-v", "test"}).
|
||||
WithMountedCache("/go/pkg/mod", cache)
|
||||
WithExec([]string{"go", "run", "magefiles/main.go", "-v", "test"})
|
||||
|
||||
_, err := runner.Stdout(ctx)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// lint is a stage that runs the linter using mage.
|
||||
func lint(ctx context.Context, client *dagger.Client, projectRoot string, cache *dagger.CacheVolume) error {
|
||||
// lint is a stage that runs the linter using mage
|
||||
func lint(ctx context.Context, client *dagger.Client, projectRoot string) error {
|
||||
image := "golangci/golangci-lint:v1.52.2-alpine"
|
||||
containerWorkspace := "/workspace"
|
||||
containerWorkdir := containerWorkspace + "/internal/build"
|
||||
|
@ -56,8 +52,7 @@ func lint(ctx context.Context, client *dagger.Client, projectRoot string, cache
|
|||
From(image).
|
||||
WithMountedDirectory(containerWorkspace, client.Host().Directory(projectRoot)).
|
||||
WithWorkdir(containerWorkdir).
|
||||
WithExec([]string{"go", "run", "magefiles/main.go", "-v", "lint"}).
|
||||
WithMountedCache("/go/pkg/mod", cache)
|
||||
WithExec([]string{"go", "run", "magefiles/main.go", "-v", "lint"})
|
||||
|
||||
_, err := runner.Stdout(ctx)
|
||||
|
||||
|
|
Loading…
Reference in a new issue