Sybren A. Stüvel c1a728dc2f Version updates via Makefile
Flamenco now no longer uses the Git tags + hash for the application
version, but an explicit `VERSION` variable in the `Makefile`.

After changing the `VERSION` variable in the `Makefile`, run
`make update-version`.

Not every part of Flamenco looks at this variable, though. Most
importantly: the Blender add-on needs special handling, because that
doesn't just take a version string but a tuple of integers. Running
`make update-version` updates the add-on's `bl_info` dict with the new
version. If the version has any `-blabla` suffix (like `3.0-beta0`) it
will also set the `warning` field to explain that it's not a stable
release.
2022-07-25 16:08:07 +02:00

88 lines
2.4 KiB
Go

package main
// SPDX-License-Identifier: GPL-3.0-or-later
import (
"flag"
"fmt"
"os"
"time"
"github.com/mattn/go-colorable"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
var cliArgs struct {
// Logging level flags.
quiet, debug, trace bool
newVersion string
updateMakefile bool
}
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")
var anyFileWasChanged bool
if cliArgs.updateMakefile {
anyFileWasChanged = anyFileWasChanged || updateMakefile()
}
anyFileWasChanged = anyFileWasChanged || updateAddon()
if !anyFileWasChanged {
log.Warn().Msg("nothing changed")
os.Exit(42)
return
}
// Lot the result & some easy-to-copy Git commands:
commitMsg := fmt.Sprintf("Bumped version to %s", cliArgs.newVersion)
tagMsg := fmt.Sprintf("Tagged version %s", cliArgs.newVersion)
log.Info().Msg("file replacement done, commit with:")
log.Info().Msgf("git commit -m %q %s %s", commitMsg, makefileFile, addonVersionFile)
log.Info().Msgf("git tag -a -m %q v%s", tagMsg, cliArgs.newVersion)
}
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)
}