From aa4efa3a69bd6abbe4e319efe54a517be622ce11 Mon Sep 17 00:00:00 2001 From: Flora Thiebaut Date: Thu, 5 Mar 2026 14:24:26 +0100 Subject: [PATCH 1/9] fix: allow no support for x11 --- .github/workflows/test.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7bb1f4f..e35fe42 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -24,9 +24,9 @@ jobs: go-version: '1.25' check-latest: true - - name: Install libraries for ubuntu - run: | - sudo apt install libx11-dev + # - name: Install libraries for ubuntu + # run: | + # sudo apt install libx11-dev - name: Print environment run: | From 0d85ec134b1ef098e474f6db5f81484aa62cb94c Mon Sep 17 00:00:00 2001 From: Flora Thiebaut Date: Thu, 5 Mar 2026 14:38:53 +0100 Subject: [PATCH 2/9] try this --- pkg/clipboard/clipboard.go | 13 +++++++++++++ pkg/clipboard/nox11.go | 13 +++++++++++++ pkg/cmd/copykeycloakadminpassword.go | 16 +++++++++++----- 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 pkg/clipboard/clipboard.go create mode 100644 pkg/clipboard/nox11.go diff --git a/pkg/clipboard/clipboard.go b/pkg/clipboard/clipboard.go new file mode 100644 index 0000000..6113d25 --- /dev/null +++ b/pkg/clipboard/clipboard.go @@ -0,0 +1,13 @@ +//go:build !linux + +package clipboard + +import "golang.design/x/clipboard" + +func Init() (supported bool, err error) { + return true, clipboard.Init() +} + +func WriteStr(value string) { + clipboard.Write(clipboard.FmtText, []byte(value)) +} diff --git a/pkg/clipboard/nox11.go b/pkg/clipboard/nox11.go new file mode 100644 index 0000000..814d894 --- /dev/null +++ b/pkg/clipboard/nox11.go @@ -0,0 +1,13 @@ +//go:build linux + +package clipboard + +import "fmt" + +func Init() (supported bool, err error) { + return false, nil +} + +func WriteStr(value string) { + fmt.Println(value) +} diff --git a/pkg/cmd/copykeycloakadminpassword.go b/pkg/cmd/copykeycloakadminpassword.go index 0297886..cedb868 100644 --- a/pkg/cmd/copykeycloakadminpassword.go +++ b/pkg/cmd/copykeycloakadminpassword.go @@ -5,12 +5,12 @@ import ( "fmt" "os" + "github.com/SwissDataScienceCenter/renku-dev-utils/pkg/clipboard" "github.com/SwissDataScienceCenter/renku-dev-utils/pkg/github" "github.com/SwissDataScienceCenter/renku-dev-utils/pkg/k8s" ns "github.com/SwissDataScienceCenter/renku-dev-utils/pkg/namespace" "github.com/spf13/cobra" "github.com/spf13/viper" - "golang.design/x/clipboard" ) var copyKeycloakAdminPasswordCmd = &cobra.Command{ @@ -61,14 +61,20 @@ func runCopyKeycloakAdminPassword(cmd *cobra.Command, args []string) { os.Exit(1) } - if err := clipboard.Init(); err != nil { + supported, err := clipboard.Init() + if err != nil { fmt.Println(err) os.Exit(1) } + if !supported { + fmt.Fprintf(os.Stderr, "Warning: clipboard not supported!") + } - clipboard.Write(clipboard.FmtText, secretValue) - fmt.Printf("Copied Keycloak admin password into the clipboard") - fmt.Println() + clipboard.WriteStr(string(secretValue)) + if supported { + fmt.Printf("Copied Keycloak admin password into the clipboard") + fmt.Println() + } } func init() { From a2d44afd062a431c1fa4c493a6cd02b5851aaf96 Mon Sep 17 00:00:00 2001 From: Flora Thiebaut Date: Thu, 5 Mar 2026 14:44:57 +0100 Subject: [PATCH 3/9] with test --- .github/workflows/test.yaml | 3 +++ Makefile | 4 ++++ pkg/clipboard/clipboard_test.go | 15 +++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 pkg/clipboard/clipboard_test.go diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e35fe42..acb6f99 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -40,6 +40,9 @@ jobs: - name: Check vet run: make check-vet + - name: Run tests + run: make test + - name: Build renku-dev-utils run: make rdu diff --git a/Makefile b/Makefile index d2fa16e..9dae7ec 100644 --- a/Makefile +++ b/Makefile @@ -73,6 +73,10 @@ check-vet: ## Check source files with `go vet` lint: ## Lint source files with `golangci-lint run` golangci-lint run +.PHONY: test +test: ## Run go tests + go test ./... + ##@ Code generation .PHONY: renku-users-apispec diff --git a/pkg/clipboard/clipboard_test.go b/pkg/clipboard/clipboard_test.go new file mode 100644 index 0000000..1ecbe35 --- /dev/null +++ b/pkg/clipboard/clipboard_test.go @@ -0,0 +1,15 @@ +package clipboard + +import ( + "fmt" + "os" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestClipboardInit(t *testing.T) { + supported, err := Init() + assert.NoError(t, err) + fmt.Fprintf(os.Stderr, "NOTE: clipboard supported: %t\n", supported) +} From 365e11558aa859d5cfb5b3450abb3e45e6bc214c Mon Sep 17 00:00:00 2001 From: Flora Thiebaut Date: Thu, 5 Mar 2026 14:45:45 +0100 Subject: [PATCH 4/9] verbose --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9dae7ec..3f2ebb8 100644 --- a/Makefile +++ b/Makefile @@ -75,7 +75,7 @@ lint: ## Lint source files with `golangci-lint run` .PHONY: test test: ## Run go tests - go test ./... + go test -v ./... ##@ Code generation From 49bb71d05fe3e78c963e7684fc676ed45b5295b4 Mon Sep 17 00:00:00 2001 From: Flora Thiebaut Date: Thu, 5 Mar 2026 14:58:36 +0100 Subject: [PATCH 5/9] detect x11 --- Makefile | 16 ++++++++++++++-- pkg/clipboard/clipboard.go | 2 +- pkg/clipboard/nox11.go | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 3f2ebb8..3520caf 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,18 @@ else VERSION := $(BRANCH).$(GIT_COMMIT_HASH) DIRTY := "dev" endif +# X11 support +X11 := 0 +ifeq ($(shell go env GOOS),linux) +ifeq ($(shell ldconfig -p | grep X11 || echo "")) +X11 := 1 +endif +endif LDFLAGS=--ldflags "-s -X github.com/SwissDataScienceCenter/renku-dev-utils/pkg/version.Version=$(VERSION) -X github.com/SwissDataScienceCenter/renku-dev-utils/pkg/version.VersionSuffix=$(DIRTY)" +TAGS= +ifeq ($(X11),1) +TAGS=-tags=x11 +endif .PHONY: all all: help @@ -29,6 +40,7 @@ vars: ## Show the Makefile vars @echo GIT_TAG="'$(GIT_TAG)'" @echo VERSION="'$(VERSION)'" @echo DIRTY="'$(DIRTY)'" + @echo X11="'$(X11)'" .PHONY: rdu rdu: build/renku-dev-utils ## Build and install renku-dev-utils @@ -38,7 +50,7 @@ rdu: build/renku-dev-utils ## Build and install renku-dev-utils .PHONY: build/renku-dev-utils build/renku-dev-utils: - go build -v -o build/ $(LDFLAGS) + go build -v -o build/ $(TAGS) $(LDFLAGS) # From the operator sdk Makefile # The help target prints out all targets with their descriptions organized @@ -75,7 +87,7 @@ lint: ## Lint source files with `golangci-lint run` .PHONY: test test: ## Run go tests - go test -v ./... + go test -v $(TAGS) ./... ##@ Code generation diff --git a/pkg/clipboard/clipboard.go b/pkg/clipboard/clipboard.go index 6113d25..c47f9e8 100644 --- a/pkg/clipboard/clipboard.go +++ b/pkg/clipboard/clipboard.go @@ -1,4 +1,4 @@ -//go:build !linux +//go:build !linux || x11 package clipboard diff --git a/pkg/clipboard/nox11.go b/pkg/clipboard/nox11.go index 814d894..61a79d8 100644 --- a/pkg/clipboard/nox11.go +++ b/pkg/clipboard/nox11.go @@ -1,4 +1,4 @@ -//go:build linux +//go:build linux && !x11 package clipboard From 2966850bbe60a7b9828b5af2b9160d0f9f61c01a Mon Sep 17 00:00:00 2001 From: Flora Thiebaut Date: Thu, 5 Mar 2026 14:59:07 +0100 Subject: [PATCH 6/9] update test --- .github/workflows/test.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index acb6f99..4f1aa56 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -46,6 +46,13 @@ jobs: - name: Build renku-dev-utils run: make rdu + - name: Install libraries for ubuntu + run: | + sudo apt install libx11-dev + + - name: Run tests with x11 + run: make test + lint: runs-on: ubuntu-24.04 steps: From 711dfc0cff01397a1ab6086384befd759e190cce Mon Sep 17 00:00:00 2001 From: Flora Thiebaut Date: Thu, 5 Mar 2026 15:00:07 +0100 Subject: [PATCH 7/9] fix? --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3520caf..0a39e87 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ endif # X11 support X11 := 0 ifeq ($(shell go env GOOS),linux) -ifeq ($(shell ldconfig -p | grep X11 || echo "")) +ifneq ($(shell ldconfig -p | grep X11 || echo ""),) X11 := 1 endif endif From 9886cdc9043368d7df125800b948f45014b6b201 Mon Sep 17 00:00:00 2001 From: Flora Thiebaut Date: Thu, 5 Mar 2026 15:01:59 +0100 Subject: [PATCH 8/9] ? --- .github/workflows/test.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 4f1aa56..84d0b11 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -23,10 +23,6 @@ jobs: with: go-version: '1.25' check-latest: true - - # - name: Install libraries for ubuntu - # run: | - # sudo apt install libx11-dev - name: Print environment run: | @@ -49,6 +45,12 @@ jobs: - name: Install libraries for ubuntu run: | sudo apt install libx11-dev + + - name: Print environment with x11 + run: | + which go + go env + make vars - name: Run tests with x11 run: make test From 4a06fa181cd2b60f95beac17d0a740eaa6b17011 Mon Sep 17 00:00:00 2001 From: Flora Thiebaut Date: Thu, 5 Mar 2026 15:03:47 +0100 Subject: [PATCH 9/9] print ldconfig --- .github/workflows/test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 84d0b11..3a1f559 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -26,6 +26,7 @@ jobs: - name: Print environment run: | + ldconfig -p | grep X11 which go go env make vars