diff --git a/.githooks/pre-commit b/.githooks/pre-commit index c37fc1b..cd48ac4 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -8,13 +8,16 @@ usage() { echo " --all check all tracked files" >&2 } +REPO_ROOT=$(git rev-parse --show-toplevel) +cd "$REPO_ROOT" || exit 1 + case "${1:-}" in "") - selected_files=$(git diff --cached --name-only --diff-filter=ACMR) + selected_files=$(git diff --cached --name-only --diff-filter=ACDMR) mode_label="staged" ;; --unstaged) - selected_files=$(git diff --name-only --diff-filter=ACMR) + selected_files=$(git diff --name-only --diff-filter=ACDMR) selected_files="$selected_files $(git ls-files --others --exclude-standard)" mode_label="unstaged" @@ -29,9 +32,6 @@ $(git ls-files --others --exclude-standard)" ;; esac -REPO_ROOT=$(git rev-parse --show-toplevel) -cd "$REPO_ROOT" || exit 1 - TMP_ROOT=${TMPDIR:-/tmp}/tests-dcompose mkdir -p "$TMP_ROOT" PIDS_FILE=$(mktemp "$TMP_ROOT/dcompose-precommit.XXXXXX") @@ -96,14 +96,14 @@ fi if [ "$go_changed" -eq 1 ]; then run_step "Go: Formatter" mise exec -- golangci-lint fmt --diff ./cmd/... ./internal/... - run_step "Go: Tests" mise exec -- go test -race ./cmd/... ./internal/... + run_step "Go: Tests" mise exec -- go test -race -shuffle=on ./cmd/... ./internal/... run_step "Go: Linter" mise exec -- golangci-lint run ./cmd/... ./internal/... fi if [ "$frontend_changed" -eq 1 ]; then run_step "Frontend: Formatter" mise exec -- bun --cwd="$PWD/frontend/" run format:check run_step "Frontend: Linter" mise exec -- bun --cwd="$PWD/frontend/" run lint - run_step "Frontend: Tests" mise exec -- bun --cwd="$PWD/frontend/" test + run_step "Frontend: Tests" mise exec -- bun --cwd="$PWD/frontend/" test --randomize run_step "Frontend: TSC" mise exec -- bun --cwd="$PWD/frontend/" run lint:tsc fi diff --git a/.github/scripts/build-info.sh b/.github/scripts/build-info.sh new file mode 100644 index 0000000..cc5623b --- /dev/null +++ b/.github/scripts/build-info.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -euo pipefail + +version=${GITHUB_REF##*/} +commit_sha=$(git rev-parse HEAD) +build_date=$(date -u +%Y-%m-%d) +branch=$(git branch --show-current) +if [[ "$GITHUB_REF" == refs/heads/* ]]; then + branch=${GITHUB_REF#refs/heads/} +fi + +printf 'version=%s\ncommit_sha=%s\nbuild_date=%s\nbranch=%s\n' \ + "$version" "$commit_sha" "$build_date" "${branch:-unknown}" diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 8a89e93..e98c4e1 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -8,7 +8,6 @@ on: branches: - master - dev - - testing paths-ignore: - '**.md' - '.github/ISSUE_TEMPLATE/**' @@ -22,6 +21,10 @@ jobs: - name: Checkout uses: actions/checkout@v7 + - name: Read build metadata + id: build-info + run: bash .github/scripts/build-info.sh >> "$GITHUB_OUTPUT" + - name: Set up tools uses: jdx/mise-action@v5 with: @@ -60,6 +63,11 @@ jobs: run: ./.githooks/pre-commit --all - name: Build frontend + env: + NUXT_PUBLIC_VERSION: ${{ steps.build-info.outputs.version }} + NUXT_PUBLIC_COMMIT_SHA: ${{ steps.build-info.outputs.commit_sha }} + NUXT_PUBLIC_BUILD_DATE: ${{ steps.build-info.outputs.build_date }} + NUXT_PUBLIC_BRANCH: ${{ steps.build-info.outputs.branch }} run: bun --cwd=$PWD/frontend/ run generate - name: Set up Docker Buildx @@ -74,3 +82,4 @@ jobs: cache-from: type=gha,scope=${{ github.workflow }} cache-to: type=gha,mode=max,scope=${{ github.workflow }} provenance: false + build-args: VERSION=${{ steps.build-info.outputs.version }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d7d23ee..61d8c0c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,7 +12,7 @@ on: type: boolean default: false push: - branches: [dev, master, testing] + branches: [dev, master] tags: ['v*'] paths-ignore: - '**.md' @@ -47,9 +47,15 @@ jobs: needs: validate-build-config runs-on: ubuntu-latest timeout-minutes: 20 + outputs: + version: ${{ steps.build-info.outputs.version }} steps: - uses: actions/checkout@v7 + - name: Read build metadata + id: build-info + run: bash .github/scripts/build-info.sh >> "$GITHUB_OUTPUT" + - uses: jdx/mise-action@v5 with: install_args: go bun node golangci-lint @@ -84,6 +90,11 @@ jobs: run: ./.githooks/pre-commit --all - name: Build frontend + env: + NUXT_PUBLIC_VERSION: ${{ steps.build-info.outputs.version }} + NUXT_PUBLIC_COMMIT_SHA: ${{ steps.build-info.outputs.commit_sha }} + NUXT_PUBLIC_BUILD_DATE: ${{ steps.build-info.outputs.build_date }} + NUXT_PUBLIC_BRANCH: ${{ steps.build-info.outputs.branch }} run: bun --cwd=$PWD/frontend/ generate - name: Upload frontend build (GitHub) @@ -110,7 +121,7 @@ jobs: env: CGO_ENABLED: '0' GOOS: linux - VERSION: ${{ github.ref_name }} + VERSION: ${{ needs.test.outputs.version }} steps: - uses: actions/checkout@v7 diff --git a/frontend/app/components/AppFooter.vue b/frontend/app/components/AppFooter.vue new file mode 100644 index 0000000..e76f46d --- /dev/null +++ b/frontend/app/components/AppFooter.vue @@ -0,0 +1,52 @@ + + + diff --git a/frontend/app/components/NodeResources.vue b/frontend/app/components/NodeResources.vue index 3d7a416..de171ff 100644 --- a/frontend/app/components/NodeResources.vue +++ b/frontend/app/components/NodeResources.vue @@ -3,11 +3,10 @@ import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue' import { NuxtLink } from '#components' import UBadge from '@nuxt/ui/components/Badge.vue' import UButton from '@nuxt/ui/components/Button.vue' -import UAlert from '@nuxt/ui/components/Alert.vue' import UIcon from '@nuxt/ui/components/Icon.vue' import UTooltip from '@nuxt/ui/components/Tooltip.vue' -import type { NodeInfo, WorkspaceNode } from '~/types' -import { notification, parse_api_response, request } from '~/utils' +import type { NodeInfo, NodeResourceStatus, WorkspaceNode } from '~/types' +import { parse_api_response, request } from '~/utils' import { formatMemoryBytes } from '~/utils/node' import { aggregateStackStats, parseStatBytes, workspaceErrorMessage } from '~/utils/stacks' @@ -33,6 +32,41 @@ const connectionLabel = computed(() => { paused: 'Paused', }[props.node.connection] }) + +const status = computed(() => { + if (props.node.paused || 'paused' === props.node.connection) { + return { + text: 'Paused. Resume this node to reconnect.', + icon: 'i-lucide-pause', + tone: 'muted', + } + } + if (!connected.value) { + return { + text: props.node.error + ? `${props.node.error}${info.value ? ' Showing previous sample.' : ''}` + : connectionLabel.value, + icon: 'i-lucide-wifi-off', + tone: 'warning', + } + } + if (error.value) { + return { + text: info.value ? `${error.value} Showing previous sample.` : error.value, + icon: 'i-lucide-circle-alert', + tone: 'warning', + } + } + if (!info.value) { + return { + text: 'Loading resource usage...', + icon: 'i-lucide-loader-circle', + tone: 'muted', + spin: true, + } + } + return null +}) const totals = computed(() => aggregateStackStats(info.value?.containers ?? [], info.value?.runtime.cpus ?? 1), ) @@ -91,14 +125,10 @@ const refresh = async () => { error.value = '' } catch (cause) { if (!current.signal.aborted) { - const message = + error.value = cause instanceof Error && !(cause instanceof TypeError) ? cause.message : 'Could not load resource usage.' - if (!error.value) { - notification('error', `Resource snapshot failed for ${props.node.name}`, message) - } - error.value = message } } finally { if (controller === current) { @@ -126,10 +156,13 @@ const resume = () => { timer = setInterval(() => void refresh(), 30_000) } -watch([() => props.node.id, connected], () => { +watch([() => props.node.id, connected, () => props.node.paused], ([id], [previousId]) => { + const reset = id !== previousId || props.node.paused || 'paused' === props.node.connection stop() - info.value = null - error.value = '' + if (reset) { + info.value = null + error.value = '' + } resume() }) @@ -179,138 +212,114 @@ onBeforeUnmount(() => { >{{ node.name }} -
- -