From 87206f75003316b185ac85769d8226501aa4a5bd Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Thu, 8 Dec 2022 21:05:53 -0300 Subject: aux/: Embed files in repository --- aux/ci/report.sh | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100755 aux/ci/report.sh (limited to 'aux/ci') diff --git a/aux/ci/report.sh b/aux/ci/report.sh new file mode 100755 index 0000000..21cc54e --- /dev/null +++ b/aux/ci/report.sh @@ -0,0 +1,158 @@ +#!/bin/sh +set -eu + +TLD="$(cat aux/tld.txt)" +. aux/lib.sh + + +usage() { + cat <<-'EOF' + Usage: + aux/ci/report.sh -n NAME -o OUTDIR + aux/ci/report.sh -h + EOF +} + +help() { + cat <<-'EOF' + + + Options: + -n NAME the lowercase name of the project + -o OUTDIR directory where to write the files + -h, --help show this message + + + Generate static HTML files CI report from data stored in git + notes. The metadata about the CI runs are stored in the ref + "refs/notes/ci-data", in the format described by + "aux/ci/run.sh", and the raw logs are stored under the ref + "refs/notes/ci-logs". + + + Examples: + + Generate report for project "myapp" in "public/ci/": + + $ sh aux/ci/report.sh -n myapp -o public/ci + EOF +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 'n:o:h' flag; do + case "$flag" in + n) + NAME="$OPTARG" + ;; + o) + OUTDIR="$OPTARG" + ;; + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + + +eval "$(assert_arg "${NAME:-}" '-n NAME')" +eval "$(assert_arg "${OUTDIR:-}" '-o OUTDIR')" + +PASS='✅' +FAIL='❌' + +mkdir -p "$OUTDIR"/logs "$OUTDIR"/data + +for c in $(git notes list | cut -d' ' -f2); do + DATA="$(git notes --ref=refs/notes/ci-data show "$c")" + FILENAME="$(echo "$DATA" | cut -d' ' -f2)" + echo "$DATA" > "$OUTDIR/data/$FILENAME" + git notes --ref=refs/notes/ci-logs show "$c" \ + > "$OUTDIR/logs/$FILENAME" +done + +{ + cat <<-EOF + + + + + + + + $NAME - CI logs + + + + + + +
+

+ CI logs for + $NAME +

+
    + EOF + + for f in $(find "$OUTDIR/data/" -type f | LANG=C.UTF-8 sort -r); do + DATA="$(cat "$f")" + STATUS="$(echo "$DATA" | cut -d\ -f1)" + FILENAME="$(echo "$DATA" | cut -d\ -f2)" + + if [ "$STATUS" = 0 ]; then + STATUS_MARKER="$PASS" + else + STATUS_MARKER="$FAIL" + fi + + cat <<-EOF +
  1. + $STATUS_MARKER
    $FILENAME
    +
  2. + EOF + done + + cat <<-EOF +
+
+ + + EOF +} > "$OUTDIR"/index.html.tmp + +mv "$OUTDIR"/index.html.tmp "$OUTDIR"/index.html -- cgit v1.3