Files
eSIM-Tools/.github/workflows/prune-workflows.yml
Abner 1b36a7e1c1 feat: 新增完整的 GitHub Actions 工作流自动化系统
- 添加质量守卫工作流,负责代码推送时的质量检查、安全扫描、单元测试和构建验证
- 实现 CI 自动修复工作流,当质量检查失败时自动尝试重新运行各项检查
- 引入质量自动改进工作流,检测评级不足时自动应用代码格式化和 ESLint 修复
- 建立清理工作流历史定时任务,自动删除三天前的工作流运行记录和附件
- 设计智能评分机制,根据各项检查结果计算综合质量分数并生成评级报告
- 集成 Artifacts 管理,自动上传质量报告、修复结果和改进补丁供后续分析使用
2025-11-24 20:13:33 +08:00

78 lines
2.7 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: 清理旧工作流历史
on:
schedule:
- cron: '30 4 * * *'
workflow_dispatch:
permissions:
actions: write
contents: read
jobs:
prune:
runs-on: ubuntu-latest
steps:
- name: 删除 3 天前的工作流运行与附件
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const retentionMs = 3 * 24 * 60 * 60 * 1000;
const cutoff = Date.now() - retentionMs;
core.info(`开始清理 ${owner}/${repo} 中早于 ${new Date(cutoff).toISOString()} 的工作流 run`);
const runs = await github.paginate(github.rest.actions.listWorkflowRunsForRepo, {
owner,
repo,
per_page: 100,
status: 'completed'
});
let deleted = 0;
for (const run of runs) {
const runTime = new Date(run.created_at).getTime();
if (runTime >= cutoff) continue;
core.info(`删除 run #${run.id} (${run.name}) - 创建时间 ${run.created_at}`);
try {
await github.rest.actions.deleteWorkflowRun({ owner, repo, run_id: run.id });
deleted++;
} catch (error) {
core.warning(`删除 run #${run.id} 失败:${error.message}`);
}
}
if (deleted === 0) {
core.info('没有需要清理的 run历史保持良好状态喵。');
} else {
core.info(`共删除 ${deleted} 条运行记录。`);
}
core.info('继续检查旧的 artifact...');
const artifacts = await github.paginate(github.rest.actions.listArtifactsForRepo, {
owner,
repo,
per_page: 100
});
let deletedArtifacts = 0;
for (const artifact of artifacts) {
const created = new Date(artifact.created_at).getTime();
if (created >= cutoff) continue;
core.info(`删除 artifact #${artifact.id} (${artifact.name}) - 创建时间 ${artifact.created_at}`);
try {
await github.rest.actions.deleteArtifact({ owner, repo, artifact_id: artifact.id });
deletedArtifacts++;
} catch (error) {
core.warning(`删除 artifact #${artifact.id} 失败:${error.message}`);
}
}
if (deletedArtifacts === 0) {
core.info('旧 artifact 无需清理,仓库保持清爽~');
} else {
core.info(`共删除 ${deletedArtifacts} 个 artifact。`);
}