@@ -509,17 +509,18 @@ def schedule_test(gh_commit, commit, test_type, branch="master", pr_nr=0) -> Non
509
509
log .critical (f'Could not post to GitHub! Response: { a .response } ' )
510
510
511
511
512
- def deschedule_test (gh_commit , commit , test_type , message = "Tests have been cancelled" , branch = "master" , pr_nr = 0 ,
513
- state = Status .FAILURE ) -> None :
512
+ def deschedule_test (gh_commit , platform , message = "Tests have been cancelled" , state = Status .FAILURE ) -> None :
514
513
"""
515
514
Post status to GitHub (default: as failure due to Github Actions incompletion).
516
515
517
516
:param gh_commit: The GitHub API call for the commit. Can be None
518
517
:type gh_commit: Any
519
518
:param commit: The commit hash.
520
519
:type commit: str
521
- :param test_type: The type of test
522
- :type test_type: TestType
520
+ :param platform: The platform name
521
+ :type platform: TestPlatform
522
+ :param message: The message to be posted to GitHub
523
+ :type message: str
523
524
:param branch: Branch name
524
525
:type branch: str
525
526
:param pr_nr: Pull Request number, if applicable.
@@ -530,29 +531,28 @@ def deschedule_test(gh_commit, commit, test_type, message="Tests have been cance
530
531
from run import log
531
532
532
533
if gh_commit is not None :
533
- for platform in TestPlatform :
534
- try :
535
- gh_commit .post (
536
- state = state ,
537
- description = message ,
538
- context = f"CI - { platform .value } " ,
539
- )
540
- except ApiError as a :
541
- log .critical (f'Could not post to GitHub! Response: { a .response } ' )
534
+ try :
535
+ gh_commit .post (
536
+ state = state ,
537
+ description = message ,
538
+ context = f"CI - { platform .value } " ,
539
+ )
540
+ except ApiError as a :
541
+ log .critical (f'Could not post to GitHub! Response: { a .response } ' )
542
542
543
543
544
- def queue_test (db , gh_commit , commit , test_type , branch = "master" , pr_nr = 0 ) -> None :
544
+ def queue_test (gh_commit , commit , test_type , platform , branch = "master" , pr_nr = 0 ) -> None :
545
545
"""
546
546
Store test details into Test model for each platform, and post the status to GitHub.
547
547
548
- :param db: Database connection.
549
- :type db: sqlalchemy.orm.scoped_session
550
548
:param gh_commit: The GitHub API call for the commit. Can be None
551
549
:type gh_commit: Any
552
550
:param commit: The commit hash.
553
551
:type commit: str
554
552
:param test_type: The type of test
555
553
:type test_type: TestType
554
+ :param platform: The platform name
555
+ :type platform: TestPlatform
556
556
:param branch: Branch name
557
557
:type branch: str
558
558
:param pr_nr: Pull Request number, if applicable.
@@ -569,38 +569,25 @@ def queue_test(db, gh_commit, commit, test_type, branch="master", pr_nr=0) -> No
569
569
log .debug ('pull request test type detected' )
570
570
branch = "pull_request"
571
571
572
- linux_test = Test .query .filter (and_ (Test .platform == TestPlatform .linux ,
573
- Test .commit == commit ,
574
- Test .fork_id == fork .id ,
575
- Test .test_type == test_type ,
576
- Test .branch == branch ,
577
- Test .pr_nr == pr_nr
578
- )).first ()
579
- windows_test = Test .query .filter (and_ (Test .platform == TestPlatform .windows ,
580
- Test .commit == commit ,
581
- Test .fork_id == fork .id ,
582
- Test .test_type == test_type ,
583
- Test .branch == branch ,
584
- Test .pr_nr == pr_nr
585
- )).first ()
586
- add_customized_regression_tests (linux_test .id )
587
- add_customized_regression_tests (windows_test .id )
572
+ platform_test = Test .query .filter (and_ (Test .platform == platform ,
573
+ Test .commit == commit ,
574
+ Test .fork_id == fork .id ,
575
+ Test .test_type == test_type ,
576
+ Test .branch == branch ,
577
+ Test .pr_nr == pr_nr
578
+ )).first ()
579
+ add_customized_regression_tests (platform_test .id )
588
580
589
581
if gh_commit is not None :
590
- status_entries = {
591
- linux_test .platform .value : linux_test .id ,
592
- windows_test .platform .value : windows_test .id
593
- }
594
- for platform_name , test_id in status_entries .items ():
595
- try :
596
- gh_commit .post (
597
- state = Status .PENDING ,
598
- description = "Tests queued" ,
599
- context = f"CI - { platform_name } " ,
600
- target_url = url_for ('test.by_id' , test_id = test_id , _external = True )
601
- )
602
- except ApiError as a :
603
- log .critical (f'Could not post to GitHub! Response: { a .response } ' )
582
+ try :
583
+ gh_commit .post (
584
+ state = Status .PENDING ,
585
+ description = "Tests queued" ,
586
+ context = f"CI - { platform_test .platform .value } " ,
587
+ target_url = url_for ('test.by_id' , test_id = platform_test .id , _external = True )
588
+ )
589
+ except ApiError as a :
590
+ log .critical (f'Could not post to GitHub! Response: { a .response } ' )
604
591
605
592
log .debug ("Created tests, waiting for cron..." )
606
593
@@ -844,24 +831,26 @@ def start_ci():
844
831
if workflow ['conclusion' ] != "success" :
845
832
has_failed = True
846
833
break
847
- if workflow ['name' ] == "Build CCExtractor on Linux" :
834
+ if workflow ['name' ] == Workflow_builds . LINUX :
848
835
builds ["linux" ] = True
849
- elif workflow ['name' ] == "Build CCExtractor on Windows" :
836
+ elif workflow ['name' ] == Workflow_builds . WINDOWS :
850
837
builds ["windows" ] = True
851
838
elif workflow ['status' ] != "completed" :
852
839
is_complete = False
853
840
break
854
841
855
842
if has_failed :
856
843
# no runs to be scheduled since build failed
857
- deschedule_test (github_status , commit_hash , TestType .commit ,
844
+ deschedule_test (github_status , TestPlatform .linux ,
845
+ message = "Cancelling tests as Github Action(s) failed" )
846
+ deschedule_test (github_status , TestPlatform .windows ,
858
847
message = "Cancelling tests as Github Action(s) failed" )
859
848
elif is_complete :
860
849
if payload ['workflow_run' ]['event' ] == "pull_request" :
861
850
# In case of pull request run tests only if it is still in an open state
862
851
# and user is not blacklisted
863
852
for pull_request in repository .pulls .get (state = "open" ):
864
- if pull_request ['head' ]['sha' ] == commit_hash and any ( builds . values ()) :
853
+ if pull_request ['head' ]['sha' ] == commit_hash :
865
854
user_id = pull_request ['user' ]['id' ]
866
855
if BlockedUsers .query .filter (BlockedUsers .user_id == user_id ).first () is not None :
867
856
g .log .warning ("User Blacklisted" )
@@ -872,13 +861,37 @@ def start_ci():
872
861
target_url = url_for ('home.index' , _external = True )
873
862
)
874
863
return 'ERROR'
875
- queue_test (g .db , github_status , commit_hash ,
876
- TestType .pull_request , pr_nr = pull_request ['number' ])
877
- elif any (builds .values ()):
878
- queue_test (g .db , github_status , commit_hash , TestType .commit )
864
+ if builds ['linux' ]:
865
+ queue_test (github_status , commit_hash , TestType .pull_request ,
866
+ TestPlatform .linux , pr_nr = pull_request ['number' ])
867
+ else :
868
+ deschedule_test (github_status , TestPlatform .linux ,
869
+ message = "Not ran - no code changes" , state = Status .SUCCESS )
870
+ if builds ['windows' ]:
871
+ queue_test (github_status , commit_hash , TestType .pull_request ,
872
+ TestPlatform .windows , pr_nr = pull_request ['number' ])
873
+ else :
874
+ deschedule_test (github_status , TestPlatform .windows ,
875
+ message = "Not ran - no code changes" , state = Status .SUCCESS )
876
+ return json .dumps ({'msg' : 'EOL' })
877
+ # Either PR head commit was updated or PR was closed, therefore cancelling tests
878
+ deschedule_test (github_status , TestPlatform .linux ,
879
+ message = "Tests cancelled" , state = Status .FAILURE )
880
+ deschedule_test (github_status , TestPlatform .windows ,
881
+ message = "Tests cancelled" , state = Status .FAILURE )
879
882
else :
880
- deschedule_test (github_status , commit_hash , TestType .commit ,
881
- message = "Not ran - no code changes" , state = Status .SUCCESS )
883
+ if builds ['linux' ]:
884
+ queue_test (github_status , commit_hash ,
885
+ TestType .commit , TestPlatform .linux )
886
+ else :
887
+ deschedule_test (github_status , TestPlatform .linux ,
888
+ message = "Not ran - no code changes" , state = Status .SUCCESS )
889
+ if builds ['windows' ]:
890
+ queue_test (github_status , commit_hash ,
891
+ TestType .commit , TestPlatform .windows )
892
+ else :
893
+ deschedule_test (github_status , TestPlatform .windows ,
894
+ message = "Not ran - no code changes" , state = Status .SUCCESS )
882
895
elif payload ['action' ] == 'requested' :
883
896
schedule_test (github_status , commit_hash , TestType .commit )
884
897
else :
0 commit comments