diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml new file mode 100644 index 0000000..ad2fe44 --- /dev/null +++ b/.gitea/workflows/test.yml @@ -0,0 +1,178 @@ +name: 网站测试和部署 + +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] + +jobs: + test: + runs-on: ubuntu-latest + name: 网站测试 + + steps: + - name: 检出代码 + uses: actions/checkout@v4 + + - name: 设置Node.js环境 + uses: actions/setup-node@v4 + with: + node-version: '18' + + - name: 安装HTML验证工具 + run: | + npm install -g html-validate + + - name: 检查文件结构 + run: | + echo "检查项目文件..." + ls -la + echo "检查HTML文件是否存在..." + if [ -f "index.html" ]; then + echo "✅ index.html 文件存在" + else + echo "❌ index.html 文件不存在" + exit 1 + fi + + - name: HTML语法验证 + run: | + echo "验证HTML语法..." + html-validate index.html || echo "HTML验证完成" + + - name: 检查HTML内容 + run: | + echo "检查HTML内容..." + if grep -q "KaGaMi" index.html; then + echo "✅ 页面包含正确的用户名" + else + echo "❌ 页面不包含用户名" + exit 1 + fi + + if grep -q "大学生" index.html; then + echo "✅ 页面包含身份信息" + else + echo "❌ 页面不包含身份信息" + exit 1 + fi + + - name: 检查页面标题 + run: | + echo "检查页面标题..." + if grep -q "KaGaMi的个人网站" index.html; then + echo "✅ 页面标题正确" + else + echo "❌ 页面标题不正确" + exit 1 + fi + + - name: 统计代码信息 + run: | + echo "代码统计信息:" + echo "HTML文件行数: $(wc -l < index.html)" + echo "HTML文件大小: $(du -h index.html | cut -f1)" + echo "项目总文件数: $(find . -type f | wc -l)" + + - name: 生成测试报告 + run: | + echo "生成测试报告..." + date > test-report.txt + echo "测试项目: KaGaMi个人网站" >> test-report.txt + echo "测试状态: 通过" >> test-report.txt + echo "HTML文件大小: $(du -h index.html | cut -f1)" >> test-report.txt + echo "测试时间: $(date)" >> test-report.txt + cat test-report.txt + + - name: 上传测试报告 + uses: actions/upload-artifact@v4 + with: + name: test-report + path: test-report.txt + retention-days: 30 + + deploy-test: + needs: test + runs-on: ubuntu-latest + name: 部署测试 + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' + + steps: + - name: 检出代码 + uses: actions/checkout@v4 + + - name: 模拟部署过程 + run: | + echo "开始模拟部署..." + mkdir -p deploy + cp index.html deploy/ + echo "部署文件列表:" + ls -la deploy/ + echo "✅ 部署模拟完成" + + - name: 验证部署结果 + run: | + echo "验证部署结果..." + if [ -f "deploy/index.html" ]; then + echo "✅ 部署文件存在" + else + echo "❌ 部署文件不存在" + exit 1 + fi + + - name: 生成部署报告 + run: | + echo "生成部署报告..." + date > deploy-report.txt + echo "部署项目: KaGaMi个人网站" >> deploy-report.txt + echo "部署状态: 成功" >> deploy-report.txt + echo "部署时间: $(date)" >> deploy-report.txt + echo "部署分支: ${{ github.ref_name }}" >> deploy-report.txt + cat deploy-report.txt + + - name: 上传部署报告 + uses: actions/upload-artifact@v4 + with: + name: deploy-report + path: deploy-report.txt + retention-days: 30 + + security-check: + runs-on: ubuntu-latest + name: 安全检查 + + steps: + - name: 检出代码 + uses: actions/checkout@v4 + + - name: 检查敏感信息 + run: | + echo "检查是否包含敏感信息..." + + # 检查是否有密码等敏感信息 + if grep -i "password\|secret\|key\|token" index.html; then + echo "⚠️ 发现可能的敏感信息,请检查" + else + echo "✅ 未发现敏感信息" + fi + + # 检查是否有恶意脚本 + if grep -i "script.*src.*http" index.html; then + echo "⚠️ 发现外部脚本引用,请检查" + else + echo "✅ 未发现外部脚本引用" + fi + + - name: 内容合规检查 + run: | + echo "检查内容合规性..." + + # 检查是否包含正面内容 + if grep -q "学习\|成长\|积极" index.html; then + echo "✅ 内容积极向上" + else + echo "⚠️ 建议添加更多积极内容" + fi + + echo "✅ 安全检查完成" \ No newline at end of file