From 653255f943d6b1dd5a97210d1aeb68cf9803c5c0 Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Mon, 23 Nov 2020 14:27:46 -0800 Subject: [PATCH 01/23] Add testing report generation. --- .github/workflows/generate_issues.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/generate_issues.yml diff --git a/.github/workflows/generate_issues.yml b/.github/workflows/generate_issues.yml new file mode 100644 index 0000000..ab21922 --- /dev/null +++ b/.github/workflows/generate_issues.yml @@ -0,0 +1,20 @@ +name: generate a report + +on: + 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: + runs-on: ubuntu-latest + name: Generate a nightly testing report issue + steps: + - uses: actions/checkout@v2 + - name: Create a nightly report + uses: ./.github/actions/testing_report_generation/ + with: + access-token: '${{ secrets.ISSUE_TEST_TOKEN }}' + exclude-workflow-files: 'performance.yml performance-integration-tests.yml' From 7d9ab76eb116d765f819e10279dccb94b162bac2 Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Mon, 23 Nov 2020 14:40:35 -0800 Subject: [PATCH 02/23] Update time. --- .github/actions/testing_report_generation/app.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index ac1889e..80e7829 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -18,7 +18,7 @@ class Table def initialize(title) - cur_time = Time.now.utc.localtime("-07:00") + cur_time = Time.now.utc.localtime("-08:00") @text = String.new "" @text << "# %s\n" % [title] @text << "Failures are detected in workflow(s)\n" @@ -67,5 +67,5 @@ def get_report() if not last_issue.nil? && last_issue.state == "open" client.add_comment(REPORT_TESTING_REPO, last_issue.number,report.get_report) 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) + new_issue = client.create_issue(REPORT_TESTING_REPO, 'Nightly Testing Report' + Time.now.utc.localtime("-08:00").strftime('%m/%d/%Y %H:%M %p'), report.get_report, labels: issue_labels, assignee: assignee) end From 57798b359c8502f109b6898e1e74ce424e77e977 Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 02:21:41 -0800 Subject: [PATCH 03/23] Test adding a comment to an issue. --- .github/actions/testing_report_generation/app.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index 80e7829..603c3a9 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -65,7 +65,9 @@ def get_report() end if not last_issue.nil? && last_issue.state == "open" + puts last_issue.number client.add_comment(REPORT_TESTING_REPO, last_issue.number,report.get_report) + last_issue.add_comment(REPORT_TESTING_REPO, last_issue.number,report.get_report) else new_issue = client.create_issue(REPORT_TESTING_REPO, 'Nightly Testing Report' + Time.now.utc.localtime("-08:00").strftime('%m/%d/%Y %H:%M %p'), report.get_report, labels: issue_labels, assignee: assignee) end From c3a06fc91353a21aa8ed2729a947609579f8918a Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 02:34:00 -0800 Subject: [PATCH 04/23] remove workflows. --- .github/workflows/main.yml | 18 ----------------- .github/workflows/test.yml | 36 --------------------------------- .github/workflows/test_prod.yml | 19 ----------------- 3 files changed, 73 deletions(-) delete mode 100644 .github/workflows/main.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_prod.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index eac26fa..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,18 +0,0 @@ -on: [push] - -jobs: - hello_world_job: - runs-on: ubuntu-latest - name: A job to say hello - steps: - - uses: actions/checkout@v2 - - name: Hello world action step - id: hello - uses: ./.github/actions/hello-docker - with: - who-to-greet: 'Mona the Octocat' - access-token: '${{ secrets.ISSUE_TEST_TOKEN }}' - exclude-workflow-files: 'performance.yml performance-integration-tests.yml' - # Use the output from the `hello` step - - name: Get the output time - run: echo "The time was ${{ steps.hello.outputs.time }}" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index fe403a3..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: test_issue_generation - -on: - pull_request: - paths: - - '.github/workflows/test.yml' -jobs: - get_link: - runs-on: macOS-latest - steps: - - uses: actions/checkout@v2 - - name: Get Job Link - run: | - echo "https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" - echo "https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> id_artifact.txt - - uses: actions/upload-artifact@v2 - with: - name: job_log_link - path: id_artifact.txt - dummy_job: - runs-on: macOS-latest - steps: - - uses: actions/checkout@v2 - - name: Get Job Link - run: | - echo "https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" - - uses: actions/download-artifact@v2 - with: - name: job_log_link - - name: Add Link - run: | - echo -e "\nhttps://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> id_artifact.txt - - uses: actions/upload-artifact@v2 - with: - name: job_log_link - path: id_artifact.txt diff --git a/.github/workflows/test_prod.yml b/.github/workflows/test_prod.yml deleted file mode 100644 index df20b9b..0000000 --- a/.github/workflows/test_prod.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: generate_issue -on: - 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: - runs-on: ubuntu-latest - name: Generate a nightly testing report issue - steps: - - uses: actions/checkout@v2 - - name: Create a nightly report - uses: ./.github/actions/testing_report_generation/ - with: - access-token: '${{ secrets.ISSUE_TEST_TOKEN }}' - exclude-workflow-files: 'performance.yml performance-integration-tests.yml' From 1eb4f53c1e0de8b1663594f9aab7cc5c4144824b Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 02:44:34 -0800 Subject: [PATCH 05/23] update log. --- .github/actions/testing_report_generation/app.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index 603c3a9..4c02e98 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -58,7 +58,10 @@ def get_report() 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 + puts latest_run.event + " " + puts latest_run.html_url + " " + puts latest_run.created_at.to_s + " " + puts 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" end From 52bd23f0042c63a1e5e3f6eebf9ed74e78570bdc Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 03:06:36 -0800 Subject: [PATCH 06/23] fix typo. --- .github/actions/testing_report_generation/app.rb | 4 ++-- .github/workflows/generate_issues.yml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index 4c02e98..324f2f8 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -11,8 +11,8 @@ if not ENV['INPUT_EXCLUDE-WORKFLOW-FILES'].nil? excluded_workflows = ENV['INPUT_EXCLUDE-WORKFLOW-FILES'].split(/[ ,]/) end -if not ENV['INPUT_ISSUE_LABELS'].nil? - issue_labels = ENV['INPUT_ISSUE_LABELS'].split(/[ ,]/) +if not ENV['INPUT_ISSUE-LABELS'].nil? + issue_labels = ENV['INPUT_ISSUE-LABELS'].split(/[ ,]/) end assignee = ENV['INPUT_ASSIGNEES'] diff --git a/.github/workflows/generate_issues.yml b/.github/workflows/generate_issues.yml index ab21922..d772e24 100644 --- a/.github/workflows/generate_issues.yml +++ b/.github/workflows/generate_issues.yml @@ -18,3 +18,4 @@ jobs: with: access-token: '${{ secrets.ISSUE_TEST_TOKEN }}' exclude-workflow-files: 'performance.yml performance-integration-tests.yml' + issue-labels: 'nightly-testihg' From dfc07808312873dcc9a8cb150e38e974ddf63026 Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 03:10:35 -0800 Subject: [PATCH 07/23] fix typo. --- .github/actions/testing_report_generation/app.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index 324f2f8..ccbad60 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -4,6 +4,7 @@ require 'optparse' require "json" +pp ENV REPO_NAME_WITH_OWNER = 'firebase/firebase-ios-sdk'.freeze REPORT_TESTING_REPO = 'granluo/issue_generations'.freeze excluded_workflows = [] @@ -42,7 +43,7 @@ def get_report() report = Table.new("Nightly Testing Report") 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(REPORT_TESTING_REPO, :labels => issue_labels)[0] workflows = client.workflows(REPO_NAME_WITH_OWNER) puts "Excluded workflow files: " + excluded_workflows.join(",") From 4da14cd97cafc5340bba0ba09ade32d84cdcf6a4 Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 03:19:36 -0800 Subject: [PATCH 08/23] fix typo. --- .github/workflows/generate_issues.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate_issues.yml b/.github/workflows/generate_issues.yml index d772e24..1d3b407 100644 --- a/.github/workflows/generate_issues.yml +++ b/.github/workflows/generate_issues.yml @@ -18,4 +18,4 @@ jobs: with: access-token: '${{ secrets.ISSUE_TEST_TOKEN }}' exclude-workflow-files: 'performance.yml performance-integration-tests.yml' - issue-labels: 'nightly-testihg' + issue-labels: 'nightly-testing' From dfc8302502ea9c811d94174a9e76f1a5eb28c56b Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 03:36:31 -0800 Subject: [PATCH 09/23] fix typo. --- .github/actions/testing_report_generation/action.yml | 4 ++-- .github/actions/testing_report_generation/app.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/actions/testing_report_generation/action.yml b/.github/actions/testing_report_generation/action.yml index d88aafe..bbecac2 100644 --- a/.github/actions/testing_report_generation/action.yml +++ b/.github/actions/testing_report_generation/action.yml @@ -5,7 +5,7 @@ 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' assignee: @@ -13,7 +13,7 @@ inputs: 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' diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index ccbad60..2ec7737 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -8,12 +8,12 @@ REPO_NAME_WITH_OWNER = 'firebase/firebase-ios-sdk'.freeze REPORT_TESTING_REPO = 'granluo/issue_generations'.freeze excluded_workflows = [] -issue_labels = [] +issue_labels = "" if not ENV['INPUT_EXCLUDE-WORKFLOW-FILES'].nil? excluded_workflows = ENV['INPUT_EXCLUDE-WORKFLOW-FILES'].split(/[ ,]/) end if not ENV['INPUT_ISSUE-LABELS'].nil? - issue_labels = ENV['INPUT_ISSUE-LABELS'].split(/[ ,]/) + issue_labels = ENV['INPUT_ISSUE-LABELS'] end assignee = ENV['INPUT_ASSIGNEES'] From 709863b680ccee58b6a28c8023b3d9e61f143734 Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 03:43:44 -0800 Subject: [PATCH 10/23] add in_process --- .github/actions/testing_report_generation/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index 2ec7737..c271dd4 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -63,7 +63,7 @@ def get_report() puts latest_run.html_url + " " puts latest_run.created_at.to_s + " " puts latest_run.conclusion - result_text = "[%s](%s)" % [latest_run.conclusion, latest_run.html_url] + result_text = "[%s](%s)" % [latest_run.conclusion.nil? ? "in_process" : latest_run.conclusion.nil, latest_run.html_url] report.add_workflow_run_and_result(workflow_text, result_text) unless latest_run.conclusion == "success" end end From 52412299c912bfab8cfe103ea1c478f4fccc0ded Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 03:51:16 -0800 Subject: [PATCH 11/23] fix typo. --- .github/actions/testing_report_generation/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index c271dd4..1818371 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -63,7 +63,7 @@ def get_report() puts latest_run.html_url + " " puts latest_run.created_at.to_s + " " puts latest_run.conclusion - result_text = "[%s](%s)" % [latest_run.conclusion.nil? ? "in_process" : latest_run.conclusion.nil, latest_run.html_url] + result_text = "[%s](%s)" % [latest_run.conclusion.nil? ? "in_process" : latest_run.conclusion, latest_run.html_url] report.add_workflow_run_and_result(workflow_text, result_text) unless latest_run.conclusion == "success" end end From ca5f0bbe5866a13cb5b3fe59f8f07c1c18905c18 Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 03:57:12 -0800 Subject: [PATCH 12/23] add manual trigger. --- .github/workflows/generate_issues.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/generate_issues.yml b/.github/workflows/generate_issues.yml index 1d3b407..dba12a0 100644 --- a/.github/workflows/generate_issues.yml +++ b/.github/workflows/generate_issues.yml @@ -1,6 +1,7 @@ name: generate a report on: + workflow_dispatch: pull_request: paths: - '.github/workflows/generate_issues.yml' @@ -8,7 +9,7 @@ on: # 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: From f49b46beab404d0f513ea73ed68545ad1d58410e Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 04:04:52 -0800 Subject: [PATCH 13/23] check all state issues. --- .github/actions/testing_report_generation/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index 1818371..298e4bf 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -43,7 +43,7 @@ def get_report() report = Table.new("Nightly Testing Report") client = Octokit::Client.new(access_token: ENV["INPUT_ACCESS-TOKEN"]) -last_issue = client.list_issues(REPORT_TESTING_REPO, :labels => issue_labels)[0] +last_issue = client.list_issues(REPORT_TESTING_REPO, :labels => issue_labels, :state => "all")[0] workflows = client.workflows(REPO_NAME_WITH_OWNER) puts "Excluded workflow files: " + excluded_workflows.join(",") From f8f697140d36b65c0a4b5d65e4f4b17013fe2b05 Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 04:11:59 -0800 Subject: [PATCH 14/23] check all state issues. --- .github/actions/testing_report_generation/app.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index 298e4bf..d174eba 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -68,6 +68,7 @@ def get_report() end end +puts "issue %s is currently %s" % [last_issue.number, last_issue.state] if not last_issue.nil? && last_issue.state == "open" puts last_issue.number client.add_comment(REPORT_TESTING_REPO, last_issue.number,report.get_report) From 1a2e5900fc3b4dae8535a3a6542e80e1039785b0 Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 04:17:03 -0800 Subject: [PATCH 15/23] && precede not --- .github/actions/testing_report_generation/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index d174eba..8518637 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -69,7 +69,7 @@ def get_report() end puts "issue %s is currently %s" % [last_issue.number, last_issue.state] -if not last_issue.nil? && last_issue.state == "open" +if !last_issue.nil? and last_issue.state == "open" puts last_issue.number client.add_comment(REPORT_TESTING_REPO, last_issue.number,report.get_report) last_issue.add_comment(REPORT_TESTING_REPO, last_issue.number,report.get_report) From c087931b024ac1643c02851f3f63e5a4d0357f95 Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 04:59:52 -0800 Subject: [PATCH 16/23] Add more logic. --- .../actions/testing_report_generation/app.rb | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index 8518637..7b09d7a 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -20,6 +20,7 @@ class Table def initialize(title) 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" @@ -32,16 +33,21 @@ 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("Nightly Testing Report") +success_report = Table.new("Nightly Testing Report") client = Octokit::Client.new(access_token: ENV["INPUT_ACCESS-TOKEN"]) last_issue = client.list_issues(REPORT_TESTING_REPO, :labels => issue_labels, :state => "all")[0] workflows = client.workflows(REPO_NAME_WITH_OWNER) @@ -64,15 +70,28 @@ def get_report() puts latest_run.created_at.to_s + " " puts latest_run.conclusion result_text = "[%s](%s)" % [latest_run.conclusion.nil? ? "in_process" : latest_run.conclusion, latest_run.html_url] - report.add_workflow_run_and_result(workflow_text, result_text) unless latest_run.conclusion == "success" + 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 puts "issue %s is currently %s" % [last_issue.number, last_issue.state] -if !last_issue.nil? and last_issue.state == "open" +if failure_report.get_report.nil? && success_report.get_report.nil? + if last_issue.state == "open" + client.add_comment(REPORT_TESTING_REPO, last_issue.number, "Nightly Testings were not run.") + else + client.create_issue(REPORT_TESTING_REPO, "Nightly Testing Report", "Nightly Testings were not run.", labels: issue_labels, assignee: assignee) + end +elsif failure_report.get_report.nil? and last_issue.state == "open" + client.add_comment(REPORT_TESTING_REPO, last_issue.number, success_report.get_report) + client.close_issue(REPORT_TESTING_REPO, last_issue.number) +elsif !last_issue.nil? and last_issue.state == "open" puts last_issue.number - client.add_comment(REPORT_TESTING_REPO, last_issue.number,report.get_report) - last_issue.add_comment(REPORT_TESTING_REPO, last_issue.number,report.get_report) + client.add_comment(REPORT_TESTING_REPO, last_issue.number,failure_report.get_report) + last_issue.add_comment(REPORT_TESTING_REPO, last_issue.number,failure_report.get_report) else - new_issue = client.create_issue(REPORT_TESTING_REPO, 'Nightly Testing Report' + Time.now.utc.localtime("-08:00").strftime('%m/%d/%Y %H:%M %p'), report.get_report, labels: issue_labels, assignee: assignee) + new_issue = client.create_issue(REPORT_TESTING_REPO, 'Nightly Testing Report' + Time.now.utc.localtime("-08:00").strftime('%m/%d/%Y %H:%M %p'), failure_report.get_report, labels: issue_labels, assignee: assignee) end From 5f1d77e403169c29e07ebff09d09a2c6c45aa7a0 Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 05:13:29 -0800 Subject: [PATCH 17/23] Add title. --- .github/actions/testing_report_generation/action.yml | 4 ++++ .github/actions/testing_report_generation/app.rb | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/actions/testing_report_generation/action.yml b/.github/actions/testing_report_generation/action.yml index bbecac2..f50bf4c 100644 --- a/.github/actions/testing_report_generation/action.yml +++ b/.github/actions/testing_report_generation/action.yml @@ -8,6 +8,10 @@ inputs: 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 diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index 7b09d7a..9c6e8ec 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -9,12 +9,17 @@ REPORT_TESTING_REPO = 'granluo/issue_generations'.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(/[ ,]/) end if not ENV['INPUT_ISSUE-LABELS'].nil? issue_labels = ENV['INPUT_ISSUE-LABELS'] end +if not ENV['INPUT_ISSUE-TITLE'].nil? + issue_title = ENV['INPUT_ISSUE-TITLE'] +end assignee = ENV['INPUT_ASSIGNEES'] class Table @@ -46,8 +51,8 @@ def get_report() end end -failure_report = Table.new("Nightly Testing Report") -success_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 => issue_labels, :state => "all")[0] workflows = client.workflows(REPO_NAME_WITH_OWNER) @@ -83,7 +88,7 @@ def get_report() if last_issue.state == "open" client.add_comment(REPORT_TESTING_REPO, last_issue.number, "Nightly Testings were not run.") else - client.create_issue(REPORT_TESTING_REPO, "Nightly Testing Report", "Nightly Testings were not run.", labels: issue_labels, assignee: assignee) + client.create_issue(REPORT_TESTING_REPO, issue_title, "Nightly Testings were not run.", labels: issue_labels, assignee: assignee) end elsif failure_report.get_report.nil? and last_issue.state == "open" client.add_comment(REPORT_TESTING_REPO, last_issue.number, success_report.get_report) From cef53747424f830ef802988511948325f62ffd15 Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 05:27:29 -0800 Subject: [PATCH 18/23] Test successsful report. --- .github/actions/testing_report_generation/app.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index 9c6e8ec..0da563d 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -78,7 +78,7 @@ def get_report() 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) + # failure_report.add_workflow_run_and_result(workflow_text, result_text) end end end @@ -88,7 +88,7 @@ def get_report() if last_issue.state == "open" client.add_comment(REPORT_TESTING_REPO, last_issue.number, "Nightly Testings were not run.") else - client.create_issue(REPORT_TESTING_REPO, issue_title, "Nightly Testings were not run.", labels: issue_labels, assignee: assignee) + client.create_issue(REPORT_TESTING_REPO, issue_title "Nightly Testing Report", "Nightly Testings were not run.", labels: issue_labels, assignee: assignee) end elsif failure_report.get_report.nil? and last_issue.state == "open" client.add_comment(REPORT_TESTING_REPO, last_issue.number, success_report.get_report) From b4fd5f9a597d96e7ea8e9b3f9fa1aff4d2ec7b95 Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 05:29:49 -0800 Subject: [PATCH 19/23] Test successsful report. --- .github/actions/testing_report_generation/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index 0da563d..67cff8f 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -88,7 +88,7 @@ def get_report() if last_issue.state == "open" client.add_comment(REPORT_TESTING_REPO, last_issue.number, "Nightly Testings were not run.") else - client.create_issue(REPORT_TESTING_REPO, issue_title "Nightly Testing Report", "Nightly Testings were not run.", labels: issue_labels, assignee: assignee) + client.create_issue(REPORT_TESTING_REPO, issue_title, "Nightly Testing Report", "Nightly Testings were not run.", labels: issue_labels, assignee: assignee) end elsif failure_report.get_report.nil? and last_issue.state == "open" client.add_comment(REPORT_TESTING_REPO, last_issue.number, success_report.get_report) From 18ebe3dbad148c2c8a601fa27581977610d07599 Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 05:42:38 -0800 Subject: [PATCH 20/23] Test no report. --- .github/actions/testing_report_generation/app.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index 67cff8f..404779a 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -28,8 +28,7 @@ def initialize(title) @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| -------- |" @@ -59,6 +58,10 @@ def get_report() 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] @@ -76,7 +79,7 @@ def get_report() puts latest_run.conclusion 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) + # success_report.add_workflow_run_and_result(workflow_text, result_text) else # failure_report.add_workflow_run_and_result(workflow_text, result_text) end From c90f3e81ae3ae985cff7cabcc0fa565e0f6196e9 Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 05:44:54 -0800 Subject: [PATCH 21/23] Test no report. --- .github/actions/testing_report_generation/app.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index 404779a..b790766 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -91,7 +91,7 @@ def get_report() if last_issue.state == "open" client.add_comment(REPORT_TESTING_REPO, last_issue.number, "Nightly Testings were not run.") else - client.create_issue(REPORT_TESTING_REPO, issue_title, "Nightly Testing Report", "Nightly Testings were not run.", labels: issue_labels, assignee: assignee) + client.create_issue(REPORT_TESTING_REPO, issue_title, "Nightly Testings were not run.", labels: issue_labels, assignee: assignee) end elsif failure_report.get_report.nil? and last_issue.state == "open" client.add_comment(REPORT_TESTING_REPO, last_issue.number, success_report.get_report) From 0b8c30c8122ad84d6dec631cad197b7ccb3e6c77 Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 07:30:17 -0800 Subject: [PATCH 22/23] Test no report. --- .../actions/testing_report_generation/app.rb | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index b790766..8b2e756 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -5,8 +5,8 @@ require "json" pp ENV -REPO_NAME_WITH_OWNER = 'firebase/firebase-ios-sdk'.freeze -REPORT_TESTING_REPO = 'granluo/issue_generations'.freeze +REPO_NAME_WITH_OWNER = 'granluo/issue_generations'.freeze +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" @@ -53,7 +53,7 @@ def get_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 => issue_labels, :state => "all")[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(",") @@ -73,33 +73,31 @@ def get_report() 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 + " " - puts latest_run.html_url + " " - puts latest_run.created_at.to_s + " " - puts latest_run.conclusion 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) + success_report.add_workflow_run_and_result(workflow_text, result_text) else - # failure_report.add_workflow_run_and_result(workflow_text, result_text) + failure_report.add_workflow_run_and_result(workflow_text, result_text) end end end -puts "issue %s is currently %s" % [last_issue.number, last_issue.state] +# 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(REPORT_TESTING_REPO, last_issue.number, "Nightly Testings were not run.") + client.add_comment(REPO_NAME_WITH_OWNER, last_issue.number, NO_WORKFLOW_RUNNING_INFO) else - client.create_issue(REPORT_TESTING_REPO, issue_title, "Nightly Testings were not run.", labels: issue_labels, assignee: assignee) + 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(REPORT_TESTING_REPO, last_issue.number, success_report.get_report) - client.close_issue(REPORT_TESTING_REPO, last_issue.number) + 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" - puts last_issue.number - client.add_comment(REPORT_TESTING_REPO, last_issue.number,failure_report.get_report) - last_issue.add_comment(REPORT_TESTING_REPO, last_issue.number,failure_report.get_report) + 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("-08:00").strftime('%m/%d/%Y %H:%M %p'), failure_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 From 7c68909e8a252359e44725ba1c5282ee3f04f505 Mon Sep 17 00:00:00 2001 From: Gran Luo Date: Tue, 24 Nov 2020 07:35:02 -0800 Subject: [PATCH 23/23] Test no report. --- .../actions/testing_report_generation/app.rb | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/actions/testing_report_generation/app.rb b/.github/actions/testing_report_generation/app.rb index 8b2e756..deea6fd 100644 --- a/.github/actions/testing_report_generation/app.rb +++ b/.github/actions/testing_report_generation/app.rb @@ -5,22 +5,22 @@ require "json" pp ENV -REPO_NAME_WITH_OWNER = 'granluo/issue_generations'.freeze +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" +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'] + ISSUE_LABELS = ENV['INPUT_ISSUE-LABELS'] end if not ENV['INPUT_ISSUE-TITLE'].nil? - issue_title = ENV['INPUT_ISSUE-TITLE'] + ISSUE_TITLE = ENV['INPUT_ISSUE-TITLE'] end -assignee = ENV['INPUT_ASSIGNEES'] +ASSIGNEE = ENV['INPUT_ASSIGNEES'] class Table def initialize(title) @@ -50,13 +50,13 @@ def get_report() end end -failure_report = Table.new(issue_title) -success_report = Table.new(issue_title) +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(REPO_NAME_WITH_OWNER, :labels => issue_labels, :state => "all")[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"] @@ -70,7 +70,7 @@ 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 result_text = "[%s](%s)" % [latest_run.conclusion.nil? ? "in_process" : latest_run.conclusion, latest_run.html_url] @@ -87,7 +87,7 @@ def get_report() 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) + 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" @@ -99,5 +99,5 @@ def get_report() last_issue.add_comment(REPO_NAME_WITH_OWNER, last_issue.number,failure_report.get_report) # Creat an new issue otherwise. else - client.create_issue(REPO_NAME_WITH_OWNER, issue_title, failure_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