feat: consolidate auto-issue into ci.yml with if: failure()
- Replace workflow_run with same-workflow conditional job - Add create_failure_issue.py script for Gitea API integration - More reliable than cross-workflow triggers Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -17,3 +17,20 @@ jobs:
|
||||
|
||||
- name: Run tests
|
||||
run: python -m pytest tests/ -v
|
||||
|
||||
create-issue-on-failure:
|
||||
runs-on: shell
|
||||
needs: test
|
||||
if: failure()
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Create failure issue
|
||||
shell: bash
|
||||
run: |
|
||||
python scripts/create_failure_issue.py \
|
||||
--sha "${{ github.sha }}" \
|
||||
--branch "${{ github.ref_name }}" \
|
||||
--run "${{ github.run_number }}" \
|
||||
--message "${{ github.event.head_commit.message }}" \
|
||||
--api-token "${{ secrets.GITEA_TOKEN }}"
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
"""Create a Gitea issue when CI fails. Called from ci.yml on failure."""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
|
||||
GITEA_URL = "http://localhost:3000"
|
||||
REPO = "pzhang_zywl/document_analyzer"
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--sha", required=True)
|
||||
parser.add_argument("--branch", required=True)
|
||||
parser.add_argument("--run", required=True)
|
||||
parser.add_argument("--message", required=True)
|
||||
parser.add_argument("--api-token", required=True)
|
||||
args = parser.parse_args()
|
||||
|
||||
sha_short = args.sha[:7]
|
||||
run_url = f"{GITEA_URL}/{REPO}/actions/runs/{args.run}"
|
||||
|
||||
title = f"CI Failure: {args.message[:80]}"
|
||||
body = (
|
||||
f"## CI 测试失败\n\n"
|
||||
f"- **Commit:** {sha_short}\n"
|
||||
f"- **Branch:** {args.branch}\n"
|
||||
f"- **工作流运行:** {run_url}\n\n"
|
||||
f"请检查上述链接查看失败详情。\n\n"
|
||||
f"### 下一步\n"
|
||||
f"- [ ] 分析失败原因\n"
|
||||
f"- [ ] 修复代码\n"
|
||||
f"- [ ] 提交 PR 触发 CI 重测"
|
||||
)
|
||||
|
||||
payload = json.dumps({
|
||||
"title": title,
|
||||
"body": body,
|
||||
"labels": ["ci-failure", "agent-task"],
|
||||
}).encode("utf-8")
|
||||
|
||||
url = f"{GITEA_URL}/api/v1/repos/{REPO}/issues"
|
||||
req = urllib.request.Request(url, data=payload, method="POST")
|
||||
req.add_header("Authorization", f"token {args.api_token}")
|
||||
req.add_header("Content-Type", "application/json")
|
||||
|
||||
try:
|
||||
with urllib.request.urlopen(req) as resp:
|
||||
data = json.loads(resp.read())
|
||||
print(f"Issue created: {data.get('html_url', data.get('url', 'unknown'))}")
|
||||
except urllib.error.HTTPError as e:
|
||||
print(f"Failed to create issue: {e.code} {e.reason}")
|
||||
print(e.read().decode())
|
||||
raise
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user