Dan Anglin
c2a1e28773
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
84 lines
1.6 KiB
Go
84 lines
1.6 KiB
Go
//go:build mage
|
|
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
"fmt"
|
|
//"path/filepath"
|
|
|
|
"github.com/magefile/mage/sh"
|
|
)
|
|
|
|
const (
|
|
binary = "greet"
|
|
)
|
|
|
|
var Default = Build
|
|
|
|
// Test runs the go tests.
|
|
// To enable verbose mode set GO_TEST_VERBOSE=1.
|
|
// To enable coverage mode set GO_TEST_COVER=1.
|
|
func Test() error {
|
|
if err := changeToProjectRoot(); err != nil {
|
|
return fmt.Errorf("unable to begin tests; %w", err)
|
|
}
|
|
|
|
goTest := sh.RunCmd("go", "test")
|
|
|
|
args := []string{"."}
|
|
|
|
if os.Getenv("GO_TEST_VERBOSE") == "1" {
|
|
args = append(args, "-v")
|
|
}
|
|
|
|
if os.Getenv("GO_TEST_COVER") == "1" {
|
|
args = append(args, "-cover")
|
|
}
|
|
|
|
return goTest(args...)
|
|
}
|
|
|
|
// Lint runs golangci-lint against the code.
|
|
func Lint() error {
|
|
if err := changeToProjectRoot(); err != nil {
|
|
return fmt.Errorf("unable to start the lint tests; %w", err)
|
|
}
|
|
|
|
return sh.RunV("golangci-lint", "run", "--color", "always")
|
|
}
|
|
|
|
// Build builds the executable.
|
|
func Build() error {
|
|
if err := changeToProjectRoot(); err != nil {
|
|
return fmt.Errorf("unable to start building the binary; %w", err)
|
|
}
|
|
|
|
main := "greet.go"
|
|
return sh.Run("go", "build", "-o", binary, main)
|
|
}
|
|
|
|
// Clean cleans the workspace.
|
|
func Clean() error {
|
|
if err := changeToProjectRoot(); err != nil {
|
|
return fmt.Errorf("unable to start the cleaning process; %w", err)
|
|
}
|
|
|
|
if err := sh.Rm(binary); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := sh.Run("go", "clean", "."); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func changeToProjectRoot() error {
|
|
if err := os.Chdir("../.."); err != nil {
|
|
return fmt.Errorf("unable to change directory; %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|