diff --git a/Makefile b/Makefile index 80fa1396..31a730d7 100644 --- a/Makefile +++ b/Makefile @@ -154,6 +154,12 @@ devserver-website: devserver-webapp: buildtool "${BUILDTOOL_PATH}" devServerWebapp +format: buildtool + "${BUILDTOOL_PATH}" format + +format-check: buildtool + "${BUILDTOOL_PATH}" formatCheck + deploy-website: $(MAKE) -s check-environment rm -rf web/project-website/public/ @@ -311,4 +317,4 @@ publish-release-packages: ${RELEASE_PACKAGE_LINUX} ${RELEASE_PACKAGE_DARWIN} ${RELEASE_PACKAGE_DARWIN_ARM64} ${RELEASE_PACKAGE_WINDOWS} ${RELEASE_PACKAGE_SHAFILE} \ ${WEBSERVER_SSH}:${WEBSERVER_ROOT}/downloads/ -.PHONY: application version flamenco-manager flamenco-worker webapp webapp-static generate generate-go generate-py with-deps swagger-ui list-embedded test clean flamenco-manager-without-webapp +.PHONY: application version flamenco-manager flamenco-worker webapp webapp-static generate generate-go generate-py with-deps swagger-ui list-embedded test clean flamenco-manager-without-webapp format format-check diff --git a/magefiles/check.go b/magefiles/check.go index 4e179653..fd4bff1d 100644 --- a/magefiles/check.go +++ b/magefiles/check.go @@ -20,7 +20,7 @@ import ( // Run unit tests, check for vulnerabilities, and run the linter func Check(ctx context.Context) { - mg.CtxDeps(ctx, Test, Govulncheck, Staticcheck, Vet) + mg.CtxDeps(ctx, Test, Govulncheck, Staticcheck, Vet, FormatCheck) } // Run unit tests @@ -59,3 +59,23 @@ func Staticcheck() error { func Vet() error { return sh.RunV(mg.GoCmd(), "vet", "./...") } + +// Run `gofmt`, formatting all the source code. +func Format() error { + return sh.RunV("gofmt", "-s", "-w", ".") +} + +// Run `gofmt` on all the source code, reporting all differences. +func FormatCheck(ctx context.Context) error { + output, err := sh.Output("gofmt", "-d", ".") + if err != nil { + return err + } + + if output == "" { + // Format was OK. + return nil + } + + return fmt.Errorf("Formatting check failed:\n%s", output) +}