Sybren A. Stüvel
5f37bcb629
Convert most of the code in `Makefile` to [Magefile](https://magefile.org/): This makes it possible to build Flamenco without `make` (and the POSIX environment/commands it expect) by running: ```bash $ go run mage.go webappInstallDeps # Only on the first build. $ go run mage.go build ``` More efficient builds are possible with other commands, and some release-related commands still require `make`. At least the barrier to entry should be considerably lower (compared to having to install Make + Cygwin/MSYS2 on Windows). Fix: #102633 This does not port the building of release packages, so it doesn't address #102671. ### Main Targets | Target | Description | |----------|---------------------------------------------------------------------------------| | build | Build Flamenco Manager and Flamenco Worker, including the webapp and the add-on | | check | Run unit tests, check for vulnerabilities, and run the linter | | clean | Remove executables and other build output | | generate | Generate code (OpenAPI and test mocks) | ### All Targets Get these via `go run mage.go -l`: ``` Targets: build Flamenco Manager and Flamenco Worker, including the webapp and the add-on check Run unit tests, check for vulnerabilities, and run the linter clean Remove executables and other build output flamencoManager Build Flamenco Manager with the webapp and add-on ZIP embedded flamencoManagerWithoutWebapp Only build the Flamenco Manager executable, do not rebuild the webapp flamencoWorker Build the Flamenco Worker executable generate code (OpenAPI and test mocks) generateGo Generate Go code for Flamenco Manager and Worker generateJS Generate JavaScript code for the webapp generatePy Generate Python code for the add-on govulncheck Check for known vulnerabilities. staticcheck Analyse the source code. test Run unit tests version Show which version information would be embedded in executables vet Run `go vet` webappInstallDeps Use Yarn to install the webapp's NodeJS dependencies webappStatic Build the webapp as static files that can be served ``` Co-authored-by: Mateus Abelli <mateusabelli@gmail.com> Reviewed-on: #104341
101 lines
2.5 KiB
Go
101 lines
2.5 KiB
Go
package main
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/mattn/go-colorable"
|
|
"github.com/rs/zerolog"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
// Global variables used by the updateXXX() functions.
|
|
var (
|
|
cliArgs struct {
|
|
// Logging level flags.
|
|
quiet, debug, trace bool
|
|
|
|
newVersion string
|
|
updateMakefile bool
|
|
}
|
|
|
|
releaseCycle string
|
|
)
|
|
|
|
func main() {
|
|
parseCliArgs()
|
|
output := zerolog.ConsoleWriter{Out: colorable.NewColorableStdout(), TimeFormat: time.RFC3339}
|
|
log.Logger = log.Output(output)
|
|
configLogLevel()
|
|
|
|
log.Info().Str("version", cliArgs.newVersion).Msg("updating Flamenco version")
|
|
|
|
switch {
|
|
case strings.Contains(cliArgs.newVersion, "alpha"), strings.Contains(cliArgs.newVersion, "dev"):
|
|
releaseCycle = "alpha"
|
|
case strings.Contains(cliArgs.newVersion, "beta"):
|
|
releaseCycle = "beta"
|
|
case strings.Contains(cliArgs.newVersion, "rc"):
|
|
releaseCycle = "rc"
|
|
default:
|
|
releaseCycle = "release"
|
|
}
|
|
|
|
var anyFileWasChanged bool
|
|
if cliArgs.updateMakefile {
|
|
anyFileWasChanged = updateMakefile() || anyFileWasChanged
|
|
}
|
|
anyFileWasChanged = updateAddon() || anyFileWasChanged
|
|
anyFileWasChanged = updateMagefiles() || anyFileWasChanged
|
|
|
|
if !anyFileWasChanged {
|
|
log.Warn().Msg("nothing changed")
|
|
os.Exit(42)
|
|
return
|
|
}
|
|
|
|
log.Info().Msg("file replacement done")
|
|
}
|
|
|
|
func parseCliArgs() {
|
|
flag.BoolVar(&cliArgs.quiet, "quiet", false, "Only log warning-level and worse.")
|
|
flag.BoolVar(&cliArgs.debug, "debug", false, "Enable debug-level logging.")
|
|
flag.BoolVar(&cliArgs.trace, "trace", false, "Enable trace-level logging.")
|
|
flag.BoolVar(&cliArgs.updateMakefile, "makefile", false,
|
|
"Also update the Makefile. Normally this application is invoked from the Makefile itself, "+
|
|
"and thus it does not change that file without this CLI argument.")
|
|
|
|
flag.Parse()
|
|
|
|
cliArgs.newVersion = flag.Arg(0)
|
|
if cliArgs.newVersion == "" {
|
|
os.Stderr.WriteString(fmt.Sprintf("Usage: %s [-quiet|-debug|-trace] {new Flamenco version number}\n", os.Args[0]))
|
|
os.Stderr.WriteString("\n")
|
|
flag.PrintDefaults()
|
|
os.Stderr.WriteString("\n")
|
|
os.Stderr.WriteString("This program updates Makefile and some other files to set the new Flamenco version.\n")
|
|
os.Stderr.WriteString("\n")
|
|
os.Exit(47)
|
|
}
|
|
}
|
|
|
|
func configLogLevel() {
|
|
var logLevel zerolog.Level
|
|
switch {
|
|
case cliArgs.trace:
|
|
logLevel = zerolog.TraceLevel
|
|
case cliArgs.debug:
|
|
logLevel = zerolog.DebugLevel
|
|
case cliArgs.quiet:
|
|
logLevel = zerolog.WarnLevel
|
|
default:
|
|
logLevel = zerolog.InfoLevel
|
|
}
|
|
zerolog.SetGlobalLevel(logLevel)
|
|
}
|