From bfd0428a78298331dae98c3703e5b0106c99e280 Mon Sep 17 00:00:00 2001 From: moilanik Date: Sat, 20 Jun 2026 13:06:02 +0300 Subject: [PATCH] bash -> sh --- scripts/ci-report.sh | 105 +++++++++++++++++++++-------------- scripts/publish-git-pages.sh | 60 +++++++++++++------- scripts/report-status.sh | 12 ++-- 3 files changed, 109 insertions(+), 68 deletions(-) diff --git a/scripts/ci-report.sh b/scripts/ci-report.sh index e509ba6..4299283 100644 --- a/scripts/ci-report.sh +++ b/scripts/ci-report.sh @@ -1,5 +1,5 @@ -#!/usr/bin/env bash -set -euo pipefail +#!/usr/bin/env sh +set -eu DESCRIPTION="${1:-}" CONTEXT="${2:-}" @@ -14,53 +14,71 @@ REPORT_DIR="reports/${SUITE}" if [ ! -d "$REPORT_DIR" ]; then echo "ERROR: $REPORT_DIR not found" >&2 - bash .ci/scripts/report-status.sh failure "$DESCRIPTION" "$CONTEXT" + sh .ci/scripts/report-status.sh failure "$DESCRIPTION" "$CONTEXT" exit 1 fi -FILES=() -while IFS= read -r -d '' f; do - FILES+=("$(basename "$f")") -done < <(find "$REPORT_DIR" -maxdepth 1 -type f ! -name index.html -print0 2>/dev/null || true) +FILE_COUNT=0 +SUBDIR_COUNT=0 +ENTRIES="" -SUBDIRS=() -while IFS= read -r -d '' d; do - name="${d#$REPORT_DIR/}" - [ -f "$d/index.html" ] && SUBDIRS+=("$name") -done < <(find "$REPORT_DIR" -maxdepth 1 -type d ! -name . -print0 2>/dev/null || true) +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 -TOTAL=$(( ${#FILES[@]} + ${#SUBDIRS[@]} )) +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 - bash .ci/scripts/report-status.sh failure "$DESCRIPTION" "$CONTEXT" + sh .ci/scripts/report-status.sh failure "$DESCRIPTION" "$CONTEXT" exit 1 fi -SHA8="${GITHUB_SHA:0:8}" +SHA8=$(echo "${GITHUB_SHA:-xxxxxxxx}" | cut -c1-8) humanize() { - local name="$1" - name="${name%.*}" - name="${name//-/ }" - name="${name//_/ }" - echo "${name^}" + 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() { - local html - html='' - html+="$DESCRIPTION" - html+='' - html+="

$DESCRIPTION

' - printf '%s' "$html" > "$REPORT_DIR/index.html" + { + echo '' + echo "$DESCRIPTION" + echo '' + echo "

$DESCRIPTION

' + } > "$REPORT_DIR/index.html" } STAGED="reports/${SHA8}/${SUITE}" @@ -68,20 +86,25 @@ mkdir -p "$STAGED" if [ "$TOTAL" -eq 1 ]; then cp -a "$REPORT_DIR/." "$STAGED/" - bash .ci/scripts/publish-git-pages.sh "$SUITE" + sh .ci/scripts/publish-git-pages.sh "$SUITE" - if [ ${#FILES[@]} -eq 1 ]; then - ENTRY="${FILES[0]}" + 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 - ENTRY="${SUBDIRS[0]}/index.html" + SINGLE_ENTRY="${first_name}/index.html" fi - URL="${GIT_PAGES_URL}/${GITHUB_REPOSITORY}/reports/${SHA8}/${SUITE}/${ENTRY}" - bash .ci/scripts/report-status.sh "$STATUS" "$DESCRIPTION" "$CONTEXT" "" "$URL" + + 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/" - bash .ci/scripts/publish-git-pages.sh "$SUITE" - bash .ci/scripts/report-status.sh "$STATUS" "$DESCRIPTION" "$CONTEXT" "$SUITE" + sh .ci/scripts/publish-git-pages.sh "$SUITE" + sh .ci/scripts/report-status.sh "$STATUS" "$DESCRIPTION" "$CONTEXT" "$SUITE" fi rm -rf "$STAGED" diff --git a/scripts/publish-git-pages.sh b/scripts/publish-git-pages.sh index acee12c..4575bc1 100755 --- a/scripts/publish-git-pages.sh +++ b/scripts/publish-git-pages.sh @@ -1,5 +1,5 @@ -#!/usr/bin/env bash -set -euo pipefail +#!/usr/bin/env sh +set -eu SUITE_PATH="${1:-}" @@ -12,7 +12,7 @@ SUITE_PATH="${1:-}" OWNER="${GITHUB_REPOSITORY%%/*}" REPO="${GITHUB_REPOSITORY##*/}" -SHA8="${GITHUB_SHA:0:8}" +SHA8=$(echo "$GITHUB_SHA" | cut -c1-8) PAGES_USER="${GIT_PAGES_PUBLISH_USER:-publish}" REPORT_DIR="reports/${SHA8}/${SUITE_PATH%/}" REPORT_BASE="${GIT_PAGES_URL}/${OWNER}/${REPO}/reports/${SHA8}" @@ -33,17 +33,30 @@ else fi mkdir -p "$TARGET" cp -a "$REPORT_DIR/." "$TARGET/" -if [ ! -f "$TARGET/index.html" ]; then - items=() - while IFS= read -r -d '' f; do - items+=("$(basename "$f")") - done < <(find "$TARGET" -maxdepth 1 -type f ! -name index.html -print0 2>/dev/null || true) - while IFS= read -r -d '' d; do - name=$(basename "$d") - [ -f "$d/index.html" ] && items+=("$name") - done < <(find "$TARGET" -maxdepth 1 -type d ! -name . -print0 2>/dev/null || true) - if [ ${#items[@]} -gt 1 ]; then +if [ ! -f "$TARGET/index.html" ]; then + ITEM_LIST="" + ITEM_COUNT=0 + + for f in "$TARGET"/*; do + [ -f "$f" ] || continue + base=$(basename "$f") + [ "$base" = "index.html" ] && continue + ITEM_LIST="${ITEM_LIST}file:${base} +" + ITEM_COUNT=$((ITEM_COUNT + 1)) + done + + for d in "$TARGET"/*/; do + [ -d "$d" ] || continue + base=$(basename "$d") + [ -f "$d/index.html" ] || continue + ITEM_LIST="${ITEM_LIST}dir:${base} +" + ITEM_COUNT=$((ITEM_COUNT + 1)) + done + + if [ "$ITEM_COUNT" -gt 1 ]; then { echo '' echo "Test report ${SHA8}" @@ -53,16 +66,21 @@ if [ ! -f "$TARGET/index.html" ]; then echo 'a{color:#2563eb;text-decoration:none}a:hover{text-decoration:underline}' echo '' echo "

Test report ${SHA8}

' } > "$TARGET/index.html" fi @@ -74,7 +92,7 @@ EOF find "$WORK/$OWNER" \( -type f -o -type l \) -print | sed "s|^${WORK}/||" | tar -cf "$TAR" -C "$WORK" -T - publish() { - local method="$1" + method="$1" curl -sS -X "$method" "$PUBLISH_SITE_URL" \ -u "${PAGES_USER}:${GIT_PAGES_PUBLISH_TOKEN}" \ -H "Content-Type: application/x-tar" \ diff --git a/scripts/report-status.sh b/scripts/report-status.sh index 5d7f8c9..6c319ac 100755 --- a/scripts/report-status.sh +++ b/scripts/report-status.sh @@ -1,11 +1,10 @@ -#!/usr/bin/env bash -set -euo pipefail - -# https://docs.gitea.com/api/next/#tag/repository/operation/repoCreateStatus +#!/usr/bin/env sh +set -eu STATE="${1:-}" DESCRIPTION="${2:-}" -KEY="${3:-commit-${GITHUB_SHA:0:8}}" +SHA8=$(echo "${GITHUB_SHA:-}" | cut -c1-8) +KEY="${3:-commit-${SHA8}}" SUITE="${4:-}" CUSTOM_URL="${5:-}" @@ -18,7 +17,8 @@ if [ -n "$CUSTOM_URL" ]; then URL="$CUSTOM_URL" elif [ -n "$SUITE" ]; then SUITE="${SUITE%/}/" - URL="${GIT_PAGES_URL}/${GITHUB_REPOSITORY}/reports/${GITHUB_SHA:0:8}/${SUITE}" + SHA8_CUT=$(echo "$GITHUB_SHA" | cut -c1-8) + URL="${GIT_PAGES_URL}/${GITHUB_REPOSITORY}/reports/${SHA8_CUT}/${SUITE}" else URL="${GITEA_API_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" fi