Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added date and commit SHA to the version command #1047

Merged
merged 1 commit into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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<String>)
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
},
}
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 3 additions & 1 deletion tools/travis/build_tag_releases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down