Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Parallelize Build and Test and add a local pre-push check

[email protected]8aeffc456d43
diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml
index 0d292576f5..4c9d52f549 100644
--- a/.github/workflows/build-and-test.yml
+++ b/.github/workflows/build-and-test.yml
@@ -58,8 +58,51 @@ jobs:
--report-format sarif \
--report-path results.sarif
- build:
- name: Frontend & Backend
+ # The secret scan above runs on every push including docs-only ones — this
+ # workflow is the only per-push gitleaks pass, so it must not be path
+ # filtered away. The build/test jobs below are gated here instead: a push
+ # that touches only docs/ and Markdown skips them entirely. Detection fails
+ # open (code=true) whenever the base commit cannot be resolved.
+ changes:
+ name: Detect changed areas
+ runs-on: ubuntu-24.04
+ outputs:
+ code: ${{ steps.filter.outputs.code }}
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
+ with:
+ fetch-depth: 0
+
+ - name: Classify changed files
+ id: filter
+ run: |
+ set -euo pipefail
+ if [ "${{ github.event_name }}" = "pull_request" ]; then
+ base="${{ github.event.pull_request.base.sha }}"
+ else
+ base="${{ github.event.before }}"
+ fi
+ if [ -z "$base" ] || [ "$base" = "0000000000000000000000000000000000000000" ] || ! git cat-file -e "$base" 2>/dev/null; then
+ echo "Base commit unavailable; assuming code changed."
+ echo "code=true" >> "$GITHUB_OUTPUT"
+ exit 0
+ fi
+ changed=$(git diff --name-only "$base" "${{ github.sha }}")
+ printf 'Changed files:\n%s\n' "$changed"
+ # Note: -q must not be combined with -v here — BSD grep exits 1 for
+ # that combination even when inverted matches exist.
+ if printf '%s\n' "$changed" | grep -vE '^docs/|\.md$' >/dev/null; then
+ code=true
+ else
+ code=false
+ fi
+ echo "code=$code" >> "$GITHUB_OUTPUT"
+
+ frontend:
+ name: Frontend
+ needs: changes
+ if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-24.04
env:
FRONTEND_DIR: frontend-modern
@@ -106,21 +149,106 @@ jobs:
working-directory: frontend-modern
run: npm run check:bundlesize
+ backend:
+ name: Backend tests (${{ matrix.shard }})
+ needs: changes
+ if: needs.changes.outputs.code == 'true'
+ runs-on: ubuntu-24.04
+ strategy:
+ fail-fast: false
+ matrix:
+ # internal/api is by far the slowest package under -race (~10m), so it
+ # gets a dedicated shard; every other package splits across the rest.
+ shard: [api, rest-0, rest-1]
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
+
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
cache: true
- - name: Script smoke tests
- run: scripts/tests/run.sh
+ # The internal/api package embeds frontend-modern/dist. Unit tests do
+ # not assert on real bundle content, so a stub file satisfies the embed
+ # without the ~5 minute frontend build; the real bundle is built and
+ # size-gated by the frontend job, and release artifacts always build it.
+ - name: Provide frontend embed stub
+ run: |
+ mkdir -p internal/api/frontend-modern/dist
+ [ -f internal/api/frontend-modern/dist/index.html ] || \
+ printf '<!doctype html><title>ci embed stub</title>\n' > internal/api/frontend-modern/dist/index.html
- - name: Go unit tests
+ - name: Go unit tests (shard ${{ matrix.shard }})
env:
PULSE_DATA_DIR: /tmp/pulse-test-data
# internal/api alone takes ~10m under -race on a fast machine; CI
- # runners need the larger per-binary budget.
- run: go test -race -timeout 25m ./...
+ # runners need the larger per-binary budget. Remaining packages are
+ # split deterministically by list position.
+ run: |
+ set -euo pipefail
+ case "${{ matrix.shard }}" in
+ api) pkgs="./internal/api" ;;
+ rest-0) pkgs=$(go list ./... | grep -v '/internal/api$' | awk 'NR % 2 == 0') ;;
+ rest-1) pkgs=$(go list ./... | grep -v '/internal/api$' | awk 'NR % 2 == 1') ;;
+ *) echo "unknown shard ${{ matrix.shard }}" >&2; exit 1 ;;
+ esac
+ if [ -z "$pkgs" ]; then
+ echo "shard resolved to an empty package list" >&2
+ exit 1
+ fi
+ printf 'Packages in this shard:\n%s\n' "$pkgs"
+ go test -race -timeout 25m $pkgs
+
+ scripts-and-build:
+ name: Script smoke tests & backend build
+ needs: changes
+ if: needs.changes.outputs.code == 'true'
+ runs-on: ubuntu-24.04
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
+
+ - name: Set up Go
+ uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
+ with:
+ go-version-file: go.mod
+ cache: true
+
+ - name: Provide frontend embed stub
+ run: |
+ mkdir -p internal/api/frontend-modern/dist
+ [ -f internal/api/frontend-modern/dist/index.html ] || \
+ printf '<!doctype html><title>ci embed stub</title>\n' > internal/api/frontend-modern/dist/index.html
+
+ - name: Script smoke tests
+ run: scripts/tests/run.sh
+
+ - name: Build Pulse backend
+ run: go build ./cmd/pulse
+
+ benchmarks:
+ name: Benchmarks
+ needs: changes
+ if: needs.changes.outputs.code == 'true'
+ runs-on: ubuntu-24.04
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
+
+ - name: Set up Go
+ uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
+ with:
+ go-version-file: go.mod
+ cache: true
+
+ - name: Provide frontend embed stub
+ run: |
+ mkdir -p internal/api/frontend-modern/dist
+ [ -f internal/api/frontend-modern/dist/index.html ] || \
+ printf '<!doctype html><title>ci embed stub</title>\n' > internal/api/frontend-modern/dist/index.html
- name: Go benchmarks
timeout-minutes: 20
@@ -182,6 +310,3 @@ jobs:
benchstat bench-baseline.txt bench-results.txt | tee bench-comparison.txt
echo ""
bash scripts/check-bench-regression.sh bench-comparison.txt
-
- - name: Build Pulse backend
- run: go build ./cmd/pulse
diff --git a/scripts/dev-prepush.sh b/scripts/dev-prepush.sh
new file mode 100755
index 0000000000..2d96bb56cd
--- /dev/null
+++ b/scripts/dev-prepush.sh
@@ -0,0 +1,99 @@
+#!/usr/bin/env bash
+#
+# Fast local validation before pushing to main. CI takes 10+ minutes to
+# deliver a verdict; this catches the common failure classes in a few:
+#
+# 1. canonical completion guard (contract/verification coupling, per commit)
+# 2. guard/registry snapshot tests when the subsystem registry changed
+# 3. mutation registry audits (fail closed on unclassified API routes)
+# 4. compilation plus tests for the Go packages the outgoing commits touch
+# 5. frontend type-check when frontend-modern changed
+#
+# Usage: scripts/dev-prepush.sh [base-ref]
+# base-ref defaults to origin/main. Run `git fetch origin` first for an
+# accurate range. Tests here run without -race for speed; CI still runs
+# the full -race suite across all packages.
+
+set -uo pipefail
+
+ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+cd "$ROOT_DIR"
+
+BASE="${1:-origin/main}"
+FAILURES=0
+
+step() { printf '\n=== %s ===\n' "$1"; }
+fail() { printf 'FAIL: %s\n' "$1"; FAILURES=$((FAILURES + 1)); }
+
+if ! git rev-parse --verify --quiet "$BASE" >/dev/null; then
+ echo "Base ref $BASE not found; run git fetch origin first." >&2
+ exit 2
+fi
+
+if ! git diff --quiet || ! git diff --cached --quiet; then
+ echo "Note: working tree has uncommitted changes; only committed work is checked."
+fi
+
+AHEAD=$(git rev-list --count "$BASE"..HEAD)
+if [ "$AHEAD" -eq 0 ]; then
+ echo "No commits ahead of $BASE; nothing to check."
+ exit 0
+fi
+
+CHANGED=$(git diff --name-only "$BASE"...HEAD)
+CHANGED_GO=$(printf '%s\n' "$CHANGED" | grep -E '\.go$' || true)
+
+step "Canonical completion guard (HEAD commit, CI mode)"
+if [ "$AHEAD" -gt 1 ]; then
+ echo "Note: $AHEAD commits ahead; the guard is checked for HEAD only here, CI checks each commit."
+fi
+if ! git diff --name-only HEAD~1 HEAD | \
+ python3 scripts/release_control/canonical_completion_guard.py --files-from-stdin --diff-base HEAD~1; then
+ fail "canonical completion guard"
+fi
+
+if printf '%s\n' "$CHANGED" | grep -q 'docs/release-control/v6/internal/subsystems/registry.json'; then
+ step "Registry snapshot tests (registry.json changed)"
+ python3 scripts/release_control/canonical_completion_guard_test.py || fail "guard snapshot test"
+ python3 scripts/release_control/subsystem_lookup_test.py || fail "subsystem lookup snapshot test (slow, ~3m)"
+fi
+
+if [ -n "$CHANGED_GO" ]; then
+ # internal/api embeds frontend-modern/dist; a stub keeps compilation working
+ # in worktrees that never built the frontend. CI does the same for test jobs.
+ if [ ! -f internal/api/frontend-modern/dist/index.html ]; then
+ mkdir -p internal/api/frontend-modern/dist
+ printf '<!doctype html><title>local embed stub</title>\n' > internal/api/frontend-modern/dist/index.html
+ echo "Note: created frontend embed stub (dist was absent in this checkout)."
+ fi
+
+ step "Go build"
+ go build ./... || fail "go build"
+
+ step "Mutation registry audits"
+ go test ./internal/mutationregistry ./internal/ai/tools -count=1 \
+ -run 'Test(EveryRegisteredMutationHasDisposition|InfrastructureAPIRoutesResolveToRegistry|TransportCommandCatalogsResolveToRegistry|PatrolJobRegistrationResolvesToRegistry|RuntimeCandidateAuditNegativeFixtures|ActionRouteMethodAuthorityIsExactAndLookalikesFailClosed|NonAdmittingTransportMessagesCannotCarryDispatchAuthority|UnknownTransportLookalikeFailsClosed|RegisteredModelMutationSchemasResolveToClosedRegistry|RetiredMutationAliasesCannotShadowExtensions)' \
+ || fail "mutation registry audits"
+
+ step "Go tests for touched packages (no -race locally)"
+ PKGS=$(printf '%s\n' "$CHANGED_GO" | xargs -n1 dirname | sort -u | sed 's|^|./|')
+ echo "$PKGS"
+ # shellcheck disable=SC2086
+ go test -count=1 -timeout 15m $PKGS || fail "go tests for touched packages"
+fi
+
+if printf '%s\n' "$CHANGED" | grep -q '^frontend-modern/'; then
+ step "Frontend type-check"
+ if [ -d frontend-modern/node_modules ]; then
+ (cd frontend-modern && npm run type-check) || fail "frontend type-check"
+ else
+ echo "Skipped: frontend-modern/node_modules missing (run npm ci there first)."
+ fi
+fi
+
+step "Result"
+if [ "$FAILURES" -gt 0 ]; then
+ echo "$FAILURES check(s) failed; fix before pushing."
+ exit 1
+fi
+echo "All pre-push checks passed."