Build with Magefile #104341

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

139
Makefile
View File

@ -23,10 +23,11 @@ ifeq (${GITHASH},dirty)
GITHASH := $(shell git rev-parse --short=9 HEAD) GITHASH := $(shell git rev-parse --short=9 HEAD)
endif endif
LDFLAGS := ${LDFLAGS} -X ${PKG}/internal/appinfo.ApplicationVersion=${VERSION} \ BUILDTOOL := mage
-X ${PKG}/internal/appinfo.ApplicationGitHash=${GITHASH} \ ifeq ($(OS),Windows_NT)
-X ${PKG}/internal/appinfo.ReleaseCycle=${RELEASE_CYCLE} BUILDTOOL := $(BUILDTOOL).exe
BUILD_FLAGS = -ldflags="${LDFLAGS}" endif
BUILDTOOL_PATH := ${PWD}/${BUILDTOOL}
# Package name of the generated Python/JavaScript code for the Flamenco API. # Package name of the generated Python/JavaScript code for the Flamenco API.
PY_API_PKG_NAME=flamenco.manager PY_API_PKG_NAME=flamenco.manager
@ -59,17 +60,20 @@ vet:
application: webapp flamenco-manager flamenco-worker application: webapp flamenco-manager flamenco-worker
flamenco-manager: flamenco-manager: buildtool
$(MAKE) webapp-static "${BUILDTOOL_PATH}" flamencoManager
go build -v ${BUILD_FLAGS} ${PKG}/cmd/flamenco-manager
.PHONY: flamenco-manager-without-webapp flamenco-manager-without-webapp: buildtool
flamenco-manager-without-webapp: "${BUILDTOOL_PATH}" flamencoManagerWithoutWebapp
go build -v ${BUILD_FLAGS} ${PKG}/cmd/flamenco-manager
flamenco-worker: flamenco-worker: buildtool
go build -v ${BUILD_FLAGS} ${PKG}/cmd/flamenco-worker "${BUILDTOOL_PATH}" flamencoWorker
# Builds the buildtool itself, for faster rebuilds of Skyfill.
buildtool: ${BUILDTOOL}
${BUILDTOOL}: mage.go $(wildcard magefiles/*.go) go.mod
@echo "Building build tool $@"
@go run mage.go -compile "${BUILDTOOL_PATH}"
# NOTE: these database migration commands are just for reference / debugging / # NOTE: these database migration commands are just for reference / debugging /
# development purposes. Flamenco Manager and Worker each perform their own # development purposes. Flamenco Manager and Worker each perform their own
@ -85,118 +89,29 @@ db-migrate-down:
goose -dir ./internal/manager/persistence/migrations/ sqlite3 flamenco-manager.sqlite down goose -dir ./internal/manager/persistence/migrations/ sqlite3 flamenco-manager.sqlite down
.PHONY: db-migrate-status db-migrate-up db-migrate-down .PHONY: db-migrate-status db-migrate-up db-migrate-down
.PHONY: stresser
stresser:
go build -v ${BUILD_FLAGS} ${PKG}/cmd/stresser
.PHONY: job-creator
job-creator:
go build -v ${BUILD_FLAGS} ${PKG}/cmd/job-creator
flamenco-addon.zip: addon-packer flamenco-addon.zip: addon-packer
./addon-packer -filename ./flamenco-addon.zip ./addon-packer -filename ./flamenco-addon.zip
addon-packer: cmd/addon-packer/addon-packer.go addon-packer: cmd/addon-packer/addon-packer.go
go build -v ${BUILD_FLAGS} ${PKG}/cmd/addon-packer go build -v ${BUILD_FLAGS} ${PKG}/cmd/addon-packer
flamenco-manager_race:
CGO_ENABLED=1 go build -race -o $@ -v ${BUILD_FLAGS} ${PKG}/cmd/flamenco-manager
flamenco-worker_race:
CGO_ENABLED=1 go build -race -o $@ -v ${BUILD_FLAGS} ${PKG}/cmd/flamenco-worker
.PHONY: shaman-checkout-id-setter
shaman-checkout-id-setter:
go build -v ${BUILD_FLAGS} ${PKG}/cmd/shaman-checkout-id-setter
webapp: webapp:
yarn --cwd web/app install yarn --cwd web/app install
webapp-static: addon-packer webapp-static: buildtool
$(MAKE) clean-webapp-static "${BUILDTOOL_PATH}" webappStatic
# When changing the base URL, also update the line
# e.GET("/app/*", echo.WrapHandler(webAppHandler))
# in `cmd/flamenco-manager/main.go`
MSYS2_ARG_CONV_EXCL="*" yarn --cwd web/app build --outDir ../static --base=/app/ --logLevel warn
# yarn --cwd web/app build --outDir ../static --base=/app/ --minify false
./addon-packer -filename ${WEB_STATIC}/flamenco-addon.zip
@echo "Web app has been installed into ${WEB_STATIC}"
generate: generate: buildtool
$(MAKE) generate-go "${BUILDTOOL_PATH}" generate
$(MAKE) generate-py
$(MAKE) generate-js
generate-go: generate-go: buildtool
go generate ./pkg/api/... "${BUILDTOOL_PATH}" generateGo
go generate ./internal/...
# The generators always produce UNIX line-ends. This creates false file
# modifications with Git. Convert them to DOS line-ends to avoid this.
ifeq ($(OS),Windows_NT)
git status --porcelain | grep '^ M .*.gen.go' | cut -d' ' -f3 | xargs unix2dos --keepdate
endif
generate-py: generate-py: buildtool
# The generator doesn't consistently overwrite existing files, nor does it "${BUILDTOOL_PATH}" generatePy
# remove no-longer-generated files.
rm -rf addon/flamenco/manager
# See https://openapi-generator.tech/docs/generators/python for the options. generate-js: buildtool
java -jar addon/openapi-generator-cli.jar \ "${BUILDTOOL_PATH}" generateJS
generate \
-i pkg/api/flamenco-openapi.yaml \
-g python \
-o addon/ \
--package-name "${PY_API_PKG_NAME}" \
--http-user-agent "Flamenco/${VERSION} (Blender add-on)" \
-p generateSourceCodeOnly=true \
-p projectName=Flamenco \
-p packageVersion="${VERSION}" > .openapi-generator-py.log
# The generator outputs files so that we can write our own tests. We don't,
# though, so it's better to just remove those placeholders.
rm -rf addon/flamenco/manager/test
# The generators always produce UNIX line-ends. This creates false file
# modifications with Git. Convert them to DOS line-ends to avoid this.
ifeq ($(OS),Windows_NT)
git status --porcelain | grep '^ M addon/flamenco/manager' | cut -d' ' -f3 | xargs unix2dos --keepdate
endif
generate-js:
# The generator doesn't consistently overwrite existing files, nor does it
# remove no-longer-generated files.
rm -rf web/app/src/manager-api
rm -rf web/_tmp-manager-api-javascript
# See https://openapi-generator.tech/docs/generators/javascript for the options.
# Version '0.0.0' is used as NPM doesn't like Git hashes as versions.
#
# -p modelPropertyNaming=original is needed because otherwise the generator will
# use original naming internally, but generate docs with camelCase, and then
# things don't work properly.
java -jar addon/openapi-generator-cli.jar \
generate \
-i pkg/api/flamenco-openapi.yaml \
-g javascript \
-o web/_tmp-manager-api-javascript \
--http-user-agent "Flamenco/${VERSION} / webbrowser" \
-p projectName=flamenco-manager \
-p projectVersion="0.0.0" \
-p apiPackage="${JS_API_PKG_NAME}" \
-p disallowAdditionalPropertiesIfNotPresent=false \
-p usePromises=true \
-p moduleName=flamencoManager > .openapi-generator-js.log
# Cherry-pick the generated sources, and remove everything else.
# The only relevant bit is that the generated code depends on `superagent`,
# which is listed in our `.
mv web/_tmp-manager-api-javascript/src web/app/src/manager-api
rm -rf web/_tmp-manager-api-javascript
# The generators always produce UNIX line-ends. This creates false file
# modifications with Git. Convert them to DOS line-ends to avoid this.
ifeq ($(OS),Windows_NT)
git status --porcelain | grep '^ M web/app/src/manager-api' | cut -d' ' -f3 | xargs unix2dos --keepdate
endif
.PHONY: .PHONY:
update-version: update-version:
@ -418,4 +333,4 @@ publish-release-packages:
${RELEASE_PACKAGE_LINUX} ${RELEASE_PACKAGE_DARWIN} ${RELEASE_PACKAGE_DARWIN_ARM64} ${RELEASE_PACKAGE_WINDOWS} ${RELEASE_PACKAGE_SHAFILE} \ ${RELEASE_PACKAGE_LINUX} ${RELEASE_PACKAGE_DARWIN} ${RELEASE_PACKAGE_DARWIN_ARM64} ${RELEASE_PACKAGE_WINDOWS} ${RELEASE_PACKAGE_SHAFILE} \
${WEBSERVER_SSH}:${WEBSERVER_ROOT}/downloads/ ${WEBSERVER_SSH}:${WEBSERVER_ROOT}/downloads/
.PHONY: application version flamenco-manager flamenco-worker flamenco-manager_race flamenco-worker_race webapp webapp-static generate generate-go generate-py with-deps swagger-ui list-embedded test clean clean-webapp-static .PHONY: application version flamenco-manager flamenco-worker flamenco-manager_race flamenco-worker_race webapp webapp-static generate generate-go generate-py with-deps swagger-ui list-embedded test clean clean-webapp-static flamenco-manager-without-webapp

View File

@ -55,10 +55,15 @@ func WebappStatic() error {
return err return err
} }
env := map[string]string{
"MSYS2_ARG_CONV_EXCL": "*",
}
// When changing the base URL, also update the line // When changing the base URL, also update the line
// e.GET("/app/*", echo.WrapHandler(webAppHandler)) // e.GET("/app/*", echo.WrapHandler(webAppHandler))
// in `cmd/flamenco-manager/main.go` // in `cmd/flamenco-manager/main.go`
err := sh.Run("yarn", err := sh.RunWithV(env,
"yarn",
"--cwd", "web/app", "--cwd", "web/app",
"build", "build",
"--outDir", "../static", "--outDir", "../static",
@ -87,7 +92,7 @@ func build(exePackage string) error {
args := []string{"build", "-v"} args := []string{"build", "-v"}
args = append(args, flags...) args = append(args, flags...)
args = append(args, exePackage) args = append(args, exePackage)
return sh.Run(mg.GoCmd(), args...) return sh.RunV(mg.GoCmd(), args...)
} }
func buildFlags() ([]string, error) { func buildFlags() ([]string, error) {

View File

@ -7,6 +7,7 @@ import (
"context" "context"
"fmt" "fmt"
"os" "os"
"path/filepath"
"regexp" "regexp"
"runtime" "runtime"
"strings" "strings"
@ -41,7 +42,6 @@ func GeneratePy() error {
sh.Rm("addon/flamenco/manager") sh.Rm("addon/flamenco/manager")
// See https://openapi-generator.tech/docs/generators/python for the options. // See https://openapi-generator.tech/docs/generators/python for the options.
err := sh.Run("java", err := sh.Run("java",
"-jar", "addon/openapi-generator-cli.jar", "-jar", "addon/openapi-generator-cli.jar",
"generate", "generate",
@ -49,10 +49,10 @@ func GeneratePy() error {
"-g", "python", "-g", "python",
"-o", "addon/", "-o", "addon/",
"--package-name", "flamenco.manager", "--package-name", "flamenco.manager",
"--http-user-agent", fmt.Sprintf("Flamenco/%s / (Blender add-on)", version), "--http-user-agent", fmt.Sprintf("Flamenco/%s (Blender add-on)", version),
"-p", "generateSourceCodeOnly=true", "-p", "generateSourceCodeOnly=true",
"-p", "projectName=Flamenco", "-p", "projectName=Flamenco",
"-p", fmt.Sprintf("packageVersion=\"%s\"", version)) "-p", fmt.Sprintf("packageVersion=%s", version))
if err != nil { if err != nil {
return err return err
} }
@ -64,16 +64,19 @@ func GeneratePy() error {
// The generators always produce UNIX line-ends. This creates false file // The generators always produce UNIX line-ends. This creates false file
// modifications with Git. Convert them to DOS line-ends to avoid this. // modifications with Git. Convert them to DOS line-ends to avoid this.
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
// TODO: Go'ify this: unix2dosModifiedFiles("addon/flamenco/manager")
// git status --porcelain | grep '^ M addon/flamenco/manager' | cut -d' ' -f3 | xargs unix2dos --keepdate
} }
return nil return nil
} }
func GenerateJS() error { func GenerateJS() error {
sh.Rm("web/app/src/manager-api") const (
sh.Rm("web/_tmp-manager-api-javascript") jsOutDir = "web/app/src/manager-api"
jsTempDir = "web/_tmp-manager-api-javascript"
)
sh.Rm(jsOutDir)
sh.Rm(jsTempDir)
// See https://openapi-generator.tech/docs/generators/javascript for the options. // See https://openapi-generator.tech/docs/generators/javascript for the options.
// Version '0.0.0' is used as NPM doesn't like Git hashes as versions. // Version '0.0.0' is used as NPM doesn't like Git hashes as versions.
@ -81,12 +84,12 @@ func GenerateJS() error {
// -p modelPropertyNaming=original is needed because otherwise the generator will // -p modelPropertyNaming=original is needed because otherwise the generator will
// use original naming internally, but generate docs with camelCase, and then // use original naming internally, but generate docs with camelCase, and then
// things don't work properly. // things don't work properly.
return sh.Run("java", err := sh.Run("java",
"-jar", "addon/openapi-generator-cli.jar", "-jar", "addon/openapi-generator-cli.jar",
"generate", "generate",
"-i", "pkg/api/flamenco-openapi.yaml", "-i", "pkg/api/flamenco-openapi.yaml",
"-g", "javascript", "-g", "javascript",
"-o", "web/_tmp-manager-api-javascript", "-o", jsTempDir,
"--http-user-agent", fmt.Sprintf("Flamenco/%s / webbrowser", version), "--http-user-agent", fmt.Sprintf("Flamenco/%s / webbrowser", version),
"-p", "projectName=flamenco-manager", "-p", "projectName=flamenco-manager",
"-p", "projectVersion=0.0.0", "-p", "projectVersion=0.0.0",
@ -94,6 +97,21 @@ func GenerateJS() error {
"-p", "disallowAdditionalPropertiesIfNotPresent=false", "-p", "disallowAdditionalPropertiesIfNotPresent=false",
"-p", "usePromises=true", "-p", "usePromises=true",
"-p", "moduleName=flamencoManager") "-p", "moduleName=flamencoManager")
if err != nil {
return err
}
// Cherry-pick the generated sources, and remove everything else.
if err := os.Rename(filepath.Join(jsTempDir, "src"), jsOutDir); err != nil {
return err
}
sh.Rm(jsTempDir)
if runtime.GOOS == "windows" {
unix2dosModifiedFiles(jsOutDir)
}
return nil
} }
// unix2dosModifiedFiles changes line ends in files Git considers modified that match the given pattern. // unix2dosModifiedFiles changes line ends in files Git considers modified that match the given pattern.

View File

@ -38,7 +38,7 @@ func (r *Runner) Run(cmd string, args ...string) {
if err := r.ctx.Err(); err != nil { if err := r.ctx.Err(); err != nil {
return err return err
} }
return sh.Run(cmd, args...) return sh.RunV(cmd, args...)
}) })
} }