Files
niko bd6ed5c2c2
CI Gitea Reports Main / Config load (push) Successful in 17s
CI Main / Config load (push) Successful in 20s
CI Gitea Reports Main / Latest version (push) Successful in 17s
CI Main / Latest versio (push) Successful in 19s
ci-helm-build-push Helm push 0.2.0
CI Gitea Reports Main / Build & Push Helm chart (push) Successful in 33s
gitops/gitea-ci-library/gitea-reports GitOps: gitea-reports 0.2.0
CI Gitea Reports Main / GitOps (push) Successful in 33s
CI Gitea Reports Main / Report Summary (push) Successful in 3s
CI Main / Bats tests (push) Failing after 1m16s
CI Main / Cucumber tests (push) Failing after 1m22s
CI Main / Build & Push Docker (push) Has been skipped
CI Main / GitOps (push) Has been skipped
CI Main / Move provider version tag (push) Has been skipped
CI Main / Report Summary (push) Successful in 3s
Feature/git pages -> oma nginx perusteinen raporointipalvelu (#48)
Co-authored-by: moilanik <niko.moilanen@tietoevry.com>
Reviewed-on: #48
2026-06-28 09:10:10 +03:00

67 lines
1.9 KiB
Bash

#!/usr/bin/env bash
# Retention cleanup: read PV directly, no git-pages API.
# Removes old commit-level report dirs based on branch existence + age rules.
set -euo pipefail
DATA_ROOT="${DATA_ROOT:-/app/data}"
CONFIG="${RETENTION_CONFIG:-/etc/retention/retention.json}"
GITEA_API_URL="${GITEA_API_URL:-}"
GITEA_TOKEN="${GITEA_TOKEN:-}"
[ -f "$CONFIG" ] || { echo "ERROR: config missing: $CONFIG" >&2; exit 1; }
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/retention-lib.sh"
DELETED_COUNT=0
ERROR_COUNT=0
for owner_dir in "$DATA_ROOT"/*/; do
[ -d "$owner_dir" ] || continue
owner=$(basename "$owner_dir")
for repo_dir in "$owner_dir"*/; do
[ -d "$repo_dir" ] || continue
repo=$(basename "$repo_dir")
for branch_dir in "$repo_dir"*/; do
[ -d "$branch_dir" ] || continue
branch=$(basename "$branch_dir")
echo "=== ${owner}/${repo}/${branch} ==="
if ! branch_exists "$owner" "$repo" "$branch"; then
echo " Branch does not exist in Gitea -> DELETE ALL"
rm -rf "$branch_dir"
DELETED_COUNT=$((DELETED_COUNT + 1))
continue
fi
rules=$(jq -r ".branches.\"$branch\" // .branches.default" "$CONFIG")
keep_min=$(echo "$rules" | jq -r '.keepMin // 5')
min_age=$(echo "$rules" | jq -r '.minAgeDays // 7')
commits=$(ls -1t "$branch_dir" 2>/dev/null || true)
count=0
for sha8 in $commits; do
[ -d "$branch_dir/$sha8" ] || continue
count=$((count + 1))
[ "$count" -le "$keep_min" ] && continue
age=$(age_days_from_stat "$branch_dir/$sha8")
[ "$age" -lt "$min_age" ] && continue
echo " DELETE: ${owner}/${repo}/${branch}/${sha8} (age=${age}d, keepMin=${keep_min})"
rm -rf "$branch_dir/$sha8"
DELETED_COUNT=$((DELETED_COUNT + 1))
done
done
done
done
echo ""
echo "=== Summary ==="
echo " Deleted: ${DELETED_COUNT}"
echo " Errors: ${ERROR_COUNT}"