🐛 fix(stats): switch badges to self-hosted svg
Ubuntu System Information / show-system-info (push) Successful in 0s
Ubuntu System Information / show-system-info (push) Successful in 0s
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
#!/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"
|
||||
@@ -199,6 +199,27 @@ test_stats_workflow_avoids_eval_find() {
|
||||
grep -q 'LANG_FIND_ARGS=()' "${file}" || fail "stats workflow should build language-specific find arguments via arrays"
|
||||
}
|
||||
|
||||
test_stats_workflow_uses_svg_badges() {
|
||||
local file workflow_doc
|
||||
|
||||
file="${REPO_ROOT}/.gitea/workflows/update_stats_badge.yaml"
|
||||
workflow_doc="${REPO_ROOT}/WORKFLOW.md"
|
||||
|
||||
grep -q 'total-lines.svg' "${file}" || fail "stats workflow should generate total-lines.svg"
|
||||
grep -q 'total-files.svg' "${file}" || fail "stats workflow should generate total-files.svg"
|
||||
grep -q 'language-count.svg' "${file}" || fail "stats workflow should generate language-count.svg"
|
||||
grep -Fq '{language}-lines.svg' "${file}" || fail "stats workflow should describe per-language svg badges"
|
||||
grep -q '/src/branch/${{ env.BADGE_BRANCH }}/README.md' "${file}" || fail "stats workflow summary should link to stats branch root README"
|
||||
! rg -q '/src/branch/\$\{\{ env.BADGE_BRANCH \}\}/\$\{\{ env.BADGE_DIR \}\}/README\.md' "${file}" || fail "stats workflow should not place README.md under the badge directory"
|
||||
! rg -q 'img\.shields\.io/endpoint' "${file}" || fail "stats workflow should not depend on Shields endpoint badges"
|
||||
! rg -q 'total-lines\.json|total-files\.json|\$\{lang_id\}-lines\.json|\$\{lang_id\}-files\.json' "${file}" || fail "stats workflow should not generate json badge payloads"
|
||||
! rg -q 'GitHub Actions' "${file}" || fail "stats workflow should not mention GitHub Actions"
|
||||
grep -q 'Gitea Actions' "${file}" || fail "stats workflow should mention Gitea Actions in generated content"
|
||||
|
||||
grep -q 'badges/cpp-lines.svg' "${workflow_doc}" || fail "WORKFLOW.md should show svg badge usage examples"
|
||||
! rg -q 'img\.shields\.io/endpoint|cpp-lines\.json' "${workflow_doc}" || fail "WORKFLOW.md should not document json endpoint badge usage"
|
||||
}
|
||||
|
||||
test_entrypoint_uses_platform_aware_multiarch_verification() {
|
||||
local file
|
||||
|
||||
@@ -226,6 +247,7 @@ test_register_requires_python_yaml_path
|
||||
test_setup_requires_upgrade_helper
|
||||
test_entrypoint_uses_shared_buildx_builder_creation
|
||||
test_stats_workflow_avoids_eval_find
|
||||
test_stats_workflow_uses_svg_badges
|
||||
test_entrypoint_uses_platform_aware_multiarch_verification
|
||||
|
||||
echo "template_defaults_test.sh: PASS"
|
||||
|
||||
Reference in New Issue
Block a user