Build with Magefile #104341

Merged
Sybren A. Stüvel merged 26 commits from magefile into main 2024-10-04 21:59:46 +02:00
5 changed files with 14 additions and 4 deletions
Showing only changes of commit 6e290a74d9 - Show all commits

View File

@ -23,18 +23,19 @@ var (
webStatic = filepath.Join("web", "static") webStatic = filepath.Join("web", "static")
) )
// Build Flamenco Manager and Flamenco Worker, including the webapp and the add-on
func Build() { func Build() {
mg.Deps(FlamencoManager, FlamencoWorker) mg.Deps(FlamencoManager, FlamencoWorker)
} }
// FlamencoManager builds Flamenco Manager with the webapp and add-on ZIP embedded. // Build Flamenco Manager with the webapp and add-on ZIP embedded
func FlamencoManager() error { func FlamencoManager() error {
mg.Deps(WebappStatic) mg.Deps(WebappStatic)
mg.Deps(flamencoManager) mg.Deps(flamencoManager)
return nil return nil
} }
// FlamencoManager only builds the Flamenco Manager executable. // Only build the Flamenco Manager executable, do not rebuild the webapp
func FlamencoManagerWithoutWebapp() error { func FlamencoManagerWithoutWebapp() error {
mg.Deps(flamencoManager) mg.Deps(flamencoManager)
return nil return nil
@ -44,12 +45,12 @@ func flamencoManager() error {
return build("./cmd/flamenco-manager") return build("./cmd/flamenco-manager")
} }
// FlamencoWorker builds the Flamenco Worker executable. // Build the Flamenco Worker executable
func FlamencoWorker() error { func FlamencoWorker() error {
return build("./cmd/flamenco-worker") return build("./cmd/flamenco-worker")
} }
// WebappStatic build the webapp as static files that can be served. // Build the webapp as static files that can be served
func WebappStatic() error { func WebappStatic() error {
if err := cleanWebappStatic(); err != nil { if err := cleanWebappStatic(); err != nil {
return err return err

View File

@ -18,10 +18,12 @@ import (
"honnef.co/go/tools/unused" "honnef.co/go/tools/unused"
) )
// Run unit tests, check for vulnerabilities, and run the linter
func Check(ctx context.Context) { func Check(ctx context.Context) {
mg.CtxDeps(ctx, Test, Govulncheck, Staticcheck, Vet) mg.CtxDeps(ctx, Test, Govulncheck, Staticcheck, Vet)
} }
// Run unit tests
func Test(ctx context.Context) error { func Test(ctx context.Context) error {
return sh.RunV(mg.GoCmd(), "test", "-short", "-failfast", "./...") return sh.RunV(mg.GoCmd(), "test", "-short", "-failfast", "./...")
} }
@ -53,6 +55,7 @@ func Staticcheck() error {
return nil return nil
} }
// Run `go vet`
func Vet() error { func Vet() error {
return sh.RunV(mg.GoCmd(), "vet", "./...") return sh.RunV(mg.GoCmd(), "vet", "./...")
} }

View File

@ -10,6 +10,7 @@ import (
"github.com/magefile/mage/sh" "github.com/magefile/mage/sh"
) )
// Remove executables and other build output
func Clean() error { func Clean() error {
if err := cleanWebappStatic(); err != nil { if err := cleanWebappStatic(); err != nil {
return err return err

View File

@ -16,10 +16,12 @@ import (
"github.com/magefile/mage/sh" "github.com/magefile/mage/sh"
) )
// Generate code (OpenAPI and test mocks)
func Generate() { func Generate() {
mg.Deps(GenerateGo, GeneratePy, GenerateJS) mg.Deps(GenerateGo, GeneratePy, GenerateJS)
} }
// Generate Go code for Flamenco Manager and Worker
func GenerateGo(ctx context.Context) error { func GenerateGo(ctx context.Context) error {
r := NewRunner(ctx) r := NewRunner(ctx)
r.Run(mg.GoCmd(), "generate", "./pkg/api/...") r.Run(mg.GoCmd(), "generate", "./pkg/api/...")
@ -36,6 +38,7 @@ func GenerateGo(ctx context.Context) error {
return nil return nil
} }
// Generate Python code for the add-on
func GeneratePy() error { func GeneratePy() error {
// The generator doesn't consistently overwrite existing files, nor does it // The generator doesn't consistently overwrite existing files, nor does it
// remove no-longer-generated files. // remove no-longer-generated files.
@ -70,6 +73,7 @@ func GeneratePy() error {
return nil return nil
} }
// Generate JavaScript code for the webapp
func GenerateJS() error { func GenerateJS() error {
const ( const (
jsOutDir = "web/app/src/manager-api" jsOutDir = "web/app/src/manager-api"

View File

@ -19,6 +19,7 @@ func gitHash() (string, error) {
return sh.Output("git", "rev-parse", "--short", "HEAD") return sh.Output("git", "rev-parse", "--short", "HEAD")
} }
// Show which version information would be embedded in executables
func Version() error { func Version() error {
fmt.Printf("Package : %s\n", goPkg) fmt.Printf("Package : %s\n", goPkg)
fmt.Printf("Version : %s\n", version) fmt.Printf("Version : %s\n", version)