Skip to content

Commit

Permalink
Merge branch 'main' into enable-krew-automation
Browse files Browse the repository at this point in the history
  • Loading branch information
garethjevans authored Oct 25, 2022
2 parents 5c7439d + fe05106 commit 201d4fb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: release
on:
push:
tags:
- 'v*.*.*'
release:
types: [published]

jobs:
goreleaser:
runs-on: ubuntu-latest
Expand All @@ -11,17 +11,20 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.18

- name: GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update new version in krew-index
uses: rajatjindal/[email protected]
VERSION: ${{ github.event.release.tag_name }}

- name: Update new version in krew-index
uses: rajatjindal/[email protected]
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ builds:
- id: kubectl-permissions
main: ./cmd/kubectl-permissions.go
binary: kubectl-permissions
ldflags:
- -X github.com/garethjevans/permissions/pkg/version.Version={{.Version}}
env:
- CGO_ENABLED=0
goos:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build:
go build -o kubectl-permissions cmd/kubectl-permissions.go
go build -o kubectl-permissions -trimpath -ldflags "-X github.com/garethjevans/permissions/pkg/version.Version=dev" cmd/kubectl-permissions.go

install: build
sudo cp -f kubectl-permissions /usr/local/bin
Expand Down
15 changes: 14 additions & 1 deletion pkg/cmd/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"github.com/garethjevans/permissions/pkg/asciitree"
"github.com/garethjevans/permissions/pkg/version"
"github.com/kyokomi/emoji/v2"
"github.com/mgutz/ansi"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -38,6 +39,8 @@ type PermissionsOptions struct {
configFlags *genericclioptions.ConfigFlags
genericclioptions.IOStreams

Version bool

Cmd *cobra.Command
Args []string
}
Expand All @@ -59,7 +62,7 @@ func NewCmdPermissions(streams genericclioptions.IOStreams) *cobra.Command {
Short: "View the permissions inherited by the specified service account",
Example: fmt.Sprintf(permissionsExample, binaryName),
SilenceUsage: true,
Args: cobra.ExactArgs(1),
Args: cobra.MaximumNArgs(1),
RunE: func(c *cobra.Command, args []string) error {
o.Args = args
o.Cmd = c
Expand All @@ -70,6 +73,8 @@ func NewCmdPermissions(streams genericclioptions.IOStreams) *cobra.Command {
},
}

cmd.Flags().BoolVarP(&o.Version, "version", "v", false, "Display the version of the permissions plugin")

o.configFlags.AddFlags(cmd.Flags())

return cmd
Expand All @@ -78,6 +83,14 @@ func NewCmdPermissions(streams genericclioptions.IOStreams) *cobra.Command {
// Run lists all available namespaces on a user's KUBECONFIG or updates the
// current context based on a provided namespace.
func (o *PermissionsOptions) Run() error {
if o.Version {
fmt.Println(version.Version)
return nil
}

if len(o.Args) != 1 {
panic(fmt.Sprintf("Error: accepts 1 arg(s), received %d", len(o.Args)))
}

var err error
config, err := o.configFlags.ToRESTConfig()
Expand Down
3 changes: 3 additions & 0 deletions pkg/version/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package version

var Version string

0 comments on commit 201d4fb

Please sign in to comment.