♻️ refactor(runner): simplify shell helpers and workflow scripts
This commit is contained in:
@@ -60,10 +60,12 @@ test_workflow_doc_describes_workspace_architecture() {
|
||||
|
||||
file="${REPO_ROOT}/WORKFLOW.md"
|
||||
|
||||
grep -q 'Git bare 镜像 + 工作副本' "${file}" || fail "WORKFLOW.md should explicitly describe the bare mirror plus worktree-style model"
|
||||
grep -q '共享仓库缓存' "${file}" || fail "WORKFLOW.md should describe the shared repository cache model"
|
||||
grep -q '独立工作副本' "${file}" || fail "WORKFLOW.md should describe isolated per-job work copies"
|
||||
grep -q '任务结束后' "${file}" || fail "WORKFLOW.md should mention cleanup after workflow completion"
|
||||
grep -Eq '^## .*运行模型' "${file}" || fail "WORKFLOW.md should include a run model section"
|
||||
grep -q 'bare' "${file}" || fail "WORKFLOW.md should describe the bare mirror model"
|
||||
grep -q '工作副本' "${file}" || fail "WORKFLOW.md should describe isolated work copies"
|
||||
grep -Eq '共享.*缓存|缓存.*共享' "${file}" || fail "WORKFLOW.md should describe the shared cache model"
|
||||
grep -Eq '并发|隔离' "${file}" || fail "WORKFLOW.md should mention concurrency or isolation tradeoffs"
|
||||
grep -Eq '结束后.*清理|清理.*工作副本' "${file}" || fail "WORKFLOW.md should mention cleanup after workflow completion"
|
||||
! rg -q 'bootstrap_workspace\.sh' "${file}" || fail "WORKFLOW.md should describe architecture rather than helper implementation"
|
||||
! rg -q '/data/git-mirrors|/home/workspace/jobs' "${file}" || fail "WORKFLOW.md should avoid implementation-specific workspace paths"
|
||||
}
|
||||
@@ -88,13 +90,13 @@ test_readme_has_project_intro_and_navigation() {
|
||||
|
||||
file="${REPO_ROOT}/README.md"
|
||||
|
||||
grep -q '^## 📖 项目简介$' "${file}" || fail "README.md should provide a project intro section"
|
||||
grep -q '^## 📂 文档导航$' "${file}" || fail "README.md should provide a document navigation section"
|
||||
grep -Eq '^## .*项目简介' "${file}" || fail "README.md should provide a project intro section"
|
||||
grep -Eq '^## .*文档导航' "${file}" || fail "README.md should provide a document navigation section"
|
||||
grep -q '\[DEPLOYMENT.md\](\./DEPLOYMENT.md)' "${file}" || fail "README.md should link to DEPLOYMENT.md"
|
||||
grep -q '\[WORKFLOW.md\](\./WORKFLOW.md)' "${file}" || fail "README.md should link to WORKFLOW.md"
|
||||
grep -q '具体部署步骤.*\[DEPLOYMENT.md\](\./DEPLOYMENT.md)' "${file}" || fail "README.md should delegate deployment details to DEPLOYMENT.md"
|
||||
! rg -q '^## 🚀 快速提示$' "${file}" || fail "README.md should not carry concrete deployment tip sections"
|
||||
! rg -q '^## ⚙️ 当前默认行为$' "${file}" || fail "README.md should not carry default behavior details"
|
||||
! rg -q 'docker compose (build|up|exec)' "${file}" || fail "README.md should stay high-level and leave compose commands to deployment docs"
|
||||
}
|
||||
|
||||
test_deployment_doc_stays_runner_focused() {
|
||||
@@ -152,6 +154,51 @@ test_preset_compose_supports_runner_identity_overrides() {
|
||||
fail "buildx arch preset should allow DEFAULT_RUNNER_LABEL override via env"
|
||||
}
|
||||
|
||||
test_register_requires_python_yaml_path() {
|
||||
local file
|
||||
|
||||
file="${REPO_ROOT}/docker-runner/common/register.sh"
|
||||
|
||||
! rg -q 'Python configuration failed, using basic sed' "${file}" || fail "register.sh should not fall back to basic sed when Python config fails"
|
||||
! rg -q 'Python3 not found, applying basic configuration' "${file}" || fail "register.sh should not continue with basic configuration when Python3 is missing"
|
||||
! rg -q "sed -i 's/capacity: 1/capacity: 4/g' config.yaml" "${file}" || fail "register.sh should not mutate config.yaml via sed fallback"
|
||||
grep -q "python3 << PYEOF" "${file}" || fail "register.sh should keep Python-based config generation"
|
||||
}
|
||||
|
||||
test_setup_requires_upgrade_helper() {
|
||||
local file
|
||||
|
||||
file="${REPO_ROOT}/docker-runner/common/setup.sh"
|
||||
|
||||
grep -q '^# shellcheck source=/dev/null$' "${file}" || fail "setup.sh should source upgrade.sh directly"
|
||||
grep -q '^source "\${UPGRADE_HELPER}"$' "${file}" || fail "setup.sh should require sourcing upgrade.sh"
|
||||
! grep -Fq 'if [ -f "${UPGRADE_HELPER}" ]; then' "${file}" || fail "setup.sh should not treat upgrade helper as optional"
|
||||
! rg -q 'declare -F resolve_latest_version_or_fallback' "${file}" || fail "setup.sh should not guard helper functions with declare -F"
|
||||
! rg -q 'declare -F validate_version' "${file}" || fail "setup.sh should not guard validate_version with declare -F"
|
||||
! rg -q 'declare -F validate_binary_arch_or_fail' "${file}" || fail "setup.sh should not guard binary validation with declare -F"
|
||||
}
|
||||
|
||||
test_entrypoint_uses_shared_buildx_builder_creation() {
|
||||
local file
|
||||
|
||||
file="${REPO_ROOT}/docker-runner/common/entrypoint.sh"
|
||||
|
||||
grep -q '^create_buildx_builder() {$' "${file}" || fail "entrypoint.sh should extract Buildx builder creation into a helper"
|
||||
grep -q '^ensure_buildx_builder() {$' "${file}" || fail "entrypoint.sh should extract Buildx builder selection into a helper"
|
||||
grep -q '^[[:space:]]*create_buildx_builder$' "${file}" || fail "entrypoint.sh should use shared builder creation during initial setup"
|
||||
grep -q '^[[:space:]]*ensure_buildx_builder$' "${file}" || fail "entrypoint.sh should use shared builder selection during reuse"
|
||||
}
|
||||
|
||||
test_stats_workflow_avoids_eval_find() {
|
||||
local file
|
||||
|
||||
file="${REPO_ROOT}/.gitea/workflows/update_stats_badge.yaml"
|
||||
|
||||
! rg -q 'eval "find ' "${file}" || fail "stats workflow should avoid eval when building find commands"
|
||||
grep -q 'EXCLUDE_FIND_ARGS=()' "${file}" || fail "stats workflow should build reusable find exclusion arrays"
|
||||
grep -q 'LANG_FIND_ARGS=()' "${file}" || fail "stats workflow should build language-specific find arguments via arrays"
|
||||
}
|
||||
|
||||
test_preset_compose_uses_env_for_instance
|
||||
test_workflows_do_not_hardcode_company_server
|
||||
test_stats_workflow_uses_workflow_secret_consistently
|
||||
@@ -164,5 +211,9 @@ test_deployment_doc_stays_runner_focused
|
||||
test_presets_define_expected_hostname
|
||||
test_preset_env_examples_exist
|
||||
test_preset_compose_supports_runner_identity_overrides
|
||||
test_register_requires_python_yaml_path
|
||||
test_setup_requires_upgrade_helper
|
||||
test_entrypoint_uses_shared_buildx_builder_creation
|
||||
test_stats_workflow_avoids_eval_find
|
||||
|
||||
echo "template_defaults_test.sh: PASS"
|
||||
|
||||
Reference in New Issue
Block a user