Move version to its own package. (#3460)
This commit is contained in:
parent
864be9d991
commit
728c496370
8
Makefile
8
Makefile
@ -16,8 +16,8 @@ bin: deps
|
|||||||
@GO15VENDOREXPERIMENT=1 sh -c "$(CURDIR)/scripts/build.sh"
|
@GO15VENDOREXPERIMENT=1 sh -c "$(CURDIR)/scripts/build.sh"
|
||||||
|
|
||||||
releasebin: deps
|
releasebin: deps
|
||||||
@grep 'const VersionPrerelease = "dev"' version.go > /dev/null ; if [ $$? -eq 0 ]; then \
|
@grep 'const VersionPrerelease = "dev"' version/version.go > /dev/null ; if [ $$? -eq 0 ]; then \
|
||||||
echo "ERROR: You must remove prerelease tags from version.go prior to release."; \
|
echo "ERROR: You must remove prerelease tags from version/version.go prior to release."; \
|
||||||
exit 1; \
|
exit 1; \
|
||||||
fi
|
fi
|
||||||
@GO15VENDOREXPERIMENT=1 sh -c "$(CURDIR)/scripts/build.sh"
|
@GO15VENDOREXPERIMENT=1 sh -c "$(CURDIR)/scripts/build.sh"
|
||||||
@ -36,8 +36,8 @@ deps:
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
dev: deps
|
dev: deps
|
||||||
@grep 'const VersionPrerelease = ""' version.go > /dev/null ; if [ $$? -eq 0 ]; then \
|
@grep 'const VersionPrerelease = ""' version/version.go > /dev/null ; if [ $$? -eq 0 ]; then \
|
||||||
echo "ERROR: You must add prerelease tags to version.go prior to making a dev build."; \
|
echo "ERROR: You must add prerelease tags to version/version.go prior to making a dev build."; \
|
||||||
exit 1; \
|
exit 1; \
|
||||||
fi
|
fi
|
||||||
@PACKER_DEV=1 GO15VENDOREXPERIMENT=1 sh -c "$(CURDIR)/scripts/build.sh"
|
@PACKER_DEV=1 GO15VENDOREXPERIMENT=1 sh -c "$(CURDIR)/scripts/build.sh"
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/hashicorp/go-checkpoint"
|
"github.com/hashicorp/go-checkpoint"
|
||||||
"github.com/mitchellh/packer/command"
|
"github.com/mitchellh/packer/command"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
|
packerVersion "github.com/mitchellh/packer/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -33,9 +34,9 @@ func runCheckpoint(c *config) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
version := Version
|
version := packerVersion.Version
|
||||||
if VersionPrerelease != "" {
|
if packerVersion.VersionPrerelease != "" {
|
||||||
version += fmt.Sprintf("-%s", VersionPrerelease)
|
version += fmt.Sprintf("-%s", packerVersion.VersionPrerelease)
|
||||||
}
|
}
|
||||||
|
|
||||||
signaturePath := filepath.Join(configDir, "checkpoint_signature")
|
signaturePath := filepath.Join(configDir, "checkpoint_signature")
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
"github.com/mitchellh/packer/command"
|
"github.com/mitchellh/packer/command"
|
||||||
|
"github.com/mitchellh/packer/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Commands is the mapping of all the available Terraform commands.
|
// Commands is the mapping of all the available Terraform commands.
|
||||||
@ -53,9 +54,9 @@ func init() {
|
|||||||
"version": func() (cli.Command, error) {
|
"version": func() (cli.Command, error) {
|
||||||
return &command.VersionCommand{
|
return &command.VersionCommand{
|
||||||
Meta: *CommandMeta,
|
Meta: *CommandMeta,
|
||||||
Revision: GitCommit,
|
Revision: version.GitCommit,
|
||||||
Version: Version,
|
Version: version.Version,
|
||||||
VersionPrerelease: VersionPrerelease,
|
VersionPrerelease: version.VersionPrerelease,
|
||||||
CheckFunc: commandVersionCheck,
|
CheckFunc: commandVersionCheck,
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
|
9
main.go
9
main.go
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/mitchellh/packer/command"
|
"github.com/mitchellh/packer/command"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
"github.com/mitchellh/packer/packer/plugin"
|
"github.com/mitchellh/packer/packer/plugin"
|
||||||
|
"github.com/mitchellh/packer/version"
|
||||||
"github.com/mitchellh/panicwrap"
|
"github.com/mitchellh/panicwrap"
|
||||||
"github.com/mitchellh/prefixedio"
|
"github.com/mitchellh/prefixedio"
|
||||||
)
|
)
|
||||||
@ -105,9 +106,7 @@ func wrappedMain() int {
|
|||||||
|
|
||||||
log.SetOutput(os.Stderr)
|
log.SetOutput(os.Stderr)
|
||||||
|
|
||||||
log.Printf(
|
log.Printf("[INFO] Packer version: %s", version.FormattedVersion())
|
||||||
"[INFO] Packer version: %s %s %s",
|
|
||||||
Version, VersionPrerelease, GitCommit)
|
|
||||||
log.Printf("Packer Target OS/Arch: %s %s", runtime.GOOS, runtime.GOARCH)
|
log.Printf("Packer Target OS/Arch: %s %s", runtime.GOOS, runtime.GOARCH)
|
||||||
log.Printf("Built with Go Version: %s", runtime.Version())
|
log.Printf("Built with Go Version: %s", runtime.Version())
|
||||||
|
|
||||||
@ -175,7 +174,7 @@ func wrappedMain() int {
|
|||||||
PostProcessor: config.LoadPostProcessor,
|
PostProcessor: config.LoadPostProcessor,
|
||||||
Provisioner: config.LoadProvisioner,
|
Provisioner: config.LoadProvisioner,
|
||||||
},
|
},
|
||||||
Version: Version,
|
Version: version.Version,
|
||||||
},
|
},
|
||||||
Cache: cache,
|
Cache: cache,
|
||||||
Ui: ui,
|
Ui: ui,
|
||||||
@ -188,7 +187,7 @@ func wrappedMain() int {
|
|||||||
Commands: Commands,
|
Commands: Commands,
|
||||||
HelpFunc: excludeHelpFunc(Commands, []string{"plugin"}),
|
HelpFunc: excludeHelpFunc(Commands, []string{"plugin"}),
|
||||||
HelpWriter: os.Stdout,
|
HelpWriter: os.Stdout,
|
||||||
Version: Version,
|
Version: version.Version,
|
||||||
}
|
}
|
||||||
|
|
||||||
exitCode, err := cli.Run()
|
exitCode, err := cli.Run()
|
||||||
|
@ -37,7 +37,7 @@ set +e
|
|||||||
gox \
|
gox \
|
||||||
-os="${XC_OS}" \
|
-os="${XC_OS}" \
|
||||||
-arch="${XC_ARCH}" \
|
-arch="${XC_ARCH}" \
|
||||||
-ldflags "-X main.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \
|
-ldflags "-X github.com/mitchellh/packer/version.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \
|
||||||
-output "pkg/{{.OS}}_{{.Arch}}/packer" \
|
-output "pkg/{{.OS}}_{{.Arch}}/packer" \
|
||||||
.
|
.
|
||||||
set -e
|
set -e
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
package main
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
// The git commit that was compiled. This will be filled in by the compiler.
|
// The git commit that was compiled. This will be filled in by the compiler.
|
||||||
var GitCommit string
|
var GitCommit string
|
||||||
@ -10,3 +15,17 @@ const Version = "0.10.1"
|
|||||||
// then it means that it is a final release. Otherwise, this is a pre-release
|
// then it means that it is a final release. Otherwise, this is a pre-release
|
||||||
// such as "dev" (in development), "beta", "rc1", etc.
|
// such as "dev" (in development), "beta", "rc1", etc.
|
||||||
const VersionPrerelease = "dev"
|
const VersionPrerelease = "dev"
|
||||||
|
|
||||||
|
func FormattedVersion() string {
|
||||||
|
var versionString bytes.Buffer
|
||||||
|
fmt.Fprintf(&versionString, "%s", Version)
|
||||||
|
if VersionPrerelease != "" {
|
||||||
|
fmt.Fprintf(&versionString, ".%s", VersionPrerelease)
|
||||||
|
|
||||||
|
if GitCommit != "" {
|
||||||
|
fmt.Fprintf(&versionString, " (%s)", GitCommit)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return versionString.String()
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user