From f1f5946ac4072dffd6531610534afb6291ee85dc Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 7 Jul 2026 14:47:34 +0200 Subject: [PATCH] added setup-gittally-testserver.sh: example script for running a test server with a fake build, including configuration for manual UI/API smoke tests, and updated documentation --- docs/bootstrapping.md | 7 ++ docs/examples/setup-gittally-testserver.sh | 99 ++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100755 docs/examples/setup-gittally-testserver.sh diff --git a/docs/bootstrapping.md b/docs/bootstrapping.md index 01a7f93..8255af6 100644 --- a/docs/bootstrapping.md +++ b/docs/bootstrapping.md @@ -128,6 +128,13 @@ Until then, a Java runtime must be available on the host. ``` 5. For permanent operation, install the systemd user service described in [deployment.md](deployment.md). +## Example: Test Server with a Fake Build + +[examples/setup-gittally-testserver.sh](examples/setup-gittally-testserver.sh) starts a GitTally server against a scratch repository with a fake build — the setup used for the manual UI/API smoke tests during development. +It creates a local bare origin plus a `work` clone, commits a slow fake build script (live log output, demo report artifact) with a `pollInterval: 5s` config, and starts the server on port 18980. +No Gitea, no credentials, no Docker; `INSTALL_DIR`, `SERVER_PORT`, and `BUILD_SECONDS` can be overridden via environment variables. +While the server runs, push empty commits from the `work` clone to trigger builds; a commit message containing `[fail]` makes the build fail, and pushing a new branch exercises the new-origin-branch path. + ## Example: Self-Hosting GitTally [examples/setup-gittally-selfhost.sh](examples/setup-gittally-selfhost.sh) shows the full sequence as a runnable script: it sets up a GitTally instance that watches and builds GitTally itself. diff --git a/docs/examples/setup-gittally-testserver.sh b/docs/examples/setup-gittally-testserver.sh new file mode 100755 index 0000000..286e9c6 --- /dev/null +++ b/docs/examples/setup-gittally-testserver.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash +# Example: start a GitTally test server watching a scratch repository with a fake build. +# This is the setup used for the manual UI/API smoke tests during development: +# a local bare origin, a slow fake build with live log output and a demo report +# artifact, and a fast poll interval — no Gitea, no credentials, no Docker. +# +# Usage: +# ./docs/examples/setup-gittally-testserver.sh +# BUILD_SECONDS=5 SERVER_PORT=18981 ./docs/examples/setup-gittally-testserver.sh +# +# While the server runs, trigger builds by pushing from the "work" clone: +# git -C ~/gittally-testserver/work commit --allow-empty -m "trigger build" && git -C ~/gittally-testserver/work push +# A commit message containing "[fail]" makes the fake build fail; +# pushing a new branch exercises the new-origin-branch path. +set -euo pipefail + +INSTALL_DIR="${INSTALL_DIR:-$HOME/gittally-testserver}" +SERVER_PORT="${SERVER_PORT:-18980}" +export BUILD_SECONDS="${BUILD_SECONDS:-25}" # inherited by the build process at runtime + +DEV_CHECKOUT=$(git rev-parse --show-toplevel) + +# 1. Build the GitTally jar. +(cd "$DEV_CHECKOUT" && ./gradlew --console=plain build) +mkdir -p "$INSTALL_DIR" +JAR=$(ls "$DEV_CHECKOUT"/build/libs/gittally-*.jar | grep -v -- '-plain' | head -1) +cp "$JAR" "$INSTALL_DIR/gittally.jar" + +# 2. Scratch bare origin plus a "work" clone for triggering builds by pushing. +if [ ! -d "$INSTALL_DIR/origin.git" ]; then + git init --bare --quiet --initial-branch=main "$INSTALL_DIR/origin.git" +fi +if [ ! -d "$INSTALL_DIR/work/.git" ]; then + git clone --quiet "$INSTALL_DIR/origin.git" "$INSTALL_DIR/work" +fi + +# First run only: commit the fake build and the project config to the scratch repo. +if ! git -C "$INSTALL_DIR/work" rev-parse --quiet --verify HEAD >/dev/null; then + cat > "$INSTALL_DIR/work/fake-build.sh" <<'EOF' +#!/usr/bin/env bash +# Fake build: visible progress for the live log, then a demo report artifact. +# GitTally exports `branch`; BUILD_SECONDS is inherited from the server process. +set -euo pipefail +echo "fake build of branch ${branch:-unknown} at commit $(git rev-parse --short HEAD)" +if git log -1 --pretty=%s | grep -qF '[fail]'; then + echo "commit message requests a failing build" >&2 + exit 1 +fi +for i in $(seq 1 "${BUILD_SECONDS:-25}"); do + echo "build step $i of ${BUILD_SECONDS:-25}" + sleep 1 +done +mkdir -p build/reports/demo +printf '

Demo Report

branch %s, commit %s

\n' \ + "${branch:-unknown}" "$(git rev-parse --short HEAD)" > build/reports/demo/index.html +echo "fake build done" +EOF + chmod +x "$INSTALL_DIR/work/fake-build.sh" + cat > "$INSTALL_DIR/work/.gittally.yml" <<'EOF' +watcher: + pollInterval: 5s + +branches: + default: + cleanCommand: rm -rf build + buildCommand: ./fake-build.sh + artifactDirs: + - build/reports +EOF + git -C "$INSTALL_DIR/work" add fake-build.sh .gittally.yml + git -C "$INSTALL_DIR/work" commit --quiet -m "fake build setup" + git -C "$INSTALL_DIR/work" commit --quiet --allow-empty -m "kick-start build" + git -C "$INSTALL_DIR/work" push --quiet origin main +fi + +# 3. The watched clone; the server runs here. No `init` needed: the project config +# is committed, and without gitea.baseUrl/git.token no statuses are published. +if [ ! -d "$INSTALL_DIR/repo/.git" ]; then + git clone --quiet "$INSTALL_DIR/origin.git" "$INSTALL_DIR/repo" +fi +cd "$INSTALL_DIR/repo" +mkdir -p .git/gittally +cat > .git/gittally/.gittally.yml <