f3abd42f17
CI Main / Config load (push) Successful in 23s
CI Gitea Reports Main / Config load (push) Successful in 23s
CI Gitea Reports Main / Latest version (push) Successful in 20s
CI Main / Latest versio (push) Successful in 21s
ci-helm-build-push Helm push 0.2.1
CI Gitea Reports Main / Build & Push Helm chart (push) Successful in 41s
unit-tests Bats test report
acc-tests Cucumber test report
CI Gitea Reports Main / Report Summary (push) Successful in 3s
ci-docker-build-push Docker push 0.2.36
CI Main / Build & Push Docker (push) Successful in 32s
CI Main / Report Summary (push) Successful in 3s
CI Main / Move provider version tag (push) Successful in 10s
gitops/gitea-ci-library/gitea-reports GitOps: gitea-reports 0.2.1
CI Gitea Reports Main / GitOps (push) Successful in 33s
CI Main / Cucumber tests (push) Successful in 1m25s
CI Main / Bats tests (push) Successful in 1m26s
gitops/gitea-ci-library GitOps: 0.2.36
CI Main / GitOps (push) Successful in 32s
Co-authored-by: moilanik <niko.moilanen@tietoevry.com> Reviewed-on: #49
118 lines
3.6 KiB
Bash
Executable File
118 lines
3.6 KiB
Bash
Executable File
#!/usr/bin/env sh
|
|
set -eu
|
|
|
|
SUITE_PATH="${1:-}"
|
|
|
|
[ -n "$SUITE_PATH" ] || { echo "ERROR: suite_path argument required" >&2; exit 1; }
|
|
[ -n "${GIT_PAGES_URL:-}" ] || { echo "ERROR: GIT_PAGES_URL is not set" >&2; exit 1; }
|
|
[ -n "${REPORTS_PUBLISH_TOKEN:-}" ] || { echo "ERROR: REPORTS_PUBLISH_TOKEN is not set" >&2; exit 1; }
|
|
[ -n "${GITHUB_REPOSITORY:-}" ] || { echo "ERROR: GITHUB_REPOSITORY is not set" >&2; exit 1; }
|
|
[ -n "${GITHUB_SHA:-}" ] || { echo "ERROR: GITHUB_SHA is not set" >&2; exit 1; }
|
|
[ -n "${GITHUB_REF_NAME:-}" ] || { echo "ERROR: GITHUB_REF_NAME is not set" >&2; exit 1; }
|
|
|
|
OWNER="${GITHUB_REPOSITORY%%/*}"
|
|
REPO="${GITHUB_REPOSITORY##*/}"
|
|
SHA8=$(echo "$GITHUB_SHA" | cut -c1-8)
|
|
BRANCH="${GITHUB_REF_NAME}"
|
|
SUITE="${SUITE_PATH%/}"
|
|
PAGES_USER="${GIT_PAGES_PUBLISH_USER:-publish}"
|
|
|
|
[ -d "$SUITE" ] || { echo "ERROR: not a directory: $SUITE" >&2; exit 1; }
|
|
|
|
EMPTY=1
|
|
for _f in "$SUITE"/* "$SUITE"/.*; do
|
|
[ -e "$_f" ] && { EMPTY=0; break; }
|
|
done
|
|
[ "$EMPTY" -eq 0 ] || { echo "ERROR: no files to publish in $SUITE" >&2; exit 1; }
|
|
|
|
WORK=$(mktemp -d)
|
|
TAR=$(mktemp)
|
|
trap 'rm -rf "$WORK" "$TAR"' EXIT
|
|
|
|
# Kopioi raporttitiedostot
|
|
mkdir -p "$WORK/$SUITE"
|
|
cp -a "$SUITE/." "$WORK/$SUITE/"
|
|
|
|
# Generoi index.html (sama logiikka kuin nykyään)
|
|
cd "$WORK/$SUITE"
|
|
if [ ! -f "index.html" ]; then
|
|
ITEM_LIST=""
|
|
ITEM_COUNT=0
|
|
|
|
for f in *; do
|
|
[ -f "$f" ] || continue
|
|
[ "$f" = "index.html" ] && continue
|
|
ITEM_LIST="${ITEM_LIST}file:${f}
|
|
"
|
|
ITEM_COUNT=$((ITEM_COUNT + 1))
|
|
done
|
|
|
|
for d in */; do
|
|
[ -d "$d" ] || continue
|
|
d="${d%/}"
|
|
[ -f "$d/index.html" ] || continue
|
|
ITEM_LIST="${ITEM_LIST}dir:${d}
|
|
"
|
|
ITEM_COUNT=$((ITEM_COUNT + 1))
|
|
done
|
|
|
|
if [ "$ITEM_COUNT" -gt 1 ]; then
|
|
{
|
|
echo '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">'
|
|
echo "<title>Test report ${SHA8}</title>"
|
|
echo '<style>body{font-family:sans-serif;margin:2em;max-width:960px}'
|
|
echo 'h1{color:#1e293b}ul{list-style:none;padding:0}'
|
|
echo 'li{margin:.5em 0;padding:.5em;background:#f8fafc;border-radius:6px}'
|
|
echo 'a{color:#2563eb;text-decoration:none}a:hover{text-decoration:underline}'
|
|
echo '</style></head><body>'
|
|
echo "<h1>Test report <code>${SHA8}</code></h1><ul>"
|
|
|
|
echo "$ITEM_LIST" | while IFS= read -r item; do
|
|
[ -z "$item" ] && continue
|
|
item_type=$(echo "$item" | cut -d: -f1)
|
|
item_name=$(echo "$item" | cut -d: -f2-)
|
|
label=$(echo "$item_name" | sed -e 's/\.[^.]*$//' -e 's/[-_]/ /g')
|
|
first=$(echo "$label" | cut -c1 | tr '[:lower:]' '[:upper:]')
|
|
rest=$(echo "$label" | cut -c2-)
|
|
if [ "$item_type" = "file" ]; then
|
|
echo "<li><a href=\"$item_name\">${first}${rest}</a></li>"
|
|
else
|
|
echo "<li><a href=\"$item_name/index.html\">${first}${rest}</a></li>"
|
|
fi
|
|
done
|
|
|
|
echo '</ul></body></html>'
|
|
} > "index.html"
|
|
fi
|
|
fi
|
|
|
|
# .meta tiedosto retentionia varten
|
|
cat > ".meta" <<EOF
|
|
{"branch":"${BRANCH}","sha":"${GITHUB_SHA}","published_at":"$(date -u +%Y-%m-%dT%H:%M:%SZ)"}
|
|
EOF
|
|
|
|
cd "$WORK"
|
|
|
|
# Pakkaa: pelkät tiedostot ilman $SUITE-etuliitettä
|
|
tar czf "$TAR" -C "$WORK/$SUITE" .
|
|
|
|
# PUT upload-sidecariin
|
|
PUBLISH_URL="${GIT_PAGES_URL}/${OWNER}/${REPO}/${BRANCH}/${SHA8}/${SUITE}/"
|
|
HTTP_CODE=$(curl -sS -X PUT "$PUBLISH_URL" \
|
|
-u "${PAGES_USER}:${REPORTS_PUBLISH_TOKEN}" \
|
|
-H "Content-Type: application/tar+gz" \
|
|
--data-binary @"$TAR" \
|
|
-o /tmp/git-pages-publish-response.txt \
|
|
-w "%{http_code}")
|
|
|
|
case "$HTTP_CODE" in
|
|
200|201|204) ;;
|
|
*)
|
|
echo "ERROR: publish HTTP ${HTTP_CODE}" >&2
|
|
cat /tmp/git-pages-publish-response.txt >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
echo "${PUBLISH_URL}"
|