Files
gitea-ci-library/scripts/ci-report.sh
T
niko 2bef079d03
CI Main / Load example-gitea-env.conf to pipeline env (push) Successful in 22s
CI Main / Check existing artifact (push) Successful in 18s
acc-tests Cucumber test report
unit-tests Bats test report
CI Main / Cucumber tests (push) Successful in 1m25s
CI Main / Bats tests (push) Successful in 1m26s
ci-docker-build-push Docker build & push 0.2.19 OK
CI Main / Build & Push Docker (push) Successful in 47s
CI Main / Report Summary (push) Successful in 6s
CI Main / Move provider version tag (push) Successful in 16s
Fix/ci kontin no internet vaatimus (#34)
Co-authored-by: moilanik <niko.moilanen@tietoevry.com>
Reviewed-on: #34
2026-06-20 14:36:42 +03:00

111 lines
3.2 KiB
Bash

#!/usr/bin/env sh
set -eu
DESCRIPTION="${1:-}"
CONTEXT="${2:-}"
SUITE="${3:-}"
STATUS="${4:-success}"
[ -n "$DESCRIPTION" ] || { echo "ERROR: description argument required" >&2; exit 1; }
[ -n "$CONTEXT" ] || { echo "ERROR: context argument required" >&2; exit 1; }
[ -n "$SUITE" ] || { echo "ERROR: suite argument required" >&2; exit 1; }
REPORT_DIR="reports/${SUITE}"
if [ ! -d "$REPORT_DIR" ]; then
echo "ERROR: $REPORT_DIR not found" >&2
sh .ci/scripts/report-status.sh failure "$DESCRIPTION" "$CONTEXT"
exit 1
fi
FILE_COUNT=0
SUBDIR_COUNT=0
ENTRIES=""
for f in "$REPORT_DIR"/*; do
[ -f "$f" ] || continue
base=$(basename "$f")
[ "$base" = "index.html" ] && continue
FILE_COUNT=$((FILE_COUNT + 1))
ENTRIES="${ENTRIES}file:${base}
"
done
for d in "$REPORT_DIR"/*/; do
[ -d "$d" ] || continue
base=$(basename "$d")
[ -f "$d/index.html" ] || continue
SUBDIR_COUNT=$((SUBDIR_COUNT + 1))
ENTRIES="${ENTRIES}dir:${base}
"
done
TOTAL=$((FILE_COUNT + SUBDIR_COUNT))
if [ "$TOTAL" -eq 0 ]; then
echo "ERROR: no reportable items in $REPORT_DIR" >&2
sh .ci/scripts/report-status.sh failure "$DESCRIPTION" "$CONTEXT"
exit 1
fi
SHA8=$(echo "${GITHUB_SHA:-xxxxxxxx}" | cut -c1-8)
humanize() {
name="$1"
name=$(echo "$name" | sed -e 's/\.[^.]*$//' -e 's/[-_]/ /g')
first=$(echo "$name" | cut -c1 | tr '[:lower:]' '[:upper:]')
rest=$(echo "$name" | cut -c2-)
echo "${first}${rest}"
}
generate_index() {
{
echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">'
echo "<title>$DESCRIPTION</title>"
echo '<style>body{font-family:sans-serif;margin:2em;max-width:960px}h1{color:#1e293b}ul{list-style:none;padding:0}li{margin:.5em 0;padding:.5em;background:#f8fafc;border-radius:6px}a{color:#2563eb;text-decoration:none}a:hover{text-decoration:underline}</style>'
echo "</head><body><h1>$DESCRIPTION</h1><ul>"
echo "$ENTRIES" | while IFS= read -r entry; do
[ -z "$entry" ] && continue
entry_type=$(echo "$entry" | cut -d: -f1)
entry_name=$(echo "$entry" | cut -d: -f2-)
if [ "$entry_type" = "file" ]; then
echo "<li><a href=\"$entry_name\">$(humanize "$entry_name")</a></li>"
else
cap=$(echo "$entry_name" | sed 's/\(.\).*/\1/' | tr '[:lower:]' '[:upper:]')$(echo "$entry_name" | sed 's/.//')
echo "<li><a href=\"$entry_name/index.html\">${cap}</a></li>"
fi
done
echo '</ul></body></html>'
} > "$REPORT_DIR/index.html"
}
STAGED="reports/${SHA8}/${SUITE}"
mkdir -p "$STAGED"
if [ "$TOTAL" -eq 1 ]; then
cp -a "$REPORT_DIR/." "$STAGED/"
sh .ci/scripts/publish-git-pages.sh "$SUITE"
first_entry=$(echo "$ENTRIES" | head -1)
first_type=$(echo "$first_entry" | cut -d: -f1)
first_name=$(echo "$first_entry" | cut -d: -f2-)
if [ "$first_type" = "file" ]; then
SINGLE_ENTRY="$first_name"
else
SINGLE_ENTRY="${first_name}/index.html"
fi
URL="${GIT_PAGES_URL}/${GITHUB_REPOSITORY}/reports/${SHA8}/${SUITE}/${SINGLE_ENTRY}"
sh .ci/scripts/report-status.sh "$STATUS" "$DESCRIPTION" "$CONTEXT" "" "$URL"
else
generate_index
cp -a "$REPORT_DIR/." "$STAGED/"
sh .ci/scripts/publish-git-pages.sh "$SUITE"
sh .ci/scripts/report-status.sh "$STATUS" "$DESCRIPTION" "$CONTEXT" "$SUITE"
fi
rm -rf "$STAGED"