143 lines
7.7 KiB
Bash
143 lines
7.7 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
|
|
}
|
|
|
|
test_preset_compose_uses_env_for_instance() {
|
|
local file
|
|
|
|
for file in \
|
|
"${REPO_ROOT}/docker-runner/presets/standard-ubuntu-22/docker-compose.yml" \
|
|
"${REPO_ROOT}/docker-runner/presets/buildx-ubuntu-22/docker-compose.yml" \
|
|
"${REPO_ROOT}/docker-runner/presets/buildx-archlinux/docker-compose.yml"; do
|
|
grep -q 'GITEA_INSTANCE=${GITEA_INSTANCE}' "${file}" || fail "${file} should read GITEA_INSTANCE from env"
|
|
grep -q 'GITEA_TOKEN=${GITEA_TOKEN}' "${file}" || fail "${file} should read GITEA_TOKEN from env"
|
|
done
|
|
}
|
|
|
|
test_workflows_do_not_hardcode_company_server() {
|
|
! rg -q 'https://git\.mytsl\.cn' "${REPO_ROOT}/.gitea/workflows/changelog_and_release.yml" || fail "changelog workflow should not hardcode company server"
|
|
! rg -q 'https://git\.mytsl\.cn' "${REPO_ROOT}/.gitea/workflows/update_stats_badge.yaml" || fail "stats workflow should not hardcode company server"
|
|
}
|
|
|
|
test_stats_workflow_uses_workflow_secret_consistently() {
|
|
local file
|
|
|
|
file="${REPO_ROOT}/.gitea/workflows/update_stats_badge.yaml"
|
|
|
|
grep -q 'ACCESS_TOKEN: ${{ secrets.WORKFLOW }}' "${file}" || fail "stats workflow should read ACCESS_TOKEN from WORKFLOW secret"
|
|
! rg -q 'STATS_TOKEN' "${file}" || fail "stats workflow should not mention legacy STATS_TOKEN secret"
|
|
! rg -q 'GITHUB_TOKEN' "${file}" || fail "stats workflow should not mention GITHUB_TOKEN in token guidance"
|
|
}
|
|
|
|
test_workflow_docs_and_links_use_actual_paths() {
|
|
local workflow_doc stats_workflow release_workflow
|
|
|
|
workflow_doc="${REPO_ROOT}/WORKFLOW.md"
|
|
stats_workflow="${REPO_ROOT}/.gitea/workflows/update_stats_badge.yaml"
|
|
release_workflow="${REPO_ROOT}/.gitea/workflows/changelog_and_release.yml"
|
|
|
|
grep -q 'changelog_and_release.yml' "${workflow_doc}" || fail "WORKFLOW.md should mention changelog_and_release.yml"
|
|
grep -q 'update_stats_badge.yaml' "${workflow_doc}" || fail "WORKFLOW.md should mention update_stats_badge.yaml"
|
|
! rg -q 'changelog-and-release\.yml' "${workflow_doc}" || fail "WORKFLOW.md should not mention stale changelog-and-release.yml filename"
|
|
! rg -q 'update-stats-badge\.yml' "${workflow_doc}" || fail "WORKFLOW.md should not mention stale update-stats-badge.yml filename"
|
|
! rg -q 'update_stats_badge\.yml' "${workflow_doc}" || fail "WORKFLOW.md should not mention stale update_stats_badge.yml filename"
|
|
|
|
grep -q '/src/branch/${{ github.ref_name }}/.gitea/workflows/update_stats_badge.yaml' "${stats_workflow}" || fail "stats workflow summary should link to .gitea workflow path"
|
|
grep -q '/src/branch/${{ env.MAIN_BRANCH }}/.gitea/workflows/changelog_and_release.yml' "${release_workflow}" || fail "release workflow summary should link to .gitea workflow path"
|
|
! rg -q '/\\.github/workflows/' "${stats_workflow}" || fail "stats workflow should not link to .github/workflows"
|
|
! rg -q '/\\.github/workflows/' "${release_workflow}" || fail "release workflow should not link to .github/workflows"
|
|
}
|
|
|
|
test_workflow_doc_describes_workspace_architecture() {
|
|
local file
|
|
|
|
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"
|
|
! 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"
|
|
}
|
|
|
|
test_presets_do_not_mount_check_crlf_helper() {
|
|
! rg -q 'check_crlf\.sh:/data/check_crlf\.sh:ro' "${REPO_ROOT}/docker-runner/presets" || fail "preset compose files should not mount check_crlf helper into containers"
|
|
}
|
|
|
|
test_runner_data_is_gitignored() {
|
|
local path
|
|
|
|
for path in \
|
|
"docker-runner/presets/standard-ubuntu-22/runner-data/config.yaml" \
|
|
"docker-runner/presets/buildx-ubuntu-22/runner-data/config.yaml" \
|
|
"docker-runner/presets/buildx-archlinux/runner-data/config.yaml"; do
|
|
git -C "${REPO_ROOT}" check-ignore -q "${path}" || fail "${path} should be ignored as runtime runner data"
|
|
done
|
|
}
|
|
|
|
test_readme_has_project_intro_and_navigation() {
|
|
local file
|
|
|
|
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 -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"
|
|
}
|
|
|
|
test_deployment_doc_stays_runner_focused() {
|
|
local file
|
|
|
|
file="${REPO_ROOT}/DEPLOYMENT.md"
|
|
|
|
! rg -q '^## ⚙️ 默认行为$' "${file}" || fail "DEPLOYMENT.md should not carry generic default behavior sections"
|
|
! rg -q '/data/git-mirrors/<owner>/<repo>\.git' "${file}" || fail "DEPLOYMENT.md should not document workflow mirror paths"
|
|
! rg -q '/home/workspace/jobs/' "${file}" || fail "DEPLOYMENT.md should not document workflow temp workspace paths"
|
|
! rg -q 'bootstrap_workspace\.sh' "${file}" || fail "DEPLOYMENT.md should stay focused on runner deployment, not workflow helpers"
|
|
}
|
|
|
|
test_presets_define_expected_hostname() {
|
|
grep -q '^ hostname: ubuntu$' "${REPO_ROOT}/docker-runner/presets/standard-ubuntu-22/docker-compose.yml" || fail "standard preset should set hostname to ubuntu"
|
|
grep -q '^ hostname: ubuntu$' "${REPO_ROOT}/docker-runner/presets/buildx-ubuntu-22/docker-compose.yml" || fail "buildx ubuntu preset should set hostname to ubuntu"
|
|
grep -q '^ hostname: arch$' "${REPO_ROOT}/docker-runner/presets/buildx-archlinux/docker-compose.yml" || fail "buildx arch preset should set hostname to arch"
|
|
}
|
|
|
|
test_preset_env_examples_exist() {
|
|
local file
|
|
|
|
for file in \
|
|
"${REPO_ROOT}/docker-runner/presets/standard-ubuntu-22/.env.example" \
|
|
"${REPO_ROOT}/docker-runner/presets/buildx-ubuntu-22/.env.example" \
|
|
"${REPO_ROOT}/docker-runner/presets/buildx-archlinux/.env.example"; do
|
|
test -f "${file}" || fail "missing env example: ${file}"
|
|
grep -q '^GITEA_INSTANCE=https://git.mytsl.cn$' "${file}" || fail "${file} should include company default instance"
|
|
grep -q '^GITEA_TOKEN=$' "${file}" || fail "${file} should include empty token placeholder"
|
|
done
|
|
}
|
|
|
|
test_preset_compose_uses_env_for_instance
|
|
test_workflows_do_not_hardcode_company_server
|
|
test_stats_workflow_uses_workflow_secret_consistently
|
|
test_workflow_docs_and_links_use_actual_paths
|
|
test_workflow_doc_describes_workspace_architecture
|
|
test_presets_do_not_mount_check_crlf_helper
|
|
test_runner_data_is_gitignored
|
|
test_readme_has_project_intro_and_navigation
|
|
test_deployment_doc_stays_runner_focused
|
|
test_presets_define_expected_hostname
|
|
test_preset_env_examples_exist
|
|
|
|
echo "template_defaults_test.sh: PASS"
|