Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@ jobs:
with:
go-version: '1.25'
check-latest: true

- name: Install libraries for ubuntu
run: |
sudo apt install libx11-dev

- name: Print environment
run: |
ldconfig -p | grep X11
which go
go env
make vars
Expand All @@ -40,9 +37,25 @@ jobs:
- name: Check vet
run: make check-vet

- name: Run tests
run: make test

- name: Build renku-dev-utils
run: make rdu

- 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

lint:
runs-on: ubuntu-24.04
steps:
Expand Down
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@ else
VERSION := $(BRANCH).$(GIT_COMMIT_HASH)
DIRTY := "dev"
endif
# X11 support
X11 := 0
ifeq ($(shell go env GOOS),linux)
ifneq ($(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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -73,6 +85,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 -v $(TAGS) ./...

##@ Code generation

.PHONY: renku-users-apispec
Expand Down
13 changes: 13 additions & 0 deletions pkg/clipboard/clipboard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build !linux || x11

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))
}
15 changes: 15 additions & 0 deletions pkg/clipboard/clipboard_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
13 changes: 13 additions & 0 deletions pkg/clipboard/nox11.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//go:build linux && !x11

package clipboard

import "fmt"

func Init() (supported bool, err error) {
return false, nil
}

func WriteStr(value string) {
fmt.Println(value)
}
16 changes: 11 additions & 5 deletions pkg/cmd/copykeycloakadminpassword.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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() {
Expand Down
Loading