1
0
mirror of https://github.com/ko-build/ko.git synced 2024-12-12 08:54:09 +02:00

Resolving #21 issue. Adding ko version and simple release script

This commit is contained in:
cezkuj 2019-04-15 21:07:42 +00:00
parent 3584e2d4d3
commit e8b7dedbe3
4 changed files with 82 additions and 0 deletions

View File

@ -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`

View File

@ -64,6 +64,14 @@ func addKubeCommands(topLevel *cobra.Command) {
},
})
topLevel.AddCommand(&cobra.Command{
Use: "version",
Short: `Print ko version.`,
Run: func(cmd *cobra.Command, args []string) {
version()
},
})
koApplyFlags := []string{}
lo := &LocalOptions{}
bo := &BinaryOptions{}

41
cmd/ko/version.go Normal file
View File

@ -0,0 +1,41 @@
// 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 main
import (
"fmt"
"log"
"os/exec"
)
// provided by govvv in compile-time
var Version string
func version() {
if Version == "" {
hash, err := gitRevParseHead()
if err != nil {
log.Fatalf("error during command execution: %v", err)
}
fmt.Printf("version: %v", string(hash))
} else {
fmt.Printf("version: %v\n", Version)
}
}
func gitRevParseHead() ([]byte, error) {
cmd := exec.Command("git", "rev-parse", "HEAD")
return cmd.Output()
}

30
hack/release.sh Executable file
View File

@ -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 -version $VERSION
git tag $VERSION
git push origin $VERSION