Skip to content

Commit cd5ebbb

Browse files
committed
updates
1 parent 984afec commit cd5ebbb

File tree

8 files changed

+504
-264
lines changed

8 files changed

+504
-264
lines changed

.golangci.yaml

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
1-
# More info on config here: https://github.com/golangci/golangci-lint#config-file
2-
run:
3-
deadline: 10s
4-
issues-exit-code: 1
5-
tests: true
6-
1+
# yaml-language-server: $schema=https://golangci-lint.run/jsonschema/golangci.jsonschema.json
2+
version: "2"
73
output:
84
formats:
9-
- format: colored-line-number
10-
print-issued-lines: true
11-
print-linter-name: true
12-
13-
linters-settings:
14-
govet:
15-
shadow: true
16-
golint:
17-
min-confidence: 0
18-
dupl:
19-
threshold: 100
20-
goconst:
21-
min-len: 2
22-
min-occurrences: 2
23-
5+
text:
6+
path: stdout
7+
print-linter-name: true
8+
print-issued-lines: true
249
linters:
25-
disable-all: true
10+
default: none
2611
enable:
27-
- revive
28-
- govet
29-
- errcheck
30-
- unused
31-
- ineffassign
32-
- typecheck
3312
- dupl
13+
- errcheck
3414
- goconst
3515
- gosec
36-
- goimports
37-
- gosimple
16+
- govet
17+
- ineffassign
18+
- revive
3819
- staticcheck
3920
- unused
40-
41-
issues:
42-
exclude-use-default: false
43-
exclude-dirs:
44-
- bin
45-
- vendor
46-
- var
47-
- tmp
48-
exclude-files:
49-
- \.pb\.go$
50-
- \.pb\.goclay\.go$
51-
exclude:
52-
# # _ instead of err checks
53-
# - G104
54-
# errcheck: Almost all programs ignore errors on these functions and in most cases it's ok
55-
- Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv|.*Rollback). is not checked
21+
settings:
22+
dupl:
23+
threshold: 100
24+
goconst:
25+
min-len: 2
26+
min-occurrences: 2
27+
exclusions:
28+
generated: lax
29+
rules:
30+
- path: (.+)\.go$
31+
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*printf?|os\.(Un)?Setenv|.*Rollback). is not checked
32+
paths:
33+
- \.pb\.go$
34+
- \.pb\.goclay\.go$
35+
- bin
36+
- vendor
37+
- var
38+
- tmp
39+
- third_party$
40+
- builtin$
41+
- examples$
42+
formatters:
43+
enable:
44+
- goimports
45+
exclusions:
46+
generated: lax
47+
paths:
48+
- \.pb\.go$
49+
- \.pb\.goclay\.go$
50+
- bin
51+
- vendor
52+
- var
53+
- tmp
54+
- third_party$
55+
- builtin$
56+
- examples$

Makefile

Lines changed: 151 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ FIRST_GOPATH:=$(firstword $(subst :, ,$(GOPATH)))
33

44
# Build available information.
55
GIT_HASH:=$(shell git log --format="%h" -n 1 2> /dev/null)
6-
RAW_GIT_BRANCH := $(if $(GITHUB_REF_NAME),$(GITHUB_REF_NAME),$(shell git rev-parse --abbrev-ref HEAD))
7-
GIT_BRANCH = $(shell echo $(RAW_GIT_BRANCH) | sed 's/[^a-zA-Z0-9-]//g')
6+
GIT_BRANCH:=$(shell git rev-parse --abbrev-ref HEAD)
87
APP_VERSION:="$(GIT_BRANCH)-$(GIT_HASH)"
98
GOPKG:=github.com/launchrctl/launchr
109

@@ -24,62 +23,186 @@ LOCAL_BIN:=$(CURDIR)/bin
2423

2524
# Linter config.
2625
GOLANGCI_BIN:=$(LOCAL_BIN)/golangci-lint
27-
GOLANGCI_TAG:=1.64.5
26+
GOLANGCI_TAG:=2.5.0
27+
28+
GOTESTFMT_BIN:=$(GOBIN)/gotestfmt
29+
30+
# Color definitions
31+
RED=\033[0;31m
32+
GREEN=\033[0;32m
33+
YELLOW=\033[0;33m
34+
BLUE=\033[0;34m
35+
MAGENTA=\033[0;35m
36+
CYAN=\033[0;36m
37+
WHITE=\033[0;37m
38+
BOLD=\033[1m
39+
RESET=\033[0m
40+
41+
# Disable colors on Windows.
42+
ifeq ($(OS),Windows_NT)
43+
RED=
44+
GREEN=
45+
YELLOW=
46+
BLUE=
47+
MAGENTA=
48+
CYAN=
49+
WHITE=
50+
BOLD=
51+
RESET=
52+
endif
53+
54+
# Print functions
55+
define print_header
56+
@echo "$(BOLD)$(CYAN)╔═════════════════════════════════════════════════════════════╗$(RESET)"
57+
@echo "$(BOLD)$(CYAN)║ LAUNCHR ║$(RESET)"
58+
@echo "$(BOLD)$(CYAN)╚═════════════════════════════════════════════════════════════╝$(RESET)"
59+
endef
60+
61+
define print_success
62+
@echo "$(BOLD)$(GREEN)$(1)$(RESET)"
63+
@echo
64+
endef
65+
66+
define print_info
67+
@echo "$(BOLD)$(BLUE)📋 $(1)$(RESET)"
68+
@echo
69+
endef
70+
71+
define print_warning
72+
@echo "$(BOLD)$(YELLOW)⚠️ $(1)$(RESET)"
73+
@echo
74+
endef
75+
76+
define print_error
77+
@echo "$(BOLD)$(RED)$(1)$(RESET)"
78+
@echo
79+
endef
80+
81+
define print_step
82+
@echo "$(BOLD)$(MAGENTA)🔧 $(1)$(RESET)"
83+
endef
2884

2985
.PHONY: all
30-
all: deps test build
86+
all: banner deps test-short build
87+
$(call print_success,"🎉 All tasks completed successfully!")
88+
89+
.PHONY: banner
90+
banner:
91+
$(call print_header)
92+
@echo "$(BOLD)$(WHITE)📦 Version: $(APP_VERSION)$(RESET)"
93+
@echo "$(BOLD)$(WHITE)🌿 Branch: $(GIT_BRANCH)$(RESET)"
94+
@echo "$(BOLD)$(WHITE)🔗 Hash: $(GIT_HASH)$(RESET)"
95+
@echo
3196

3297
# Install go dependencies
3398
.PHONY: deps
3499
deps:
35-
$(info Installing go dependencies...)
36-
go mod download
100+
$(call print_step,"Installing go dependencies...")
101+
@go mod download
102+
$(call print_success,"Dependencies installed successfully!")
37103

38104
# Run all tests
39105
.PHONY: test
40-
test:
41-
$(info Running tests...)
42-
go test ./...
43-
44-
# Echo vars for debbug
45-
.PHONY: debugvars
46-
debugvars:
47-
$(shell echo "GITHUB_REF_NAME=${GITHUB_REF_NAME}")
48-
$(shell echo "RAW_GIT_BRANCH=${SANITIZED_GIT_BRANCH}")
49-
$(shell echo "GIT_BRANCH=$(GIT_BRANCH)")
50-
$(shell echo "GIT_HASH=$(GIT_HASH)")
51-
$(shell echo "APP_VERSION=$(APP_VERSION)")
106+
test: .install-gotestfmt
107+
$(call print_step,"Running all tests...")
108+
@go test -json -v ./... | $(GOTESTFMT_BIN) -hide all && \
109+
echo "$(BOLD)$(GREEN)🧪 ✅ All tests passed$(RESET)" || \
110+
echo "$(BOLD)$(RED)🧪 ❌ Some tests failed$(RESET)"
111+
@echo
112+
113+
# Run short tests
114+
.PHONY: test-short
115+
test-short: .install-gotestfmt
116+
$(call print_step,"Running short tests...")
117+
@go test -json -short -v ./... | $(GOTESTFMT_BIN) -hide all && \
118+
echo "$(BOLD)$(GREEN)🧪 ✅ All short tests passed$(RESET)" || \
119+
echo "$(BOLD)$(RED)🧪 ❌ Some short tests failed$(RESET)"
120+
@echo
52121

53122
# Build launchr
54123
.PHONY: build
55124
build:
56-
$(info Building launchr...)
125+
$(call print_step,"Building launchr...")
57126
# Application related information available on build time.
58127
$(eval LDFLAGS:=-X '$(GOPKG).name=launchr' -X '$(GOPKG).version=$(APP_VERSION)' $(LDFLAGS_EXTRA))
59128
$(eval BIN?=$(LOCAL_BIN)/launchr)
60-
go generate ./...
61-
$(BUILD_ENVPARMS) go build -ldflags "$(LDFLAGS)" $(BUILD_OPTS) -o $(BIN) ./cmd/launchr
129+
@go generate ./...
130+
@$(BUILD_ENVPARMS) go build -ldflags "$(LDFLAGS)" $(BUILD_OPTS) -o $(BIN) ./cmd/launchr
131+
$(call print_success,"🔨 Build completed: $(BIN)")
62132

63133
# Install launchr
64134
.PHONY: install
65135
install: all
66-
install:
67-
$(info Installing launchr to GOPATH...)
68-
cp $(LOCAL_BIN)/launchr $(GOBIN)/launchr
136+
$(call print_step,"Installing launchr to GOPATH...")
137+
@cp $(LOCAL_BIN)/launchr $(GOBIN)/launchr
138+
$(call print_success,"🚀 launchr installed to $(GOBIN)/launchr")
69139

70140
# Install and run linters
71141
.PHONY: lint
72-
lint: .install-lint .lint
142+
lint: .install-lint .lint-fix
73143

74144
# Install golangci-lint binary
75145
.PHONY: .install-lint
76146
.install-lint:
77147
ifeq ($(wildcard $(GOLANGCI_BIN)),)
78-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCAL_BIN) v$(GOLANGCI_TAG)
148+
$(call print_step,"Installing golangci-lint v$(GOLANGCI_TAG)...")
149+
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCAL_BIN) v$(GOLANGCI_TAG)
150+
$(call print_success,"golangci-lint installed!")
151+
endif
152+
153+
# Install gotestfmt binary
154+
.PHONY: .install-gotestfmt
155+
.install-gotestfmt:
156+
ifeq ($(wildcard $(GOTESTFMT_BIN)),)
157+
$(call print_step,"Installing gotestfmt...")
158+
@go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
159+
$(call print_success,"gotestfmt installed!")
79160
endif
80161

81162
# Runs linters
163+
.PHONY: .lint-fix
164+
.lint-fix:
165+
$(call print_step,"Running linters with auto-fix...")
166+
@$(GOLANGCI_BIN) run --fix ./... && \
167+
echo "$(BOLD)$(GREEN)🔍 ✅ All linting checks passed$(RESET)" || \
168+
echo "$(BOLD)$(YELLOW)🔍 ⚠️ Some linting issues found - please review$(RESET)"
169+
@echo
170+
82171
.PHONY: .lint
83172
.lint:
84-
$(info Running lint...)
85-
$(GOLANGCI_BIN) run --fix ./...
173+
$(call print_step,"Running linters...")
174+
@$(GOLANGCI_BIN) run && \
175+
echo "$(BOLD)$(GREEN)🔍 ✅ All linting checks passed$(RESET)" || \
176+
echo "$(BOLD)$(YELLOW)🔍 ⚠️ Some linting issues found - please review$(RESET)"
177+
@echo
178+
179+
# Clean build artifacts
180+
.PHONY: clean
181+
clean:
182+
$(call print_step,"Cleaning build artifacts...")
183+
@rm -rf $(LOCAL_BIN)
184+
$(call print_success,"🧹 Cleanup completed!")
185+
186+
# Show help
187+
.PHONY: help
188+
help:
189+
$(call print_header)
190+
@echo "$(BOLD)$(WHITE)Available targets:$(RESET)"
191+
@echo ""
192+
@echo " $(BOLD)$(GREEN)all$(RESET) 🎯 Run deps, test, and build"
193+
@echo " $(BOLD)$(GREEN)deps$(RESET) 📦 Install go dependencies"
194+
@echo " $(BOLD)$(GREEN)test$(RESET) 🧪 Run all tests"
195+
@echo " $(BOLD)$(GREEN)test-short$(RESET) ⚡ Run short tests only"
196+
@echo " $(BOLD)$(GREEN)build$(RESET) 🔨 Build launchr binary"
197+
@echo " $(BOLD)$(GREEN)install$(RESET) 🚀 Install launchr to GOPATH"
198+
@echo " $(BOLD)$(GREEN)lint$(RESET) 🔍 Run linters with auto-fix"
199+
@echo " $(BOLD)$(GREEN)clean$(RESET) 🧹 Clean build artifacts"
200+
@echo " $(BOLD)$(GREEN)help$(RESET) ❓ Show this help message"
201+
@echo ""
202+
@echo "$(BOLD)$(CYAN)Environment variables:$(RESET)"
203+
@echo " $(BOLD)$(YELLOW)DEBUG=1$(RESET) Enable debug build"
204+
@echo " $(BOLD)$(YELLOW)BIN=path$(RESET) Custom binary output path"
205+
@echo ""
206+
207+
# Default target shows help
208+
.DEFAULT_GOAL := help

compose/compose.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package compose
44
import (
55
"context"
66
"errors"
7+
"net/url"
78
"os"
89
"os/signal"
910
"path/filepath"
@@ -35,6 +36,27 @@ type keyringWrapper struct {
3536
shouldUpdate bool
3637
}
3738

39+
func baseURL(fullURL string) (string, error) {
40+
u, err := url.Parse(fullURL)
41+
if err != nil {
42+
return "", err
43+
}
44+
if u.Scheme == "" {
45+
u.Scheme = "https"
46+
}
47+
return u.Scheme + "://" + u.Host, nil
48+
}
49+
50+
func (kw *keyringWrapper) getForBaseURL(url string) (keyring.CredentialsItem, error) {
51+
burl, err := baseURL(url)
52+
if err != nil {
53+
return keyring.CredentialsItem{}, err
54+
}
55+
56+
ci, err := kw.keyringService.GetForURL(burl)
57+
return ci, err
58+
}
59+
3860
func (kw *keyringWrapper) getForURL(url string) (keyring.CredentialsItem, error) {
3961
ci, errGet := kw.keyringService.GetForURL(url)
4062
if errGet != nil {

compose/downloadManager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ func CreateDownloadManager(keyring *keyringWrapper) DownloadManager {
3535
}
3636

3737
func (m DownloadManager) getDownloaderForPackage(downloadType string) Downloader {
38-
switch {
39-
case downloadType == HTTPType:
38+
switch downloadType {
39+
case HTTPType:
4040
return newHTTP(m.kw)
41-
case downloadType == GitType:
41+
case GitType:
4242
fallthrough
4343
default:
4444
return newGit(m.kw)

0 commit comments

Comments
 (0)