@@ -201,6 +201,50 @@ def generate_gitignore() -> None:
201
201
fh .write (data )
202
202
203
203
204
+ # TODO: remove this function when affected people disappears. You can see the list of such people at https://github.com/search?q=%22timestamps.local.json%22+language%3Agitignore&type=Code
205
+ def _delete_gitignore () -> None :
206
+ """A workaround for the issue https://github.com/online-judge-tools/verification-helper/issues/332
207
+ """
208
+
209
+ try :
210
+ # check if it's on GitHub Action
211
+ should_push = 'GITHUB_ACTION' in os .environ and 'GITHUB_TOKEN' in os .environ and os .environ .get ('GITHUB_REF' , '' ).startswith ('refs/heads/' )
212
+ if not should_push :
213
+ return
214
+
215
+ # checkout the target branch
216
+ branch = os .environ ['GITHUB_REF' ][len ('refs/heads/' ):]
217
+ logger .info ('$ git checkout %s' , branch )
218
+ subprocess .check_call (['git' , 'checkout' , branch ])
219
+
220
+ # check if .verify-helper/.gitignore exists
221
+ gitignore_path = pathlib .Path ('.verify-helper' , '.gitignore' )
222
+ gitignore_checked_in = (subprocess .run (['git' , 'ls-files' , '--error-unmatch' , str (gitignore_path )]).returncode == 0 )
223
+ if not gitignore_checked_in :
224
+ return
225
+ logger .warning ('file %s exists in this Git repository. It should not be checked in.' , str (gitignore_path ))
226
+
227
+ # read config
228
+ logger .info ('use GITHUB_TOKEN' ) # NOTE: don't use GH_PAT here, because it may cause infinite loops with triggering GitHub Actions itself
229
+ url = 'https://{}:{}@github.com/{}.git' .format (os .environ ['GITHUB_ACTOR' ], os .environ ['GITHUB_TOKEN' ], os .environ ['GITHUB_REPOSITORY' ])
230
+ logger .info ('GITHUB_ACTOR = %s' , os .environ ['GITHUB_ACTOR' ])
231
+ logger .info ('GITHUB_REPOSITORY = %s' , os .environ ['GITHUB_REPOSITORY' ])
232
+
233
+ # remove .verify-helper/.gitignore
234
+ subprocess .check_call (['git' , 'config' , '--global' , 'user.name' , 'GitHub' ])
235
+ subprocess .
check_call ([
'git' ,
'config' ,
'--global' ,
'user.email' ,
'[email protected] ' ])
236
+ logger .info ('$ git rm --cached %s' , str (gitignore_path ))
237
+ subprocess .check_call (['git' , 'rm' , '--cached' , str (gitignore_path )])
238
+ message = '[auto-verifier] remove .verify-helper/.gitignore (see https://github.com/online-judge-tools/verification-helper/issues/332)'
239
+ logger .info ('$ git commit -m ...' )
240
+ subprocess .check_call (['git' , 'commit' , '-m' , message ])
241
+ logger .info ('$ git push ... HEAD' )
242
+ subprocess .check_call (['git' , 'push' , url , 'HEAD' ])
243
+
244
+ except Exception :
245
+ logger .exception ('something wrong in _delete_gitignore(). ignored.' )
246
+
247
+
204
248
def main (args : Optional [List [str ]] = None ) -> None :
205
249
# configure logging
206
250
log_format = '%(log_color)s%(levelname)s%(reset)s:%(name)s:%(message)s'
@@ -220,6 +264,7 @@ def main(args: Optional[List[str]] = None) -> None:
220
264
onlinejudge_verify .marker .get_verification_marker (jobs = parsed .jobs )
221
265
222
266
if parsed .subcommand == 'all' :
267
+ _delete_gitignore ()
223
268
generate_gitignore ()
224
269
summary = subcommand_run (paths = [], timeout = parsed .timeout , tle = parsed .tle , jobs = parsed .jobs )
225
270
subcommand_docs (jobs = parsed .jobs )
@@ -228,13 +273,15 @@ def main(args: Optional[List[str]] = None) -> None:
228
273
sys .exit (1 )
229
274
230
275
elif parsed .subcommand == 'run' :
276
+ _delete_gitignore ()
231
277
generate_gitignore ()
232
278
summary = subcommand_run (paths = parsed .path , timeout = parsed .timeout , tle = parsed .tle , jobs = parsed .jobs )
233
279
summary .show ()
234
280
if not summary .succeeded ():
235
281
sys .exit (1 )
236
282
237
283
elif parsed .subcommand == 'docs' :
284
+ _delete_gitignore ()
238
285
generate_gitignore ()
239
286
subcommand_docs (jobs = parsed .jobs )
240
287
0 commit comments