From 24edb42dfc044be61811a48cbd2f3849bffbacb0 Mon Sep 17 00:00:00 2001 From: Stefan Koelle <50440224+skoelle@users.noreply.github.com> Date: Sun, 9 Aug 2026 11:25:00 +0200 Subject: [PATCH] Add CI workflow, install.sh, and example config --- .github/workflows/build.yml | 85 +++++++++++++++++++++++++++++++++++++ config.example.yaml | 19 +++++++++ install.sh | 64 ++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 config.example.yaml create mode 100644 install.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..0442eab --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,85 @@ +name: Build and Test + +on: + push: + branches: [ "main" ] + tags: [ "v*" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: write + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version: "1.22" + + - name: Download dependencies + run: go mod download + + - name: Vet + run: go vet ./... + + - name: Run tests + run: go test ./... -v -cover + + build: + name: Build binaries + needs: test + runs-on: ubuntu-latest + strategy: + matrix: + goos: [linux, windows, darwin] + goarch: [amd64, arm64] + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version: "1.22" + + - name: Download dependencies + run: go mod download + + - name: Build + env: + GOOS: ${{ matrix.goos }} + GOARCH: ${{ matrix.goarch }} + CGO_ENABLED: 0 + run: | + mkdir -p dist + ext="" + if [ "${{ matrix.goos }}" = "windows" ]; then ext=".exe"; fi + out="dist/kctl-tui-${{ matrix.goos }}-${{ matrix.goarch }}${ext}" + go build -o "$out" -ldflags "-s -w" ./cmd/kctl-tui + echo "Built $out" + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: kctl-tui-${{ matrix.goos }}-${{ matrix.goarch }} + path: dist/* + + release: + name: Attach binaries to GitHub Release + if: startsWith(github.ref, 'refs/tags/v') + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 + with: + path: dist + merge-multiple: true + + - name: Create release and upload binaries + uses: softprops/action-gh-release@v2 + with: + files: dist/* + generate_release_notes: true diff --git a/config.example.yaml b/config.example.yaml new file mode 100644 index 0000000..d5ebffb --- /dev/null +++ b/config.example.yaml @@ -0,0 +1,19 @@ +# Example configuration for kctl-tui. +# Copy this file to ~/.kctl-tui/config.yaml and adjust the values to your +# own cluster setup. Do NOT commit your real config.yaml with company- or +# project-specific context/namespace/label names to a public repository. + +# Groups of kubectl contexts that belong together (e.g. the same +# environment pair, such as staging/production of the same cluster). +# Pressing TAB in the control pane cycles through the contexts listed here +# while keeping the current namespace. +context_pairs: + - name: "example-environment-pair" + contexts: + - "example-context-a" + - "example-context-b" + +# The namespace label key used to group namespaces by team/ownership in the +# team-selection screen. Adjust this to whatever label your organization +# actually uses (can contain a domain prefix, e.g. "example.org/team"). +team_label_key: "example.org/team" diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..d29d720 --- /dev/null +++ b/install.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash +# Install script for kctl-tui. +# Downloads the latest GitHub release binary matching the current OS/arch +# and installs it to /usr/local/bin (or $INSTALL_DIR if set). +# +# Usage: +# curl -fsSL https://raw.githubusercontent.com/skoelle/kctl-tui/main/install.sh | bash +# +# Requires: curl, a supported OS (linux, darwin). +# Native Windows is not supported by this script; use WSL, or download the +# .exe asset manually from the Releases page. + +set -euo pipefail + +REPO="skoelle/kctl-tui" +INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}" +BIN_NAME="kctl-tui" + +os="$(uname -s | tr '[:upper:]' '[:lower:]')" +arch="$(uname -m)" + +case "$arch" in + x86_64|amd64) arch="amd64" ;; + arm64|aarch64) arch="arm64" ;; + *) + echo "Unsupported architecture: $arch" >&2 + exit 1 + ;; +esac + +case "$os" in + linux|darwin) ;; + *) + echo "Unsupported OS: $os. On Windows, use WSL or download the .exe from the Releases page." >&2 + exit 1 + ;; +esac + +echo "Detecting latest release for $REPO ..." +latest_tag="$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep -m1 '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')" + +if [ -z "$latest_tag" ]; then + echo "Could not determine latest release tag. Is there at least one published release?" >&2 + exit 1 +fi + +asset="kctl-tui-${os}-${arch}" +url="https://github.com/${REPO}/releases/download/${latest_tag}/${asset}" + +echo "Downloading ${asset} (${latest_tag}) ..." +tmp_file="$(mktemp)" +curl -fsSL "$url" -o "$tmp_file" +chmod +x "$tmp_file" + +if [ -w "$INSTALL_DIR" ]; then + mv "$tmp_file" "${INSTALL_DIR}/${BIN_NAME}" +else + echo "Elevated permissions required to write to ${INSTALL_DIR}" + sudo mv "$tmp_file" "${INSTALL_DIR}/${BIN_NAME}" +fi + +echo "Installed ${BIN_NAME} to ${INSTALL_DIR}/${BIN_NAME}" +"${INSTALL_DIR}/${BIN_NAME}" --help >/dev/null 2>&1 || true +echo "Done. Run '${BIN_NAME}' to get started."