2023-05-13 23:06:25 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"dagger.io/dagger"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if err := run(context.Background()); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// run creates the Dagger client and runs the pipeline.
|
|
|
|
func run(ctx context.Context) error {
|
|
|
|
log.Println("Building with Dagger")
|
|
|
|
|
|
|
|
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("unable to initiate the Dagger client, %w", err)
|
|
|
|
}
|
|
|
|
defer client.Close()
|
|
|
|
|
2023-05-20 05:48:22 +01:00
|
|
|
client = client.Pipeline("Greet Build Pipeline")
|
|
|
|
cache := client.CacheVolume("go-mod-cache")
|
|
|
|
|
2023-05-13 23:06:25 +01:00
|
|
|
projectRoot, err := filepath.Abs("../..")
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("unable to get the project's root directory, %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
stages := [2]stage{
|
|
|
|
{
|
|
|
|
name: "Mage Test",
|
|
|
|
projectRoot: projectRoot,
|
|
|
|
stageFunc: test,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Mage Lint",
|
|
|
|
projectRoot: projectRoot,
|
|
|
|
stageFunc: lint,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range stages {
|
2023-05-20 05:48:22 +01:00
|
|
|
if err := stages[i].run(ctx, client, cache); err != nil {
|
2023-05-13 23:06:25 +01:00
|
|
|
return fmt.Errorf("error running pipeline; %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|