Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/actions/testing_report_generation/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ inputs:
description: 'access token'
required: true
issue-labels:
description: 'Testing labels(delimited by comma or space)'
description: 'Testing labels(delimited by comma)'
required: true
default: 'nightly-testing'
issue-title:
description: 'Title of a Github Issue'
required: true
default: 'Nightly Testing Report'
assignee:
description: 'Assignee of this issue'
required: false
default: ''
exclude-workflow-files:
description: 'Excluded yml files(delimited by comma or space)'
description: 'Excluded yml files(delimited by comma)'
required: false
runs:
using: 'docker'
Expand Down
74 changes: 53 additions & 21 deletions .github/actions/testing_report_generation/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,31 @@
require 'optparse'
require "json"

REPO_NAME_WITH_OWNER = 'firebase/firebase-ios-sdk'.freeze
REPORT_TESTING_REPO = 'granluo/issue_generations'.freeze
excluded_workflows = []
issue_labels = []
pp ENV
REPO_NAME_WITH_OWNER = ENV['GITHUB_REPOSITORY']
NO_WORKFLOW_RUNNING_INFO = 'All nightly cron job were not run. Please make sure there at least exists one cron job running.'.freeze
EXCLUDED_WORKFLOWS = []
ISSUE_LABELS = ""
ISSUE_TITLE = "Auto-Generated Testing Report"

if not ENV['INPUT_EXCLUDE-WORKFLOW-FILES'].nil?
excluded_workflows = ENV['INPUT_EXCLUDE-WORKFLOW-FILES'].split(/[ ,]/)
EXCLUDED_WORKFLOWS = ENV['INPUT_EXCLUDE-WORKFLOW-FILES'].split(/[ ,]/)
end
if not ENV['INPUT_ISSUE-LABELS'].nil?
ISSUE_LABELS = ENV['INPUT_ISSUE-LABELS']
end
if not ENV['INPUT_ISSUE_LABELS'].nil?
issue_labels = ENV['INPUT_ISSUE_LABELS'].split(/[ ,]/)
if not ENV['INPUT_ISSUE-TITLE'].nil?
ISSUE_TITLE = ENV['INPUT_ISSUE-TITLE']
end
assignee = ENV['INPUT_ASSIGNEES']
ASSIGNEE = ENV['INPUT_ASSIGNEES']

class Table
def initialize(title)
cur_time = Time.now.utc.localtime("-07:00")
cur_time = Time.now.utc.localtime("-08:00")
@is_empty_table = true
@text = String.new ""
@text << "# %s\n" % [title]
@text << "Failures are detected in workflow(s)\n"
@text << "This issue is generated at %s\n" % [cur_time.strftime('%m/%d/%Y %H:%M %p') ]
@text << "This issue is generated at %s\n" % [cur_time.strftime('%m/%d/%Y %H:%M %p %:z') ]
@text << "| Workflow |"
@text << (cur_time - 86400).strftime('%m/%d') + "|"
@text << "\n| -------- |"
Expand All @@ -31,22 +37,31 @@ def initialize(title)
end

def add_workflow_run_and_result(workflow, result)
@is_empty_table = false
record = "| %s | %s |\n" % [workflow, result]
@text << record
end

def get_report()
if @is_empty_table
return nil
end
return @text
end
end

report = Table.new("Nightly Testing Report")
failure_report = Table.new(ISSUE_TITLE)
success_report = Table.new(ISSUE_TITLE)
client = Octokit::Client.new(access_token: ENV["INPUT_ACCESS-TOKEN"])
last_issue = client.list_issues(REPORT_TESTING_REPO, :labels => ENV['INPUT_ISSUE-LABEL'])[0]
last_issue = client.list_issues(REPO_NAME_WITH_OWNER, :labels => ISSUE_LABELS, :state => "all")[0]
workflows = client.workflows(REPO_NAME_WITH_OWNER)

puts "Excluded workflow files: " + excluded_workflows.join(",")
puts "Excluded workflow files: " + EXCLUDED_WORKFLOWS.join(",")
for wf in workflows.workflows do
# skip if it is the issue generation workflow.
if wf.name == ENV["GITHUB_WORKFLOW"]
next
end
workflow_file = File.basename(wf.path)
puts workflow_file
workflow_text = "[%s](%s)" % [wf.name, wf.html_url]
Expand All @@ -55,17 +70,34 @@ def get_report()
latest_run = runs[0]
if latest_run.nil?
puts "no schedule runs found."
elsif excluded_workflows.include?(workflow_file)
elsif EXCLUDED_WORKFLOWS.include?(workflow_file)
puts workflow_file + " is excluded in the report."
elsif Time.now.utc - latest_run.created_at < 86400
puts latest_run.event + latest_run.html_url + " " + latest_run.created_at.to_s + " " + latest_run.conclusion
result_text = "[%s](%s)" % [latest_run.conclusion, latest_run.html_url]
report.add_workflow_run_and_result(workflow_text, result_text) unless latest_run.conclusion == "success"
result_text = "[%s](%s)" % [latest_run.conclusion.nil? ? "in_process" : latest_run.conclusion, latest_run.html_url]
if latest_run.conclusion == "success"
success_report.add_workflow_run_and_result(workflow_text, result_text)
else
failure_report.add_workflow_run_and_result(workflow_text, result_text)
end
end
end

if not last_issue.nil? && last_issue.state == "open"
client.add_comment(REPORT_TESTING_REPO, last_issue.number,report.get_report)
# Check if there exists any cron jobs.
if failure_report.get_report.nil? && success_report.get_report.nil?
if last_issue.state == "open"
client.add_comment(REPO_NAME_WITH_OWNER, last_issue.number, NO_WORKFLOW_RUNNING_INFO)
else
client.create_issue(REPO_NAME_WITH_OWNER, ISSUE_TITLE, NO_WORKFLOW_RUNNING_INFO, labels: ISSUE_LABELS, assignee: ASSIGNEE)
end
# Close an issue if all workflows succeed.
elsif failure_report.get_report.nil? and last_issue.state == "open"
client.add_comment(REPO_NAME_WITH_OWNER, last_issue.number, success_report.get_report)
client.close_issue(REPO_NAME_WITH_OWNER, last_issue.number)
# If the last issue is open, then failed report will be commented to the issue.
elsif !last_issue.nil? and last_issue.state == "open"
client.add_comment(REPO_NAME_WITH_OWNER, last_issue.number,failure_report.get_report)
last_issue.add_comment(REPO_NAME_WITH_OWNER, last_issue.number,failure_report.get_report)
# Creat an new issue otherwise.
else
new_issue = client.create_issue(REPORT_TESTING_REPO, 'Nightly Testing Report' + Time.now.utc.localtime("-07:00").strftime('%m/%d/%Y %H:%M %p'), report.get_report, labels: issue_labels, assignee: assignee)
client.create_issue(REPO_NAME_WITH_OWNER, ISSUE_TITLE, failure_report.get_report, labels: ISSUE_LABELS, assignee: ASSIGNEE)
end
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name: generate_issue
name: generate a report

on:
workflow_dispatch:
pull_request:
paths:
- '.github/workflows/generate_issues.yml'
schedule:
# Run every day at 4am (PST) - cron uses UTC times
- cron: '0 12 * * *'
jobs:
hello_world_job:
generate_an_issue:
runs-on: ubuntu-latest
name: Generate a nightly testing report issue
steps:
Expand All @@ -17,3 +19,4 @@ jobs:
with:
access-token: '${{ secrets.ISSUE_TEST_TOKEN }}'
exclude-workflow-files: 'performance.yml performance-integration-tests.yml'
issue-labels: 'nightly-testing'
18 changes: 0 additions & 18 deletions .github/workflows/main.yml

This file was deleted.

36 changes: 0 additions & 36 deletions .github/workflows/test.yml

This file was deleted.