Skip to content

A modern, self-hosted backup solution for secure, encrypted backups across local and cloud storage.

chore: add git hooks setup and CI for backend tests

towfiqi34db506e45c0
diff --git a/.githooks/pre-push b/.githooks/pre-push
new file mode 100644
index 0000000..4960dd7
--- /dev/null
+++ b/.githooks/pre-push
@@ -0,0 +1,24 @@
+#!/usr/bin/env sh
+
+set -eu
+
+run_tests=0
+
+while read -r local_ref local_sha remote_ref remote_sha
+do
+ if [ "${remote_ref}" = "refs/heads/main" ]; then
+ if [ "${local_sha}" != "0000000000000000000000000000000000000000" ]; then
+ run_tests=1
+ break
+ fi
+ fi
+done
+
+if [ "$run_tests" -eq 0 ]; then
+ exit 0
+fi
+
+echo "[pre-push] Pushing to main. Running backend test suite..."
+pnpm --filter @plutonhq/core-backend test
+
+echo "[pre-push] Backend tests passed. Continuing push."
\ No newline at end of file
diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.yml
new file mode 100644
index 0000000..1640653
--- /dev/null
+++ b/.github/workflows/ci-backend.yml
@@ -0,0 +1,48 @@
+name: Backend Test CI
+
+on:
+ pull_request:
+ types: [opened, synchronize, reopened]
+ push:
+ branches:
+ - main
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+concurrency:
+ group: backend-test-ci-${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ backend-checks:
+ name: Backend Lint, Test, Build
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Setup pnpm
+ uses: pnpm/action-setup@v4
+ with:
+ version: 10.20.0
+
+ - name: Setup Node.js
+ uses: actions/setup-node@v4
+ with:
+ node-version: "24"
+ cache: "pnpm"
+
+ - name: Install dependencies
+ run: pnpm install --frozen-lockfile
+
+ - name: Lint backend
+ run: pnpm --filter @plutonhq/core-backend lint
+
+ - name: Test backend
+ run: pnpm --filter @plutonhq/core-backend test
+
+ - name: Build backend
+ run: pnpm --filter @plutonhq/core-backend build
diff --git a/package.json b/package.json
index e8ffd11..a66d87a 100644
--- a/package.json
+++ b/package.json
@@ -4,6 +4,8 @@
"description": "Pluton - Open Source Backup Software",
"license": "Apache-2.0",
"scripts": {
+ "prepare": "pnpm run setup:hooks",
+ "setup:hooks": "node ./scripts/setup-git-hooks.js",
"build": "turbo run build",
"build:executables": "node ./scripts/build-executables.js",
"build:appimage:local": "wsl -e bash -c \"cd /mnt/f/JS/apps/pluton/codebase/pluton-app/pluton/installers/linux && ./build-appimage.sh all pluton\"",
diff --git a/scripts/setup-git-hooks.js b/scripts/setup-git-hooks.js
new file mode 100644
index 0000000..3d57106
--- /dev/null
+++ b/scripts/setup-git-hooks.js
@@ -0,0 +1,34 @@
+#!/usr/bin/env node
+
+const { existsSync, chmodSync } = require("fs");
+const { spawnSync } = require("child_process");
+
+if (!existsSync(".git")) {
+ console.log("[hooks] Skipped: not a git checkout.");
+ process.exit(0);
+}
+
+const result = spawnSync(
+ "git",
+ ["config", "--local", "core.hooksPath", ".githooks"],
+ {
+ stdio: "inherit",
+ },
+);
+
+if (result.status !== 0) {
+ console.log(
+ "[hooks] Failed to configure core.hooksPath. Run manually: git config --local core.hooksPath .githooks",
+ );
+ process.exit(result.status || 1);
+}
+
+try {
+ if (existsSync(".githooks/pre-push")) {
+ chmodSync(".githooks/pre-push", 0o755);
+ }
+} catch {
+ // ignore on filesystems that do not support chmod
+}
+
+console.log("[hooks] Configured git hooks path to .githooks");