Skip to content

Commit

Permalink
multi: update version string system and build metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ukane-philemon authored Apr 27, 2022
1 parent 105d3e7 commit 83ccb74
Show file tree
Hide file tree
Showing 15 changed files with 672 additions and 300 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# <img src="docs/images/logo_wide_v1.svg" alt="DCRDEX" width="250">

[![Build Status](https://github.com/decred/dcrdex/workflows/Build%20and%20Test/badge.svg)](https://github.com/decred/dcrdex/actions)
[![ISC License](https://img.shields.io/badge/license-Blue_Oak-007788.svg)](http://copyfree.org)
[![ISC License](https://img.shields.io/badge/license-Blue_Oak-007788.svg)](https://blueoakcouncil.org/license/1.0.0)
[![GoDoc](https://img.shields.io/badge/go.dev-reference-blue.svg?logo=go&logoColor=lightblue)](https://pkg.go.dev/decred.org/dcrdex)

## What is DEX?
Expand Down
3 changes: 1 addition & 2 deletions client/cmd/dexc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"runtime"

"decred.org/dcrdex/client/asset"
"decred.org/dcrdex/client/cmd/dexc/version"
"decred.org/dcrdex/dex"
"github.com/decred/dcrd/dcrutil/v4"
"github.com/decred/slog"
Expand Down Expand Up @@ -136,7 +135,7 @@ func configure() (*Config, error) {
// Show the version and exit if the version flag was specified.
if preCfg.ShowVer {
fmt.Printf("%s version %s (Go version %s %s/%s)\n",
version.AppName, version.Version(), runtime.Version(), runtime.GOOS, runtime.GOARCH)
appName, Version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
os.Exit(0)
}

Expand Down
3 changes: 1 addition & 2 deletions client/cmd/dexc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
_ "decred.org/dcrdex/client/asset/doge" // register doge asset
_ "decred.org/dcrdex/client/asset/ltc" // register ltc asset

"decred.org/dcrdex/client/cmd/dexc/version"
"decred.org/dcrdex/client/core"
"decred.org/dcrdex/client/rpcserver"
"decred.org/dcrdex/client/webserver"
Expand Down Expand Up @@ -76,7 +75,7 @@ func mainCore() error {
}
logMaker := initLogging(cfg.DebugLevel, utc)
log = logMaker.Logger("DEXC")
log.Infof("%s version %v (Go version %s)", version.AppName, version.Version(), runtime.Version())
log.Infof("%s version %v (Go version %s)", appName, Version, runtime.Version())
if utc {
log.Infof("Logging with UTC time stamps. Current local time is %v",
time.Now().Local().Format("15:04:05 MST"))
Expand Down
49 changes: 49 additions & 0 deletions client/cmd/dexc/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// This code is available on the terms of the project LICENSE.md file,
// also available online at https://blueoakcouncil.org/license/1.0.0.

package main

import (
"decred.org/dcrdex/dex/version"
)

const (
// appName defines the application name.
appName string = "dexc"
)

var (
// Note for maintainers:
//
// The expected process for setting the version in releases is as follows:
// - Create a release branch of the form 'release-vMAJOR.MINOR'
// - Modify the Version variable below on that branch to:
// - Remove the pre-release portion
// - Set the build metadata to 'release'
// - Example: 'Version = "0.5.0+release"'
// - Update the Version variable below on the master branch to the next
// expected version while retaining a pre-release of 'pre'
//
// These steps ensure that building from source produces versions that are
// distinct from reproducible builds that override the Version via linker
// flags.

// Version is the application version per the semantic versioning 2.0.0 spec
// (https://semver.org/).
//
// It is defined as a variable so it can be overridden during the build
// process with:
// '-ldflags "-X main.Version=fullsemver"'
// if needed.
//
// It MUST be a full semantic version per the semantic versioning spec or
// the package will panic at runtime. Of particular note is the pre-release
// and build metadata portions MUST only contain characters from
// semanticAlphabet.
// NOTE: The Version string is overridden on init.
Version = "0.5.0-pre"
)

func init() {
Version = version.Parse(Version)
}
97 changes: 0 additions & 97 deletions client/cmd/dexc/version/version.go

This file was deleted.

2 changes: 1 addition & 1 deletion client/cmd/dexcctl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func configure() (*config, []string, bool, error) {
// Show the version and exit if the version flag was specified.
if cfg.ShowVersion {
fmt.Printf("%s version %s (Go version %s %s/%s)\n", appName,
version(), runtime.Version(), runtime.GOOS, runtime.GOARCH)
Version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
return nil, nil, stop, nil
}

Expand Down
116 changes: 34 additions & 82 deletions client/cmd/dexcctl/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,94 +4,46 @@
package main

import (
"bytes"
"fmt"
"strings"
"decred.org/dcrdex/dex/version"
)

const (
// semanticAlphabet defines the allowed characters for the pre-release
// portion of a semantic version string.
semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"

// semanticBuildAlphabet defines the allowed characters for the build
// portion of a semantic version string.
semanticBuildAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-."
)

// These constants define the application version and follow the semantic
// versioning 2.0.0 spec (http://semver.org/).
const (
appName string = "dexcctl"
appMajor uint = 0
appMinor uint = 5
appPatch uint = 0
// appName is the application name.
appName string = "dexcctl"
)

// go build -v -ldflags "-X decred.org/dcrdex/client/cmd/dexcctl/main.appPreRelease= -X decred.org/dcrdex/client/cmd/dexcctl/main.appBuild=$(git rev-parse --short HEAD)"
var (
// appPreRelease is defined as a variable so it can be overridden during the
// build process. It MUST only contain characters from semanticAlphabet per
// the semantic versioning spec.
appPreRelease = "pre"

// appBuild is defined as a variable so it can be overridden during the
// build process. It MUST only contain characters from semanticBuildAlphabet
// per the semantic versioning spec.
appBuild = "dev"
// Note for maintainers:
//
// The expected process for setting the version in releases is as follows:
// - Create a release branch of the form 'release-vMAJOR.MINOR'
// - Modify the Version variable below on that branch to:
// - Remove the pre-release portion
// - Set the build metadata to 'release'
// - Example: 'Version = "0.5.0+release"'
// - Update the Version variable below on the master branch to the next
// expected version while retaining a pre-release of 'pre'
//
// These steps ensure that building from source produces versions that are
// distinct from reproducible builds that override the Version via linker
// flags.

// Version is the application version per the semantic versioning 2.0.0 spec
// (https://semver.org/).
//
// It is defined as a variable so it can be overridden during the build
// process with:
// '-ldflags "-X main.Version=fullsemver"'
// if needed.
//
// It MUST be a full semantic version per the semantic versioning spec or
// the package will panic at runtime. Of particular note is the pre-release
// and build metadata portions MUST only contain characters from
// semanticAlphabet.
// NOTE: The Version string is overridden on init.
Version = "0.5.0-pre"
)

// version returns the application version as a properly formed string per the
// semantic versioning 2.0.0 spec (http://semver.org/).
func version() string {
// Start with the major, minor, and patch versions.
version := fmt.Sprintf("%d.%d.%d", appMajor, appMinor, appPatch)

// Append pre-release version if there is one. The hyphen called for
// by the semantic versioning spec is automatically appended and should
// not be contained in the pre-release string. The pre-release version
// is not appended if it contains invalid characters.
preRelease := normalizePreRelString(appPreRelease)
if preRelease != "" {
version = fmt.Sprintf("%s-%s", version, preRelease)
}

// Append build metadata if there is any. The plus called for
// by the semantic versioning spec is automatically appended and should
// not be contained in the build metadata string. The build metadata
// string is not appended if it contains invalid characters.
build := normalizeBuildString(appBuild)
if build != "" {
version = fmt.Sprintf("%s+%s", version, build)
}

return version
}

// normalizeSemString returns the passed string stripped of all characters
// which are not valid according to the provided semantic versioning alphabet.
func normalizeSemString(str, alphabet string) string {
var result bytes.Buffer
for _, r := range str {
if strings.ContainsRune(alphabet, r) {
result.WriteRune(r)
}
}
return result.String()
}

// normalizePreRelString returns the passed string stripped of all characters
// which are not valid according to the semantic versioning guidelines for
// pre-release strings. In particular they MUST only contain characters in
// semanticAlphabet.
func normalizePreRelString(str string) string {
return normalizeSemString(str, semanticAlphabet)
}

// normalizeBuildString returns the passed string stripped of all characters
// which are not valid according to the semantic versioning guidelines for build
// metadata strings. In particular they MUST only contain characters in
// semanticBuildAlphabet.
func normalizeBuildString(str string) string {
return normalizeSemString(str, semanticBuildAlphabet)
func init() {
Version = version.Parse(Version)
}
Loading

0 comments on commit 83ccb74

Please sign in to comment.