diff --git a/scripts/ci-finalize-badges.sh b/scripts/ci-finalize-badges.sh index 1a69ad9..9707ba4 100755 --- a/scripts/ci-finalize-badges.sh +++ b/scripts/ci-finalize-badges.sh @@ -54,7 +54,12 @@ for badge in $expected; do exit 1 } done -actual_count=$(find coverage -maxdepth 1 -name '*.svg' | wc -l) +actual_count=0 +for candidate in coverage/*.svg; do + if [ -e "$candidate" ] || [ -L "$candidate" ]; then + actual_count=$((actual_count + 1)) + fi +done [ "$actual_count" -eq 3 ] || { echo "expected exactly three SVG badges, found $actual_count" >&2 exit 1 diff --git a/scripts/test-ci.sh b/scripts/test-ci.sh index 9fe28c6..ca40d10 100755 --- a/scripts/test-ci.sh +++ b/scripts/test-ci.sh @@ -22,6 +22,25 @@ assert_fails() { fi } +file_mode() { + if stat -c '%a' "$1" >/dev/null 2>&1; then + stat -c '%a' "$1" + else + stat -f '%Lp' "$1" + fi +} + +svg_count() { + directory=$1 + count=0 + for candidate in "$directory"/*.svg; do + if [ -e "$candidate" ] || [ -L "$candidate" ]; then + count=$((count + 1)) + fi + done + printf '%s\n' "$count" +} + renderer="$repository/scripts/ci-coverage-badges.sh" render_dir="$workspace/render" mkdir "$render_dir" @@ -153,7 +172,7 @@ assert_contains "$finalize_work/coverage/coverage.svg" '#9f9f9f' assert_contains "$finalize_work/coverage/test.svg" 'passing' assert_contains "$finalize_work/coverage/version.svg" '1.2.3' [ ! -e "$finalize_work/coverage/.tests-passed-local" ] || fail 'test marker survived finalization' -[ "$(find "$finalize_work/coverage" -maxdepth 1 -name '*.svg' | wc -l)" -eq 3 ] \ +[ "$(svg_count "$finalize_work/coverage")" -eq 3 ] \ || fail 'finalization did not leave exactly three SVG files' printf 'fresh measurement\n' >"$finalize_work/coverage/coverage.svg" @@ -178,11 +197,11 @@ done "$repository/scripts/ci-publish-badges.sh" "$publish_root" MadGobblins fader_master main coverage test version ) destination="$publish_root/MadGobblins/fader_master/main" -[ "$(stat -c '%a' "$publish_root/MadGobblins")" = 755 ] || fail 'owner mode is not 0755' -[ "$(stat -c '%a' "$publish_root/MadGobblins/fader_master")" = 755 ] || fail 'project mode is not 0755' -[ "$(stat -c '%a' "$destination")" = 755 ] || fail 'branch mode is not 0755' +[ "$(file_mode "$publish_root/MadGobblins")" = 755 ] || fail 'owner mode is not 0755' +[ "$(file_mode "$publish_root/MadGobblins/fader_master")" = 755 ] || fail 'project mode is not 0755' +[ "$(file_mode "$destination")" = 755 ] || fail 'branch mode is not 0755' for badge_name in coverage test version; do - [ "$(stat -c '%a' "$destination/$badge_name.svg")" = 644 ] || fail "$badge_name mode is not 0644" + [ "$(file_mode "$destination/$badge_name.svg")" = 644 ] || fail "$badge_name mode is not 0644" done assert_fails sh -c "cd '$publish_work' && '$repository/scripts/ci-publish-badges.sh' '$publish_root' MadGobblins fader_master main coverage coverage"