@@ -327,3 +327,76 @@ def update_for_pending_release():
327
327
'commit' , '-m' ,
328
328
'Bump version to %s and update changelog\n \n [skip ci]' % (__version__ ,)
329
329
)
330
+
331
+
332
+ def could_affect_tests (path ):
333
+ """Does this file have any effect on test results?"""
334
+ # RST files are the input to some tests -- in particular, the
335
+ # documentation build and doctests. Both of those jobs are always run,
336
+ # so we can ignore their effect here.
337
+ #
338
+ # IPython notebooks aren't currently used in any tests.
339
+ if path .endswith (('.rst' , '.ipynb' )):
340
+ return False
341
+
342
+ # These files exist but have no effect on tests.
343
+ if path in ('CITATION' , 'LICENSE.txt' , ):
344
+ return False
345
+
346
+ # We default to marking a file "interesting" unless we know otherwise --
347
+ # it's better to run tests that could have been skipped than skip tests
348
+ # when they needed to be run.
349
+ return True
350
+
351
+
352
+ def changed_files_from_master ():
353
+ """Returns a list of files which have changed between a branch and
354
+ master."""
355
+ files = set ()
356
+ command = ['git' , 'diff' , '--name-only' , 'HEAD' , 'master' ]
357
+ diff_output = subprocess .check_output (command ).decode ('ascii' )
358
+ for line in diff_output .splitlines ():
359
+ filepath = line .strip ()
360
+ if filepath :
361
+ files .add (filepath )
362
+ return files
363
+
364
+
365
+ def should_run_ci_task (task , is_pull_request ):
366
+ """Given a task name, should we run this task?"""
367
+ if not is_pull_request :
368
+ print ('We only skip tests if the job is a pull request.' )
369
+ return True
370
+
371
+ # These tests are usually fast; we always run them rather than trying
372
+ # to keep up-to-date rules of exactly which changed files mean they
373
+ # should run.
374
+ if task in [
375
+ 'check-pyup-yml' ,
376
+ 'check-release-file' ,
377
+ 'check-shellcheck' ,
378
+ 'documentation' ,
379
+ 'lint' ,
380
+ ]:
381
+ print ('We always run the %s task.' % task )
382
+ return True
383
+
384
+ # The remaining tasks are all some sort of test of Hypothesis
385
+ # functionality. Since it's better to run tests when we don't need to
386
+ # than skip tests when it was important, we remove any files which we
387
+ # know are safe to ignore, and run tests if there's anything left.
388
+ changed_files = changed_files_from_master ()
389
+
390
+ interesting_changed_files = [
391
+ f for f in changed_files if could_affect_tests (f )
392
+ ]
393
+
394
+ if interesting_changed_files :
395
+ print (
396
+ 'Changes to the following files mean we need to run tests: %s' %
397
+ ', ' .join (interesting_changed_files )
398
+ )
399
+ return True
400
+ else :
401
+ print ('There are no changes which would need a test run.' )
402
+ return False
0 commit comments