未验证 提交 67e9d8f6 编写于 作者: J jwithers 提交者: GitHub

Issue on error

New issue creation and updating mechanism for action error trapping.

On error creates a new issue with the tag ci:bot_issue if one doesn't exist. Places information about the script failing and run in the body.

If an issue with the script name in the body and the ci:bot_issue tag exists and is open, will update with a comment about the current failure.

Error trapping implemented for testing in generate_integration_tests.yml

BUG=https://issuetracker.google.com/issues/229828377
上级 036f60bf
......@@ -4,4 +4,4 @@ labels: bug
---
There was a failed test in the CI pipeline for [PR {{ env.PR_NUM }}]({{ env.PR_LINK }}). Please see comments in the PR for more details.
This issue has been automatically generated for notification purposes.
\ No newline at end of file
This issue automatically generated for notification purposes.
......@@ -33,10 +33,12 @@ jobs:
tensorflow/lite/micro/tools/ci_build/test_generate_integration_tests.sh
- name: error trapping
if: ${{ failure() }}
uses: JasonEtco/create-an-issue@v2
env:
WORKFLOW: ${{ github.workflow }}
RUN_NUMBER: ${{ github.run_number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
filename: .github/scheduled-error-template.md
TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
FLAG_LABEL: ci:bot_issue
run: |
pip3 install PyGithub
python3 ci/issue_on_error.py
# issue_on_error.py
# Requires python 3.6+, PyGithub
#
# Creates or updates an issue on action failure.
#
# Looks though REPO for open issues with FLAG_LABEL. If none,
# creates a new issue. If there is an open issue with FLAG_LABEL,
# looks for WORKFLOW in body. If none, creates an issue. If an
# issue for WORKFLOW exists, makes adds a comment.
#
# Requires the environment provide the variables in the block below.
# TOKEN must have access to update issues.
from github import Github
from datetime import datetime
import os
TOKEN = os.environ['TOKEN']
REPO = os.environ['REPO']
WORKFLOW = os.environ['WORKFLOW']
FLAG_LABEL = os.environ['FLAG_LABEL']
RUN_NUMBER = os.environ['RUN_NUMBER']
def get_tagged_issues(repo, flag_label, workflow):
issues = repo.get_issues(state='open', labels=[flag_label])
tagged_issues =[]
for issue in issues:
if workflow in issue.body:
tagged_issues.append(issue)
return(tagged_issues)
def create_issue(repo, flag_label, workflow, run_number):
body_string = f"{workflow} run number {run_number} failed.\n"
body_string += "Please examine the run itself for details.\n\n"
body_string += "This issue has been automatically generated for "
body_string += "notification purposes."
title_string = f"{workflow} Scheduled Run Failed"
new_issue = repo.create_issue(title = title_string, body = body_string,
labels=[flag_label])
return(new_issue)
def add_comment(issue, run_number):
dt_string = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
msg_string = "Error reoccurred: " + dt_string
msg_string += " run number: " + run_number
issue.create_comment(msg_string)
return()
if __name__ == "__main__":
g = Github(TOKEN)
repo = g.get_repo(REPO)
tagged_issues = get_tagged_issues(repo, FLAG_LABEL, WORKFLOW)
if not tagged_issues:
create_issue(repo, FLAG_LABEL, WORKFLOW, RUN_NUMBER)
else:
for issue in tagged_issues:
add_comment(issue, RUN_NUMBER)
for issue in tagged_issues:
print(issue.number)
print(issue.closed_at)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册