Skip to content

Commit

Permalink
Merge remote-tracking branch 'azure/master' into pkg-token
Browse files Browse the repository at this point in the history
  • Loading branch information
bcho committed Dec 20, 2023
2 parents 8897cff + 7564350 commit 96e6157
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 207 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ jobs:
env:
GO111MODULE: on
steps:
- name: Set up Go 1.21
- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21"
go-version-file: "go.mod"
cache: false
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Build
run: make

Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# NOTE: this is a workaround for codeql go toolchain setup
# ref: https://github.com/github/codeql-action/issues/1842#issuecomment-1704398087
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: "1.21"
go-version-file: "go.mod"
cache: false
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ jobs:
env:
GO111MODULE: on
steps:
- name: Set up Go 1.21
- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21"
go-version-file: "go.mod"
cache: false
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v4

# Read changelog and read versions etc.
- name: Check version is mentioned in Changelog.md
id: changelog_reader
Expand Down
17 changes: 2 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,9 @@ ifeq ($(OS),windows)
BIN = bin/$(OS)_$(ARCH)$(if $(GOARM),v$(GOARM),)/$(TARGET).exe
endif

GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
GIT_HASH := $(shell git rev-parse --verify HEAD)
GIT_TAG := $(shell git describe --tags --exact-match --abbrev=0 2>/dev/null || echo "")
BUILD_TIME ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
PLATFORM := $(OS)/$(ARCH)$(if $(GOARM),v$(GOARM),)

ifdef GIT_TAG
VERSION := $(GIT_TAG)/$(GIT_HASH)
else
VERSION := $(GIT_BRANCH)/$(GIT_HASH)
endif
GIT_TAG := $(shell git describe --tags --exact-match --abbrev=0 2>/dev/null || echo "")

LDFLAGS := -X main.version=$(VERSION) \
-X main.goVersion=$(shell go version | cut -d " " -f 3) \
-X main.buildTime=$(BUILD_TIME) \
-X 'main.platform=$(PLATFORM)'
LDFLAGS := -X main.gitTag=$(GIT_TAG)

all: $(TARGET)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/Azure/kubelogin

go 1.18
go 1.21.3

require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.8.0
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func main() {
pflag.CommandLine.AddGoFlag(flag.CommandLine.Lookup("v"))
pflag.CommandLine.AddGoFlag(flag.CommandLine.Lookup("logtostderr"))
_ = pflag.CommandLine.Set("logtostderr", "true")
root := cmd.NewRootCmd(v.String())
root := cmd.NewRootCmd(loadVersion().String())
if err := root.Execute(); err != nil {
os.Exit(1)
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
47 changes: 0 additions & 47 deletions pkg/token/options.go

This file was deleted.

41 changes: 0 additions & 41 deletions pkg/token/provider.go

This file was deleted.

74 changes: 0 additions & 74 deletions pkg/token/provider_test.go

This file was deleted.

93 changes: 78 additions & 15 deletions version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package main

import "fmt"
import (
"fmt"
"runtime"
"runtime/debug"
)

// gitTag provides the git tag used to build this binary.
// This is set via ldflags at build time, which normally set by the release pipeline.
// For go install binary, this value stays empty.
var gitTag string

type Version struct {
Version string
Expand All @@ -9,23 +18,77 @@ type Version struct {
Platform string
}

var (
v Version
version string
goVersion string
buildTime string
platform string
)
func loadVersion() Version {
rv := Version{
Version: "unknown",
GoVersion: "unknown",
BuildTime: "unknown",
Platform: runtime.GOOS + "/" + runtime.GOARCH,
}
if gitTag != "" {
rv.Version = gitTag
}

buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return rv
}

rv.GoVersion = buildInfo.GoVersion

var (
modified bool
revision string
buildTime string
)
for _, s := range buildInfo.Settings {
if s.Value == "" {
continue
}

func init() {
v = Version{
Version: version,
GoVersion: goVersion,
BuildTime: buildTime,
Platform: platform,
switch s.Key {
case "vcs.revision":
revision = s.Value
case "vcs.modified":
modified = s.Value == "true"
case "vcs.time":
buildTime = s.Value
}
}

// in Go install mode, this is a known issue that vcs information will not be available.
// ref: https://github.com/golang/go/issues/51279
// Fallback to use module version and stop here as vcs information is incomplete.
if revision == "" {
if buildInfo.Main.Version != "" {
// fallback to use module version (legacy usage)
rv.Version = buildInfo.Main.Version
}

return rv
}

if modified {
revision += "-dirty"
}
if gitTag != "" {
revision = gitTag + "/" + revision
}
rv.Version = revision

if buildTime != "" {
rv.BuildTime = buildTime
}

return rv
}

func (ver Version) String() string {
return fmt.Sprintf("\ngit hash: %s\nGo version: %s\nBuild time: %s\nPlatform: %s", v.Version, v.GoVersion, v.BuildTime, v.Platform)
return fmt.Sprintf(
"\ngit hash: %s\nGo version: %s\nBuild time: %s\nPlatform: %s",
ver.Version,
ver.GoVersion,
ver.BuildTime,
ver.Platform,
)
}
Loading

0 comments on commit 96e6157

Please sign in to comment.