@@ -201,6 +201,45 @@ 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
+ # check if .verify-helper/.gitignore exists
216
+ gitignore_path = pathlib .Path ('.verify-helper' , '.gitignore' )
217
+ gitignore_checked_in = (subprocess .run (['git' , 'ls-files' , '--error-unmatch' , str (gitignore_path )]).returncode == 0 )
218
+ if not gitignore_checked_in :
219
+ return
220
+ logger .warning ('file %s exists in this Git repository. It should not be checked in.' , str (gitignore_path ))
221
+
222
+ # read config
223
+ logger .info ('use GITHUB_TOKEN' ) # NOTE: don't use GH_PAT here, because it may cause infinite loops with triggering GitHub Actions itself
224
+ url = 'https://{}:{}@github.com/{}.git' .format (os .environ ['GITHUB_ACTOR' ], os .environ ['GITHUB_TOKEN' ], os .environ ['GITHUB_REPOSITORY' ])
225
+ logger .info ('GITHUB_ACTOR = %s' , os .environ ['GITHUB_ACTOR' ])
226
+ logger .info ('GITHUB_REPOSITORY = %s' , os .environ ['GITHUB_REPOSITORY' ])
227
+
228
+ # remove .verify-helper/.gitignore
229
+ subprocess .check_call (['git' , 'config' , '--global' , 'user.name' , 'GitHub' ])
230
+ subprocess .
check_call ([
'git' ,
'config' ,
'--global' ,
'user.email' ,
'[email protected] ' ])
231
+ logger .info ('$ git rm --cached %s' , str (gitignore_path ))
232
+ subprocess .check_call (['git' , 'rm' , '--cached' , str (gitignore_path )])
233
+ message = '[auto-verifier] remove .verify-helper/.gitignore (see https://github.com/online-judge-tools/verification-helper/issues/332)'
234
+ logger .info ('$ git commit -m ...' )
235
+ subprocess .check_call (['git' , 'commit' , '-m' , message ])
236
+ logger .info ('$ git push ... HEAD' )
237
+ subprocess .check_call (['git' , 'push' , url , 'HEAD' ])
238
+
239
+ except Exception :
240
+ logger .exception ('something wrong in _delete_gitignore(). ignored.' )
241
+
242
+
204
243
def main (args : Optional [List [str ]] = None ) -> None :
205
244
# configure logging
206
245
log_format = '%(log_color)s%(levelname)s%(reset)s:%(name)s:%(message)s'
@@ -220,6 +259,7 @@ def main(args: Optional[List[str]] = None) -> None:
220
259
onlinejudge_verify .marker .get_verification_marker (jobs = parsed .jobs )
221
260
222
261
if parsed .subcommand == 'all' :
262
+ _delete_gitignore ()
223
263
generate_gitignore ()
224
264
summary = subcommand_run (paths = [], timeout = parsed .timeout , tle = parsed .tle , jobs = parsed .jobs )
225
265
subcommand_docs (jobs = parsed .jobs )
@@ -228,13 +268,15 @@ def main(args: Optional[List[str]] = None) -> None:
228
268
sys .exit (1 )
229
269
230
270
elif parsed .subcommand == 'run' :
271
+ _delete_gitignore ()
231
272
generate_gitignore ()
232
273
summary = subcommand_run (paths = parsed .path , timeout = parsed .timeout , tle = parsed .tle , jobs = parsed .jobs )
233
274
summary .show ()
234
275
if not summary .succeeded ():
235
276
sys .exit (1 )
236
277
237
278
elif parsed .subcommand == 'docs' :
279
+ _delete_gitignore ()
238
280
generate_gitignore ()
239
281
subcommand_docs (jobs = parsed .jobs )
240
282
0 commit comments