Skip to content

Commit f4824cc

Browse files
Merge pull request #86 from FRRouting/master
Release 2.3.5
2 parents 0f38183 + 776d3b8 commit f4824cc

File tree

9 files changed

+148
-21
lines changed

9 files changed

+148
-21
lines changed

lib/github/build/action.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def initialize(check_suite, github, jobs, logger_level: Logger::INFO)
2929
def create_summary(rerun: false)
3030
logger(Logger::INFO, "SUMMARY #{@stages.inspect}")
3131

32+
Github::Build::SkipOldTests.new(@check_suite).skip_old_tests
33+
3234
@stages.each do |stage_config|
3335
create_check_run_stage(stage_config)
3436
end

lib/github/build/skip_old_tests.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SPDX-License-Identifier: BSD-2-Clause
2+
#
3+
# skip_old_tests.rb
4+
# Part of NetDEF CI System
5+
#
6+
# Copyright (c) 2024 by
7+
# Network Device Education Foundation, Inc. ("NetDEF")
8+
#
9+
# frozen_string_literal: true
10+
11+
module Github
12+
module Build
13+
class SkipOldTests
14+
attr_reader :stages
15+
16+
def initialize(check_suite)
17+
@check_suite = check_suite
18+
@github = Github::Check.new(@check_suite)
19+
@stages = StageConfiguration.all.map { |config| "[CI] #{config.github_check_run_name}" }
20+
@logger = GithubLogger.instance.create('github_skip_old_tests.log', Logger::INFO)
21+
end
22+
23+
def skip_old_tests
24+
%w[queued in_progress success failure queued].each do |status|
25+
@github
26+
.check_runs_for_ref(@check_suite.pull_request.repository,
27+
@check_suite.commit_sha_ref, status: status)[:check_runs]
28+
&.each { |check_run| skipping_old_test(check_run) }
29+
end
30+
end
31+
32+
private
33+
34+
def skipping_old_test(check_run)
35+
return if check_run[:app][:name] != 'NetDEF CI Hook' or @stages.include?(check_run[:name])
36+
37+
@logger.info("Skipping old test suite: #{check_run[:name]}")
38+
puts("Skipping old test suite: #{check_run[:name]}")
39+
40+
message = 'Old test suite, skipping...'
41+
@github.skipped(check_run[:id], { title: "#{check_run[:name]} summary", summary: message })
42+
end
43+
end
44+
end
45+
end

lib/github/build/summary.rb

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def build_summary
4040
msg = "Github::Build::Summary - #{@job.inspect}, #{current_stage.inspect}, bamboo info: #{bamboo_info}"
4141
@pr_log.info(msg)
4242

43+
return if current_stage.cancelled?
44+
4345
# Update current stage
4446
update_summary(current_stage)
4547
# Check if current stage finished
@@ -71,7 +73,7 @@ def must_update_previous_stage(current_stage)
7173
end
7274

7375
def must_cancel_next_stages(current_stage)
74-
return if @job.success? or @job.in_progress? or @job.queued?
76+
return unless current_stage.failure? or current_stage.skipped? or current_stage.cancelled?
7577
return unless current_stage.configuration.mandatory?
7678

7779
Stage
@@ -96,7 +98,7 @@ def must_continue_next_stage(current_stage)
9698
.where(configuration: { position: current_stage.configuration.position + 1 })
9799
.first
98100

99-
return if next_stage.nil?
101+
return if next_stage.nil? or next_stage.cancelled?
100102

101103
update_summary(next_stage)
102104
end
@@ -110,66 +112,56 @@ def cancelling_next_stage(pending_stage)
110112
"The previous stage failed and the remaining tests will be canceled.\nDetails at [#{url}](#{url})."
111113
}
112114

113-
logger(Logger::INFO, "cancelling_next_stage - pending_stage: #{pending_stage.inspect}\n#{output}")
115+
logger(Logger::INFO, "cancelling_next_stage - pending_stage: #{pending_stage.inspect}")
114116

115117
pending_stage.cancelled(@github, output: output)
116118
pending_stage.jobs.each { |job| job.cancelled(@github) }
117119
end
118120

119121
def finished_summary(stage)
120-
logger(Logger::INFO, "Finished stage: #{stage.inspect}, CiJob status: #{@job.status}")
121-
logger(Logger::INFO, "Finished stage: #{stage.inspect}, running? #{stage.reload.running?}")
122-
123122
return if @job.in_progress? or stage.running?
124123

125124
finished_stage_summary(stage)
126125
end
127126

128127
def finished_stage_summary(stage)
129-
logger(Logger::INFO, "finished_stage_summary: #{stage.inspect}. Reason Job: #{@job.inspect}")
130-
131128
url = "https://ci1.netdef.org/browse/#{stage.check_suite.bamboo_ci_ref}"
132129
output = {
133130
title: "#{stage.name} summary",
134131
summary: "#{summary_basic_output(stage)}\nDetails at [#{url}](#{url}).".force_encoding('utf-8')
135132
}
136133

137134
finished_stage_update(stage, output)
138-
139-
logger(Logger::INFO, "finished_stage_summary: #{stage.inspect} #{output.inspect}")
140135
end
141136

142137
def finished_stage_update(stage, output)
143138
if stage.jobs.failure.empty?
144-
logger(Logger::WARN, "Stage: #{stage.name} finished - failure")
145-
stage.success(@github, output: output, agent: @agent)
146-
else
147139
logger(Logger::WARN, "Stage: #{stage.name} finished - success")
148-
stage.failure(@github, output: output, agent: @agent)
140+
stage.success(@github, output: output, agent: @agent)
141+
142+
return
149143
end
144+
145+
logger(Logger::WARN, "Stage: #{stage.name} finished - failure")
146+
stage.failure(@github, output: output, agent: @agent)
150147
end
151148

152149
def update_summary(stage)
153-
logger(Logger::INFO, "Updating summary status #{stage.inspect} -> @job.status: #{@job.status}")
154-
155150
url = "https://ci1.netdef.org/browse/#{@check_suite.bamboo_ci_ref}"
156151
output = {
157152
title: "#{stage.name} summary",
158153
summary: "#{summary_basic_output(stage)}\nDetails at [#{url}](#{url}).".force_encoding('utf-8')
159154
}
160155

161-
logger(Logger::INFO, "update_summary: #{stage.inspect} #{output.inspect}")
162-
163156
logger(Logger::WARN, "Updating stage: #{stage.name} to in_progress")
164157
stage.in_progress(@github, output: output)
165158
stage.update_output(@github, output: output)
166159
end
167160

168161
def summary_basic_output(stage)
169162
jobs = stage.jobs.reload
170-
in_progress = jobs.where(status: :in_progress)
171163

172-
header = ":arrow_right: Jobs in progress: #{in_progress.size}/#{jobs.size}\n\n"
164+
header = queued_message(jobs)
173165
header += in_progress_message(jobs)
174166
header += generate_success_failure_info(stage.name, jobs)
175167

@@ -200,11 +192,25 @@ def generate_success_failure_info(name, jobs)
200192
end
201193

202194
def in_progress_message(jobs)
203-
jobs.where(status: %i[in_progress queued]).map do |job|
195+
in_progress = jobs.where(status: :in_progress)
196+
197+
message = "\n\n:arrow_right: Jobs in progress: #{in_progress.size}/#{jobs.size}\n\n"
198+
199+
message + jobs.where(status: %i[in_progress]).map do |job|
204200
"- **#{job.name}** -> https://ci1.netdef.org/browse/#{job.job_ref}\n"
205201
end.join("\n")
206202
end
207203

204+
def queued_message(jobs)
205+
queued = jobs.where(status: :queued)
206+
207+
message = ":arrow_right: Jobs queued: #{queued.size}/#{jobs.size}\n\n"
208+
message +
209+
queued.map do |job|
210+
"- **#{job.name}** -> https://ci1.netdef.org/browse/#{job.job_ref}\n"
211+
end.join("\n")
212+
end
213+
208214
def success_message(jobs)
209215
jobs.where(status: :success).map do |job|
210216
"- **#{job.name}** -> https://ci1.netdef.org/browse/#{job.job_ref}\n"

lib/github/check.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ def comment_reaction_thumb_down(repo, comment_id)
6060
accept: Octokit::Preview::PREVIEW_TYPES[:reactions])
6161
end
6262

63+
def check_runs_for_ref(repo, sha, status: 'queued')
64+
@app.check_runs_for_ref(repo, sha, status: status, accept: Octokit::Preview::PREVIEW_TYPES[:checks])
65+
end
66+
6367
def create(name)
6468
@app.create_check_run(
6569
@check_suite.pull_request.repository,

lib/github_ci_app.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
require_relative 'github/update_status'
2929
require_relative 'github/plan_execution/finished'
3030
require_relative 'github/user_info'
31+
require_relative 'github/build/skip_old_tests'
3132

3233
# Helpers libs
3334
require_relative 'helpers/configuration'

spec/lib/github/build/action_spec.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,72 @@
4444
allow(fake_github_check).to receive(:success).and_return(ci_job.check_suite)
4545
allow(fake_github_check).to receive(:cancelled).and_return(ci_job.check_suite)
4646
allow(fake_github_check).to receive(:queued).and_return(ci_job.check_suite)
47+
allow(fake_github_check).to receive(:check_runs_for_ref).and_return({})
4748
allow(BambooCi::Result).to receive(:fetch).and_return({})
4849

4950
stage
5051
end
5152

53+
context 'when previous check suite has old tests' do
54+
let(:ci_job) { create(:ci_job, stage: stage, check_suite: check_suite) }
55+
let(:old_test) { create(:ci_job, stage: stage, check_suite: check_suite) }
56+
let(:skip_info) do
57+
{
58+
check_runs: [
59+
{
60+
app: {
61+
name: 'NetDEF CI Hook'
62+
},
63+
name: old_test.name,
64+
id: 1
65+
}
66+
]
67+
}
68+
end
69+
70+
before do
71+
old_test
72+
allow(Stage).to receive(:create).and_return(stage)
73+
allow(stage).to receive(:persisted?).and_return(false)
74+
allow(fake_github_check).to receive(:check_runs_for_ref).and_return(skip_info)
75+
end
76+
77+
it 'must create a stage' do
78+
action.create_summary(rerun: false)
79+
expect(check_suite.reload.stages.size).to eq(1)
80+
end
81+
end
82+
83+
context 'when previous check suite has old tests - but wrong app' do
84+
let(:ci_job) { create(:ci_job, stage: stage, check_suite: check_suite) }
85+
let(:old_test) { create(:ci_job, stage: stage, check_suite: check_suite) }
86+
let(:skip_info) do
87+
{
88+
check_runs: [
89+
{
90+
app: {
91+
name: 'NetDEF CI'
92+
},
93+
name: old_test.name,
94+
id: 1
95+
}
96+
]
97+
}
98+
end
99+
100+
before do
101+
old_test
102+
allow(Stage).to receive(:create).and_return(stage)
103+
allow(stage).to receive(:persisted?).and_return(false)
104+
allow(fake_github_check).to receive(:check_runs_for_ref).and_return(skip_info)
105+
end
106+
107+
it 'must create a stage' do
108+
action.create_summary(rerun: false)
109+
expect(check_suite.reload.stages.size).to eq(1)
110+
end
111+
end
112+
52113
context 'when could not create stage' do
53114
let(:ci_job) { create(:ci_job, stage: stage, check_suite: check_suite) }
54115

spec/lib/github/build_plan_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
allow(fake_github_check).to receive(:in_progress).and_return(fake_check_run)
6565
allow(fake_github_check).to receive(:queued).and_return(fake_check_run)
6666
allow(fake_github_check).to receive(:fetch_username).and_return({})
67+
allow(fake_github_check).to receive(:fetch_username).and_return({})
68+
allow(fake_github_check).to receive(:check_runs_for_ref).and_return({})
6769

6870
allow(BambooCi::RunningPlan).to receive(:fetch).with(fake_plan_run.bamboo_reference).and_return(ci_jobs)
6971
end

spec/lib/github/re_run/command_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
allow(fake_github_check).to receive(:comment_reaction_thumb_up)
7171
allow(fake_github_check).to receive(:skipped)
7272
allow(fake_github_check).to receive(:fetch_username).and_return({})
73+
allow(fake_github_check).to receive(:check_runs_for_ref).and_return({})
7374

7475
allow(BambooCi::PlanRun).to receive(:new).and_return(fake_plan_run)
7576
allow(fake_plan_run).to receive(:start_plan).and_return(200)

spec/lib/github/re_run/comment_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
allow(fake_github_check).to receive(:queued)
7878
allow(fake_github_check).to receive(:comment_reaction_thumb_up)
7979
allow(fake_github_check).to receive(:fetch_username).and_return({})
80+
allow(fake_github_check).to receive(:check_runs_for_ref).and_return({})
8081

8182
allow(BambooCi::PlanRun).to receive(:new).and_return(fake_plan_run)
8283
allow(fake_plan_run).to receive(:start_plan).and_return(200)
@@ -126,6 +127,7 @@
126127
allow(fake_github_check).to receive(:in_progress)
127128
allow(fake_github_check).to receive(:comment_reaction_thumb_up)
128129
allow(fake_github_check).to receive(:fetch_username).and_return({})
130+
allow(fake_github_check).to receive(:check_runs_for_ref).and_return({})
129131

130132
allow(BambooCi::PlanRun).to receive(:new).and_return(fake_plan_run)
131133
allow(fake_plan_run).to receive(:start_plan).and_return(200)
@@ -195,6 +197,7 @@
195197
allow(fake_github_check).to receive(:queued)
196198
allow(fake_github_check).to receive(:pull_request_info).and_return(pull_request_info)
197199
allow(fake_github_check).to receive(:fetch_username).and_return({})
200+
allow(fake_github_check).to receive(:check_runs_for_ref).and_return({})
198201

199202
allow(BambooCi::PlanRun).to receive(:new).and_return(fake_plan_run)
200203
allow(fake_plan_run).to receive(:start_plan).and_return(200)
@@ -275,6 +278,7 @@
275278
allow(fake_github_check).to receive(:queued)
276279
allow(fake_github_check).to receive(:pull_request_info).and_return(pull_request_info)
277280
allow(fake_github_check).to receive(:fetch_username).and_return({})
281+
allow(fake_github_check).to receive(:check_runs_for_ref).and_return({})
278282

279283
allow(BambooCi::PlanRun).to receive(:new).and_return(fake_plan_run)
280284
allow(fake_plan_run).to receive(:start_plan).and_return(200)
@@ -309,6 +313,7 @@
309313
allow(fake_github_check).to receive(:queued)
310314
allow(fake_github_check).to receive(:pull_request_info).and_return(pull_request_info)
311315
allow(fake_github_check).to receive(:fetch_username).and_return({})
316+
allow(fake_github_check).to receive(:check_runs_for_ref).and_return({})
312317

313318
allow(BambooCi::PlanRun).to receive(:new).and_return(fake_plan_run)
314319
allow(fake_plan_run).to receive(:start_plan).and_return(200)

0 commit comments

Comments
 (0)