Skip to content

Commit

Permalink
update go version and add support for comp debugging
Browse files Browse the repository at this point in the history
updated to go 1.22
added completion debugging support by setting BASH_COMP_DEBUG_FILE
fixed tooling install
cache update
  • Loading branch information
leucos committed Jun 26, 2024
1 parent ca8a926 commit bf9dc7b
Show file tree
Hide file tree
Showing 9 changed files with 351 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
with:
fetch-depth: 0 # See: https://goreleaser.com/ci/actions/

- name: Set up Go 1.19
- name: Set up Go 1.22
uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.22
id: go

- name: Run GoReleaser
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/update_cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
- name: Set up NodeJS
uses: actions/setup-node@v1

- name: Set up Go 1.19
- name: Set up Go 1.22
uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.22
id: go

- name: Build binary
Expand Down
39 changes: 11 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,33 +95,17 @@ e2e: bin ; $(info $(M) runs end2end integration tests (very long)…) @ ## inst
$Q echo starting docker
$Q docker run -ti --name binenv-e2e -e GITHUB_TOKEN --rm -v $(pwd)/distributions/distributions.yaml:/home/binenv/.config/binenv/distributions.yaml binenv-e2e

# Tools

$(BIN):
@mkdir -p $@
$(BIN)/%: | $(BIN) ; $(info $(M) building $(REPOSITORY)…)
$Q tmp=$$(mktemp -d); \
env GO111MODULE=off GOPATH=$$tmp GOBIN=$(BIN) $(GO) get $(REPOSITORY) \
|| ret=$$?; \
rm -rf $$tmp ; exit $$ret

GOLINT = $(BIN)/golint
$(BIN)/golint: REPOSITORY=golang.org/x/lint/golint

GOCOVMERGE = $(BIN)/gocovmerge
$(BIN)/gocovmerge: REPOSITORY=github.com/wadey/gocovmerge

GOCOV = $(BIN)/gocov
$(BIN)/gocov: REPOSITORY=github.com/axw/gocov/...

GOCOVXML = $(BIN)/gocov-xml
$(BIN)/gocov-xml: REPOSITORY=github.com/AlekSi/gocov-xml

GO2XUNIT = $(BIN)/go2xunit
$(BIN)/go2xunit: REPOSITORY=github.com/tebeka/go2xunit
# Tools

GOMODOUTDATED = $(BIN)/go-mod-outdated
$(BIN)/go-mod-outdated: REPOSITORY=github.com/psampaz/go-mod-outdated
GOLINT = $(GO) run golang.org/x/lint/golint@latest
GOCOVMERGE = $(GO) run github.com/wadey/gocovmerge@latest
GOCOV = $(GO) run github.com/axw/gocov/gocov@latest
GOCOVXML = $(GO) run github.com/AlekSi/gocov-xml@latest
GO2XUNIT = $(GO) run github.com/tebeka/go2xunit@latest
GOMODOUTDATED = $(GO) run github.com/psampaz/go-mod-outdated@latest

# Tests

Expand All @@ -145,10 +129,9 @@ COVERAGE_MODE = atomic
COVERAGE_PROFILE = $(COVERAGE_DIR)/profile.out
COVERAGE_XML = $(COVERAGE_DIR)/coverage.xml
COVERAGE_HTML = $(COVERAGE_DIR)/index.html
.PHONY: test-coverage test-coverage-tools
test-coverage-tools: | $(GOCOVMERGE) $(GOCOV) $(GOCOVXML)
.PHONY: test-coverage
test-coverage: COVERAGE_DIR := $(CURDIR)/test/coverage.$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
test-coverage: fmt lint test-coverage-tools ; $(info $(M) running coverage tests…) @ ## Run coverage tests
test-coverage: fmt lint ; $(info $(M) running coverage tests…) @ ## Run coverage tests
$Q mkdir -p $(COVERAGE_DIR)/coverage
$Q for pkg in $(TESTPKGS); do \
$(GO) test \
Expand All @@ -163,11 +146,11 @@ test-coverage: fmt lint test-coverage-tools ; $(info $(M) running coverage tests
$Q $(GOCOV) convert $(COVERAGE_PROFILE) | $(GOCOVXML) > $(COVERAGE_XML)

.PHONY: lint
lint: | $(GOLINT) ; $(info $(M) running golint…) @ ## Run golint
lint: ; $(info $(M) running golint…) @ ## Run golint
$Q $(GOLINT) -set_exit_status $(PKGS)

.PHONY: outdated
outdated: | $(GOMODOUTDATED) ; $(info $(M) running go-mod-outdated…) @ ## Run go-mod-outdated
outdated: ; $(info $(M) running go-mod-outdated…) @ ## Run go-mod-outdated
$Q $(GO) list -u -m -json all 2>/dev/null | $(GOMODOUTDATED) -update
$Q $(GO) list -u -m -json all 2>/dev/null | $(GOMODOUTDATED) -update -direct

Expand Down
1 change: 0 additions & 1 deletion cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,5 @@ $ binenv completion fish > ~/.config/fish/completions/binenv.fish
}
},
}
// cmd.Flags().IntVarP(&a.Params.MinLength, "min-length", "m", 16, "Specify minimum password length, must not be less than 8")
return cmd
}
24 changes: 24 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ This is version ` + Version + ` built on ` + BuildDate + `.`,

// disable flag parsing if we're called as a shim
if !isItMe() {
debugCompletion("binenv called in shim mode for %q\n", strings.Join(os.Args, " "))
rootCmd.DisableFlagParsing = true
rootCmd.Args = cobra.ArbitraryArgs
rootCmd.SilenceUsage = true
Expand All @@ -144,6 +145,8 @@ This is version ` + Version + ` built on ` + BuildDate + `.`,
return rootCmd
}

debugCompletion("binenv called in binenv mode for %q\n", strings.Join(os.Args, " "))

rootCmd.AddCommand(
completionCmd(),
expandCmd(a),
Expand Down Expand Up @@ -202,3 +205,24 @@ func isItMe() bool {
return strings.HasSuffix(os.Args[0], "binenv") || // this is us
strings.HasSuffix(os.Args[0], "__debug_bin") // for debugging in vscode
}

func isCompletionDebug() bool {
return os.Getenv("BASH_COMP_DEBUG_FILE") != ""
}

func debugCompletion(msg string, args ...interface{}) {
if !isCompletionDebug() {
return
}

f, err := os.OpenFile(os.Getenv("BASH_COMP_DEBUG_FILE"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
fmt.Fprintf(os.Stderr, "unable to open bash completion debug file %s: %v", os.Getenv("BASH_COMP_DEBUG_FILE"), err)
return
}

defer f.Close()

fmt.Fprintf(f, msg, args...)
// fmt.Fprintf(os.Stderr, "[DBG] called in completion mode for %s", os.Args[0])
}
Loading

0 comments on commit bf9dc7b

Please sign in to comment.