16
16
17
17
def check_file_exists (file ):
18
18
if not os .path .exists (file ):
19
- print ("Expected file '" + file + " ' doesn't exist." , file = sys .stderr )
19
+ print (f "Expected file '{ file } ' doesn't exist." , file = sys .stderr )
20
20
return False
21
21
return True
22
22
@@ -73,7 +73,7 @@ def get_comment_text(output_file, repo, run_id):
73
73
return
74
74
75
75
comment = ":warning: The head of this PR and the base branch were compared for differences in the framework coverage reports. " + \
76
- "The generated reports are available in the [artifacts of this workflow run](https://github.com/" + repo + " /actions/runs/" + str ( run_id ) + " ). " + \
76
+ f "The generated reports are available in the [artifacts of this workflow run](https://github.com/{ repo } /actions/runs/{ run_id } ). " + \
77
77
"The differences will be picked up by the nightly job after the PR gets merged. "
78
78
79
79
if size < 2000 :
@@ -83,8 +83,7 @@ def get_comment_text(output_file, repo, run_id):
83
83
comment += file .read ()
84
84
else :
85
85
print ("There's a large change in the CSV framework coverage reports" )
86
- comment += "The differences can be found in the " + \
87
- output_file + " artifact of this job."
86
+ comment += f"The differences can be found in the { output_file } artifact of this job."
88
87
89
88
return comment
90
89
@@ -114,12 +113,11 @@ def comment_pr(output_file, repo, run_id):
114
113
write_diff_for_run (prev_output_file , repo , prev_run_id )
115
114
116
115
if filecmp .cmp (output_file , prev_output_file , shallow = False ):
117
- print ("Previous run " + str ( prev_run_id ) +
118
- " resulted in the same diff, so not commenting again." )
116
+ print (
117
+ f"Previous run { prev_run_id } resulted in the same diff, so not commenting again." )
119
118
return
120
119
else :
121
- print ("Diff of previous run " +
122
- str (prev_run_id ) + " differs, commenting." )
120
+ print (f"Diff of previous run { prev_run_id } differs, commenting." )
123
121
except Exception :
124
122
# this is not mecessarily a failure, it can also mean that there was no previous run yet.
125
123
print ("Couldn't generate diff for previous run:" , sys .exc_info ()[1 ])
@@ -132,7 +130,7 @@ def comment_pr(output_file, repo, run_id):
132
130
133
131
134
132
def post_comment (comment , repo , pr_number ):
135
- print ("Posting comment to PR #" + str ( pr_number ) )
133
+ print (f "Posting comment to PR #{ pr_number } " )
136
134
utils .subprocess_run (["gh" , "pr" , "comment" , str (pr_number ),
137
135
"--repo" , repo , "--body" , comment ])
138
136
@@ -155,41 +153,33 @@ def compare_folders(folder1, folder2, output_file):
155
153
language = lang )
156
154
157
155
# check if files exist in both folder1 and folder 2
158
- if not check_file_exists (folder1 + "/" + generated_output_rst ):
159
- expected_files += "- " + generated_output_rst + \
160
- " doesn't exist in folder " + folder1 + "\n "
161
- if not check_file_exists (folder2 + "/" + generated_output_rst ):
162
- expected_files += "- " + generated_output_rst + \
163
- " doesn't exist in folder " + folder2 + "\n "
164
- if not check_file_exists (folder1 + "/" + generated_output_csv ):
165
- expected_files += "- " + generated_output_csv + \
166
- " doesn't exist in folder " + folder1 + "\n "
167
- if not check_file_exists (folder2 + "/" + generated_output_csv ):
168
- expected_files += "- " + generated_output_csv + \
169
- " doesn't exist in folder " + folder2 + "\n "
156
+ if not check_file_exists (f"{ folder1 } /{ generated_output_rst } " ):
157
+ expected_files += f"- { generated_output_rst } doesn't exist in folder { folder1 } \n "
158
+ if not check_file_exists (f"{ folder2 } /{ generated_output_rst } " ):
159
+ expected_files += f"- { generated_output_rst } doesn't exist in folder { folder2 } \n "
160
+ if not check_file_exists (f"{ folder1 } /{ generated_output_csv } " ):
161
+ expected_files += f"- { generated_output_csv } doesn't exist in folder { folder1 } \n "
162
+ if not check_file_exists (f"{ folder2 } /{ generated_output_csv } " ):
163
+ expected_files += f"- { generated_output_csv } doesn't exist in folder { folder2 } \n "
170
164
171
165
if expected_files != "" :
172
166
print ("Expected files are missing" , file = sys .stderr )
173
- return_md += "\n ### " + lang + "\n \n #### Expected files are missing for " + \
174
- lang + "\n " + expected_files + "\n "
167
+ return_md += f"\n ### { lang } \n \n #### Expected files are missing for { lang } \n { expected_files } \n "
175
168
continue
176
169
177
170
# compare contents of files
178
171
cmp1 = compare_files_str (
179
- folder1 + "/" + generated_output_rst , folder2 + "/" + generated_output_rst )
172
+ f" { folder1 } / { generated_output_rst } " , f" { folder2 } / { generated_output_rst } " )
180
173
cmp2 = compare_files_str (
181
- folder1 + "/" + generated_output_csv , folder2 + "/" + generated_output_csv )
174
+ f" { folder1 } / { generated_output_csv } " , f" { folder2 } / { generated_output_csv } " )
182
175
183
176
if cmp1 != "" or cmp2 != "" :
184
177
print ("Generated file contents are not matching" , file = sys .stderr )
185
- return_md += "\n ### " + lang + "\n \n #### Generated file changes for " + \
186
- lang + "\n \n "
178
+ return_md += f"\n ### { lang } \n \n #### Generated file changes for { lang } \n \n "
187
179
if cmp1 != "" :
188
- return_md += "- Changes to " + generated_output_rst + \
189
- ":\n ```diff\n " + cmp1 + "```\n \n "
180
+ return_md += f"- Changes to { generated_output_rst } :\n ```diff\n { cmp1 } ```\n \n "
190
181
if cmp2 != "" :
191
- return_md += "- Changes to " + generated_output_csv + \
192
- ":\n ```diff\n " + cmp2 + "```\n \n "
182
+ return_md += f"- Changes to { generated_output_csv } :\n ```diff\n { cmp2 } ```\n \n "
193
183
194
184
with open (output_file , 'w' , newline = '' ) as out :
195
185
out .write (return_md )
@@ -201,29 +191,29 @@ def get_previous_run_id(repo, run_id, pr_number):
201
191
"""
202
192
203
193
# Get branch and repo from run:
204
- this_run = utils .subprocess_check_output ([ "gh" , "api" , "-X" , "GET" , "repos/" + repo + "/actions/runs/" + str (
205
- run_id ) , "--jq" , "{ head_branch: .head_branch, head_repository: .head_repository.full_name }" ])
194
+ this_run = utils .subprocess_check_output (
195
+ [ "gh" , "api" , "-X" , "GET" , f"repos/ { repo } /actions/runs/ { run_id } " , "--jq" , "{ head_branch: .head_branch, head_repository: .head_repository.full_name }" ])
206
196
207
197
this_run = json .loads (this_run )
208
198
pr_branch = this_run ["head_branch" ]
209
199
pr_repo = this_run ["head_repository" ]
210
200
211
201
# Get all previous runs that match branch, repo and workflow name:
212
- ids = utils .subprocess_check_output (["gh" , "api" , "-X" , "GET" , "repos/" + repo + " /actions/runs" , "-f" , "event=pull_request" , "-f" , "status=success" , "-f" , "name=\" " + artifacts_workflow_name + "\" " , "--jq" ,
213
- "[.workflow_runs.[] | select(.head_branch==\" " + pr_branch + " \" and .head_repository.full_name==\" " + pr_repo + " \" ) | { created_at: .created_at, run_id: .id}] | sort_by(.created_at) | reverse | [.[].run_id]" ])
202
+ ids = utils .subprocess_check_output (["gh" , "api" , "-X" , "GET" , f "repos/{ repo } /actions/runs" , "-f" , "event=pull_request" , "-f" , "status=success" , "-f" , "name=\" " + artifacts_workflow_name + "\" " , "--jq" ,
203
+ f "[.workflow_runs.[] | select(.head_branch==\" { pr_branch } \" and .head_repository.full_name==\" { pr_repo } \" ) | {{ created_at: .created_at, run_id: .id} }] | sort_by(.created_at) | reverse | [.[].run_id]" ])
214
204
215
205
ids = json .loads (ids )
216
206
if ids [0 ] != int (run_id ):
217
- raise Exception ("Expected to find " + str ( run_id ) +
218
- " in the list of matching runs." )
207
+ raise Exception (
208
+ f"Expected to find { run_id } in the list of matching runs." )
219
209
220
210
for previous_run_id in ids [1 :]:
221
211
download_artifact (repo , "pr" , "prev_run_pr" , previous_run_id )
222
212
223
213
try :
224
214
with open ("prev_run_pr/NR" ) as file :
225
215
prev_pr_number = int (file .read ())
226
- print ("PR number: " + str ( prev_pr_number ) )
216
+ print (f "PR number: { prev_pr_number } " )
227
217
finally :
228
218
if os .path .isdir ("prev_run_pr" ):
229
219
shutil .rmtree ("prev_run_pr" )
0 commit comments