greet/internal/build/dagger.go
Dan Anglin c2a1e28773
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ci: add CI pipelines
Summary:

Add simple CI pipelines to the greet project. Here we add CI pipelines
for both Woodpecker and Dagger CI as we are currently interested in both
technologies.

Changes:

- Add .woodpecker/woodpecker.yml
- Updated LICENSE
- Updated README.md
- Fixed linting issues in greet.go
- Created a new internal go module for CI/CD in internal/build
- Moved the magefiles to internal/build/magefiles
- Add dagger pipeline code
2023-05-13 23:06:25 +01:00

54 lines
994 B
Go

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()
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 {
if err := stages[i].run(ctx, client); err != nil {
return fmt.Errorf("error running pipeline; %w", err)
}
}
return nil
}