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

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

Merged
merged 3 commits into from
May 17, 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
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)
}