Skip to content

Commit

Permalink
Resolving ko-build#21 issue. Adding ko version and simple release script
Browse files Browse the repository at this point in the history
  • Loading branch information
cezkuj committed Apr 19, 2019
1 parent 3584e2d commit e8b7ded
Show file tree
Hide file tree
Showing 4 changed files with 82 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
8 changes: 8 additions & 0 deletions cmd/ko/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
41 changes: 41 additions & 0 deletions cmd/ko/version.go
Original file line number Diff line number Diff line change
@@ -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 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 -version $VERSION
git tag $VERSION
git push origin $VERSION

0 comments on commit e8b7ded

Please sign in to comment.