scripts: Add git commit to builds
This commit is contained in:
parent
d4e8321a80
commit
3b32ba9f11
|
@ -27,7 +27,9 @@ func main() {
|
|||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
}
|
||||
|
||||
log.Printf("Packer Version: %s %s", packer.Version, packer.VersionPrerelease)
|
||||
log.Printf(
|
||||
"Packer Version: %s %s %s",
|
||||
packer.Version, packer.VersionPrerelease, packer.GitCommit)
|
||||
log.Printf("Packer Target OS/Arch: %s %s", runtime.GOOS, runtime.GOARCH)
|
||||
|
||||
config, err := loadConfig()
|
||||
|
|
|
@ -5,6 +5,10 @@ import (
|
|||
"fmt"
|
||||
)
|
||||
|
||||
// The git commit that is being compiled. This will be filled in by the
|
||||
// compiler for source builds.
|
||||
var GitCommit string
|
||||
|
||||
// The version of packer.
|
||||
const Version = "0.1.6"
|
||||
|
||||
|
@ -29,6 +33,10 @@ func (versionCommand) Run(env Environment, args []string) int {
|
|||
fmt.Fprintf(&versionString, ".%s", VersionPrerelease)
|
||||
}
|
||||
|
||||
if GitCommit != "" {
|
||||
fmt.Fprintf(&versionString, " (%s)", GitCommit)
|
||||
}
|
||||
|
||||
env.Ui().Say(versionString.String())
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# This script only builds the application from source.
|
||||
set -e
|
||||
|
||||
NO_COLOR="\x1b[0m"
|
||||
|
@ -14,13 +16,23 @@ DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
|
|||
# Change into that directory
|
||||
cd $DIR
|
||||
|
||||
# Get the git commit
|
||||
GIT_COMMIT=$(git rev-parse --short HEAD)
|
||||
GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES")
|
||||
|
||||
# Compile the main Packer app
|
||||
echo -e "${OK_COLOR}--> Compiling Packer${NO_COLOR}"
|
||||
go build -v -o bin/packer .
|
||||
go build \
|
||||
-ldflags "-X github.com/mitchellh/packer/packer.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \
|
||||
-v \
|
||||
-o bin/packer .
|
||||
|
||||
# Go over each plugin and build it
|
||||
for PLUGIN in $(find ./plugin -mindepth 1 -maxdepth 1 -type d); do
|
||||
PLUGIN_NAME=$(basename ${PLUGIN})
|
||||
echo -e "${OK_COLOR}--> Compiling Plugin: ${PLUGIN_NAME}${NO_COLOR}"
|
||||
go build -v -o bin/packer-${PLUGIN_NAME} ${PLUGIN}
|
||||
go build \
|
||||
-ldflags "-X github.com/mitchellh/packer/packer.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \
|
||||
-v \
|
||||
-o bin/packer-${PLUGIN_NAME} ${PLUGIN}
|
||||
done
|
||||
|
|
Loading…
Reference in New Issue