diff --git a/.travis.yml b/.travis.yml index ef5aadd31..06d551b8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,7 +52,7 @@ before_deploy: export GIT_TAG=$TRAVIS_TAG; export TAG=true; fi -- ./gradlew --console=plain releaseBinaries -PpackageVersion=$GIT_TAG +- ./gradlew --console=plain releaseBinaries -PpackageVersion=$GIT_TAG -PgitCommit=$(git rev-parse HEAD) -PbuildDate=$(date -u +"%Y-%m-%dT%H:%M:%SZ") - "./tools/travis/build_tag_releases.sh $build_file_name $GIT_TAG" - export RELEASE_PKG_FILE="$(cd "$TRAVIS_BUILD_DIR/release" && ls ${zip_file_name}-*.tgz ${zip_file_name}-*.zip)" - echo "Deploying $RELEASE_PKG_FILE to GitHub releases." diff --git a/Makefile b/Makefile index 844c49f7d..bf632b01e 100644 --- a/Makefile +++ b/Makefile @@ -24,11 +24,13 @@ VERSION=latest BUILD=`git rev-parse HEAD` +BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` + deps: @echo "Installing dependencies" godep restore -v -LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Build=`git rev-parse HEAD` " +LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.GitCommit=${BUILD} -X main.BuildDate=${BUILD_DATE} -X main.Build=`git rev-parse HEAD` " test: deps @echo "Testing" diff --git a/build.gradle b/build.gradle index bd194b984..b8c4fdbff 100644 --- a/build.gradle +++ b/build.gradle @@ -185,6 +185,12 @@ OpenWhiskPlatform.zipFileName = project.ext.packageVersion = rootProject.findProperty('packageVersion') ?: 'latest' +project.ext.gitCommit = + rootProject.findProperty('gitCommit') ?: 'unset' + +project.ext.buildDate = + rootProject.findProperty('buildDate') ?: 'unset' + String buildFileName = System.env['build_file_name'] ?: (rootProject.findProperty('buildFileName') ?: 'wskdeploy') @@ -237,7 +243,7 @@ goBuild { // WARNING: The single quotes are intentional! The gogradle plugin will // parse the command with the GString engine at execution time. go(['build', - '-ldflags', "-X main.Version=${packageVersion}" as String, + '-ldflags', "-X main.Version=${packageVersion} -X main.GitCommit=${gitCommit} -X main.BuildDate=${buildDate}" as String, '-o', './build/${GOOS}-${GOARCH}/'+buildFileName+'${GOEXE}', golang.packagePath ] as List) } diff --git a/cmd/version.go b/cmd/version.go index 2d4d71057..f8775aca5 100755 --- a/cmd/version.go +++ b/cmd/version.go @@ -38,5 +38,9 @@ var versionCmd = &cobra.Command{ // Note: no need to translate the following string // TODO(#767) - Flags.CliVersion are not set during build fmt.Sprintf("wskdeploy version: %s", utils.Flags.CliVersion)) + wskprint.PrintlnOpenWhiskOutput( + fmt.Sprintf("wskdeploy git commit: %s", utils.Flags.CliGitCommit)) + wskprint.PrintlnOpenWhiskOutput( + fmt.Sprintf("wskdeploy build date: %s", utils.Flags.CliBuildDate)) }, } diff --git a/main.go b/main.go index 54a809302..156ce5f81 100644 --- a/main.go +++ b/main.go @@ -28,9 +28,13 @@ func main() { var ( //Version ...The Version of the tool - Version = "unset" + Version = "unset" + GitCommit = "unset" + BuildDate = "unset" ) func init() { utils.Flags.CliVersion = Version + utils.Flags.CliGitCommit = GitCommit + utils.Flags.CliBuildDate = BuildDate } diff --git a/tools/travis/build_tag_releases.sh b/tools/travis/build_tag_releases.sh index 62bd52097..074dd27f9 100755 --- a/tools/travis/build_tag_releases.sh +++ b/tools/travis/build_tag_releases.sh @@ -20,6 +20,8 @@ declare -a os_list=("linux" "darwin" "windows") declare -a arc_list=("amd64" "386") build_file_name=${1:-"wskdeploy"} build_version=${2:-"$TRAVIS_TAG"} +gitCommit=$(git rev-parse HEAD) +buildDate=$(date -u +"%Y-%m-%dT%H:%M:%SZ") for os in "${os_list[@]}" do @@ -34,7 +36,7 @@ do os_name="mac" fi cd $TRAVIS_BUILD_DIR - GOOS=$os GOARCH=$arc go build -ldflags "-X main.Version=$build_version" -o build/$os/$wskdeploy + GOOS=$os GOARCH=$arc go build -ldflags "-X main.Version=$build_version -X main.GitCommit=$gitCommit -X main.BuildDate=$buildDate" -o build/$os/$wskdeploy cd build/$os if [[ "$os" == "linux" ]]; then tar -czvf "$TRAVIS_BUILD_DIR/$build_file_name-$TRAVIS_TAG-$os_name-$arc.tgz" $wskdeploy diff --git a/utils/flags.go b/utils/flags.go index a860850fc..3025bf64e 100644 --- a/utils/flags.go +++ b/utils/flags.go @@ -29,6 +29,8 @@ type WskDeployFlags struct { ApiVersion string // OpenWhisk version CfgFile string CliVersion string + CliGitCommit string + CliBuildDate string ProjectPath string DeploymentPath string ManifestPath string