Skip to content

Commit

Permalink
Merge pull request ko-build#25 from cezkuj/ko-version
Browse files Browse the repository at this point in the history
Resolving ko-build#21 issue. Adding ko version and simple release script
  • Loading branch information
imjasonh authored May 17, 2019
2 parents cef9764 + 672e478 commit 8a084cb
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ This flag is still experimental, and feedback is very welcome.
`ko delete` simply passes through to `kubectl delete`. It is exposed purely out
of convenience for cleaning up resources created through `ko apply`.

### `ko version`

`ko version` prints version of ko. For not released binaries it will print hash of latest commit in current git tree.

## With `minikube`

Expand Down
30 changes: 30 additions & 0 deletions hack/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

# Copyright 2019 Google LLC All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Usage:
# hack/release.sh $VERSION
#
# Example:
# hack/release.sh v0.2

VERSION=$1

KO_ROOT="$(cd "$(dirname "$0")" && pwd)/.."

go get github.com/ahmetb/govvv
govvv build -o $KO_ROOT/build/ko $KO_ROOT/cmd/ko -pkg github.com/google/ko/pkg/commands -version $VERSION
git tag $VERSION
git push origin $VERSION
1 change: 1 addition & 0 deletions pkg/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
// https://github.com/google/go-containerregistry/issues/80
func AddKubeCommands(topLevel *cobra.Command) {
addDelete(topLevel)
addVersion(topLevel)
addCreate(topLevel)
addApply(topLevel)
addResolve(topLevel)
Expand Down
51 changes: 51 additions & 0 deletions pkg/commands/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2019 Google LLC All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package commands

import (
"fmt"
"log"
"os"
"os/exec"
"strings"

"github.com/spf13/cobra"
)

// provided by govvv in compile-time
var Version string

// addVersion augments our CLI surface with version.
func addVersion(topLevel *cobra.Command) {
topLevel.AddCommand(&cobra.Command{
Use: "version",
Short: `Print ko version.`,
Run: func(cmd *cobra.Command, args []string) {
version()
},
})
}

func version() {
if Version == "" {
gitDir := fmt.Sprintf("--git-dir=%v/src/github.com/google/ko/.git", os.Getenv("GOPATH"))
hash, err := exec.Command("git", gitDir, "rev-parse", "HEAD").Output()
if err != nil {
log.Fatalf("error during command execution: %v", err)
}
Version = strings.TrimSpace(string(hash))
}
fmt.Printf("version: %v\n", Version)
}

0 comments on commit 8a084cb

Please sign in to comment.