58 lines
2.5 KiB
Bash
58 lines
2.5 KiB
Bash
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
REPO_ROOT=$(cd "${SCRIPT_DIR}/.." && pwd)
|
|
|
|
fail() {
|
|
echo "FAIL: $*" >&2
|
|
exit 1
|
|
}
|
|
|
|
temp_root=$(mktemp -d)
|
|
lang_summary="${temp_root}/lang_summary.txt"
|
|
output_dir="${temp_root}/badges"
|
|
readme_path="${temp_root}/README.md"
|
|
|
|
cat > "${lang_summary}" <<'EOF'
|
|
python|Python|1200|1,200|12|3572A5|python
|
|
typescript|TypeScript|800|800|9|3178c6|typescript
|
|
yaml|YAML|120|120|5|CB171E|
|
|
EOF
|
|
|
|
python3 "${REPO_ROOT}/.gitea/ci/render_stats_svgs.py" \
|
|
--output-dir "${output_dir}" \
|
|
--readme-path "${readme_path}" \
|
|
--repo "csh/actions-template" \
|
|
--generated-by "Gitea Actions" \
|
|
--updated-at "2026-05-22 12:00:00 UTC" \
|
|
--total-code 2120 \
|
|
--formatted-total-code "2,120" \
|
|
--total-files 26 \
|
|
--formatted-total-files "26" \
|
|
--language-count 3 \
|
|
--exclude-dirs "node_modules,dist,.git" \
|
|
--min-lines-threshold 10 \
|
|
--lang-summary "${lang_summary}"
|
|
|
|
test -f "${output_dir}/total-lines.svg" || fail "renderer should create total-lines.svg"
|
|
test -f "${output_dir}/total-files.svg" || fail "renderer should create total-files.svg"
|
|
test -f "${output_dir}/language-count.svg" || fail "renderer should create language-count.svg"
|
|
test -f "${output_dir}/python-lines.svg" || fail "renderer should create per-language svg badges"
|
|
test -f "${readme_path}" || fail "renderer should create root README.md"
|
|
|
|
grep -q '<svg' "${output_dir}/total-lines.svg" || fail "svg badges should contain svg markup"
|
|
grep -q '2,120' "${output_dir}/total-lines.svg" || fail "total-lines badge should include formatted total code"
|
|
grep -q 'Python' "${output_dir}/python-lines.svg" || fail "language badge should include display name"
|
|
grep -q '\./badges/total-lines.svg' "${readme_path}" || fail "README should reference badges via relative svg paths"
|
|
grep -q '\./badges/python-lines.svg' "${readme_path}" || fail "README should reference language badges via relative svg paths"
|
|
grep -q 'Gitea Actions' "${readme_path}" || fail "README should mention Gitea Actions"
|
|
grep -q '此分支由 Gitea Actions 自动生成和维护' "${readme_path}" || fail "README should explain that stats branch is generated"
|
|
grep -q '请勿手动修改此分支的内容' "${readme_path}" || fail "README should warn against manual edits"
|
|
! grep -q 'GitHub Actions' "${readme_path}" || fail "README should not mention GitHub Actions"
|
|
! find "${temp_root}" -name '*.json' | grep -q . || fail "renderer should not create json badge payloads"
|
|
|
|
rm -rf "${temp_root}"
|
|
|
|
echo "stats_svg_render_test.sh: PASS"
|