Sybren A. Stüvel
c1a728dc2f
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.
66 lines
2.5 KiB
Go
66 lines
2.5 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
const addonVersionFile = "addon/flamenco/__init__.py"
|
|
|
|
// updateAddon changes the version number in the Blender add-on.
|
|
// Returns whether the file actually changed.
|
|
func updateAddon() bool {
|
|
// The add-on needs a (x, y, z) tuple as version, and doesn't support suffixes
|
|
// like `-dev0` or `-beta3`.
|
|
splitOnDash := strings.SplitN(cliArgs.newVersion, "-", 2)
|
|
versionWithoutSuffix := splitOnDash[0]
|
|
|
|
var warning string
|
|
if len(splitOnDash) >= 2 {
|
|
log.Warn().Msg("versions of form `x.y.z-something` will put a warning in the bl_info about the `-something`")
|
|
warning = fmt.Sprintf("This is version %s of the add-on, which is not a stable release", cliArgs.newVersion)
|
|
}
|
|
|
|
versionParts := strings.Split(versionWithoutSuffix, ".")
|
|
var versionTuple string
|
|
switch len(versionParts) {
|
|
case 0:
|
|
log.Fatal().Str("versionWithoutSuffix", versionWithoutSuffix).Msg("no dot-separated version number found")
|
|
case 1:
|
|
log.Warn().Strs("versionParts", versionParts).Msg("only a major version found, may be the wrong syntax")
|
|
versionTuple = fmt.Sprintf("(%s, 0)", versionParts[0])
|
|
case 2:
|
|
log.Debug().Strs("versionParts", versionParts).Msg("major.minor version found, this is expected")
|
|
versionTuple = fmt.Sprintf("(%s, %s)", versionParts[0], versionParts[1])
|
|
case 3:
|
|
log.Debug().Strs("versionParts", versionParts).Msg("major.minor.micro version found, this is expected")
|
|
versionTuple = fmt.Sprintf("(%s, %s, %s)", versionParts[0], versionParts[1], versionParts[2])
|
|
default:
|
|
log.Warn().Strs("versionParts", versionParts).Msg("more than three (major, minor, micro) version parts found, using only the first three")
|
|
versionTuple = fmt.Sprintf("(%s, %s, %s)", versionParts[0], versionParts[1], versionParts[2])
|
|
}
|
|
|
|
var blinfoOpened, blinfoClosed bool
|
|
replacer := func(line string) string {
|
|
switch {
|
|
case !blinfoOpened && strings.HasPrefix(line, "bl_info = {"):
|
|
blinfoOpened = true
|
|
case blinfoOpened && strings.HasPrefix(line, "}"):
|
|
blinfoClosed = true
|
|
case blinfoOpened && !blinfoClosed && strings.HasPrefix(line, " \"version\":"):
|
|
return fmt.Sprintf(" \"version\": %s,", versionTuple)
|
|
case blinfoOpened && !blinfoClosed && strings.HasPrefix(line, " \"warning\":"):
|
|
return fmt.Sprintf(" \"warning\": %q,", warning)
|
|
}
|
|
return line
|
|
}
|
|
|
|
fileWasChanged, err := updateLines(addonVersionFile, replacer)
|
|
if err != nil {
|
|
log.Fatal().Err(err).Msg("error updating add-on")
|
|
}
|
|
return fileWasChanged
|
|
}
|