Title: [291627] trunk/Tools
Revision
291627
Author
jbed...@apple.com
Date
2022-03-22 10:30:16 -0700 (Tue, 22 Mar 2022)

Log Message

[Merge-Queue] Add ValidateSquashed
https://bugs.webkit.org/show_bug.cgi?id=238172
<rdar://problem/90602594>

Reviewed by Aakash Jain.

* Tools/CISupport/ews-build/factories.py:
(MergeQueueFactory.__init__): Add ValidateSquashed.
* Tools/CISupport/ews-build/factories_unittest.py:
(TestExpectedBuildSteps): Ditto.
* Tools/CISupport/ews-build/steps.py:
(VerifyGitHubIntegrity.send_email_for_github_issue):
(ValidateSquashed): Ensure that a pull request only has a single commit.
(ValidateSquashed.__init__): Do not log environment variables.
(ValidateSquashed.start): Log commits between the HEAD branch and base branch.
(ValidateSquashed.getResultSummary):
(ValidateSquashed.evaluateCommand): Check number of commits between HEAD and base branch.
(ValidateSquashed.doStepIf): Only run step for pull requests.
(ValidateSquashed.hideStepIf): Hide step if we aren't running it.

Canonical link: https://commits.webkit.org/248720@main

Modified Paths

Diff

Modified: trunk/Tools/CISupport/ews-build/factories.py (291626 => 291627)


--- trunk/Tools/CISupport/ews-build/factories.py	2022-03-22 17:19:45 UTC (rev 291626)
+++ trunk/Tools/CISupport/ews-build/factories.py	2022-03-22 17:30:16 UTC (rev 291627)
@@ -33,7 +33,7 @@
                    RunWebKitPyPython3Tests, RunWebKitTests, RunWebKitTestsRedTree, RunWebKitTestsInStressMode, RunWebKitTestsInStressGuardmallocMode,
                    SetBuildSummary, ShowIdentifier, TriggerCrashLogSubmission, UpdateWorkingDirectory,
                    ValidateChange, ValidateChangeLogAndReviewer, ValidateCommitterAndReviewer, WaitForCrashCollection,
-                   InstallBuiltProduct, VerifyGitHubIntegrity)
+                   InstallBuiltProduct, VerifyGitHubIntegrity, ValidateSquashed)
 
 
 class Factory(factory.BuildFactory):
@@ -330,3 +330,4 @@
         self.addStep(VerifyGitHubIntegrity())
         self.addStep(UpdateWorkingDirectory())
         self.addStep(CheckOutPullRequest())
+        self.addStep(ValidateSquashed())

Modified: trunk/Tools/CISupport/ews-build/factories_unittest.py (291626 => 291627)


--- trunk/Tools/CISupport/ews-build/factories_unittest.py	2022-03-22 17:19:45 UTC (rev 291626)
+++ trunk/Tools/CISupport/ews-build/factories_unittest.py	2022-03-22 17:30:16 UTC (rev 291627)
@@ -637,7 +637,8 @@
             'show-identifier',
             'verify-github-integrity',
             'update-working-directory',
-            'checkout-pull-request'
+            'checkout-pull-request',
+            'validate-squashed',
         ],
     }
 

Modified: trunk/Tools/CISupport/ews-build/steps.py (291626 => 291627)


--- trunk/Tools/CISupport/ews-build/steps.py	2022-03-22 17:19:45 UTC (rev 291626)
+++ trunk/Tools/CISupport/ews-build/steps.py	2022-03-22 17:30:16 UTC (rev 291627)
@@ -4582,3 +4582,44 @@
             send_email_to_github_admin(email_subject, email_text)
         except Exception as e:
             print('Error in sending email for github issue: {}'.format(e))
+
+
+class ValidateSquashed(shell.ShellCommand):
+    name = 'validate-squashed'
+    haltOnFailure = True
+
+    def __init__(self, **kwargs):
+        super(ValidateSquashed, self).__init__(logEnviron=False, **kwargs)
+
+    def start(self, BufferLogObserverClass=logobserver.BufferLogObserver):
+        base_ref = self.getProperty('github.base.ref', DEFAULT_BRANCH)
+        head_ref = self.getProperty('github.head.ref', DEFAULT_BRANCH)
+        self.command = ['git', 'log', '--oneline', head_ref, f'^{base_ref}', '--max-count=2']
+
+        self.log_observer = BufferLogObserverClass(wantStderr=True)
+        self.addLogObserver('stdio', self.log_observer)
+
+        return shell.ShellCommand.start(self)
+
+    def getResultSummary(self):
+        if self.results == SKIPPED:
+            return {'step': 'Patches are always squashed'}
+        elif self.results == SUCCESS:
+            return {'step': 'Verified branch is squashed'}
+        return {'step': 'Can only land squashed branches'}
+
+    def evaluateCommand(self, cmd):
+        rc = shell.ShellCommand.evaluateCommand(self, cmd)
+        if rc != SUCCESS:
+            return rc
+
+        log_text = self.log_observer.getStdout()
+        if len(log_text.splitlines()) == 1:
+            return SUCCESS
+        return FAILURE
+
+    def doStepIf(self, step):
+        return self.getProperty('github.number')
+
+    def hideStepIf(self, results, step):
+        return not self.doStepIf(step)

Modified: trunk/Tools/CISupport/ews-build/steps_unittest.py (291626 => 291627)


--- trunk/Tools/CISupport/ews-build/steps_unittest.py	2022-03-22 17:19:45 UTC (rev 291626)
+++ trunk/Tools/CISupport/ews-build/steps_unittest.py	2022-03-22 17:30:16 UTC (rev 291627)
@@ -56,7 +56,7 @@
                    RunWebKitTestsWithoutChange, RunWebKitTestsRedTree, RunWebKitTestsRepeatFailuresRedTree, RunWebKitTestsRepeatFailuresWithoutChangeRedTree,
                    RunWebKitTestsWithoutChangeRedTree, AnalyzeLayoutTestsResultsRedTree, TestWithFailureCount, ShowIdentifier,
                    Trigger, TransferToS3, UnApplyPatch, UpdateWorkingDirectory, UploadBuiltProduct,
-                   UploadTestResults, ValidateChangeLogAndReviewer, ValidateCommitterAndReviewer, ValidateChange, VerifyGitHubIntegrity)
+                   UploadTestResults, ValidateChangeLogAndReviewer, ValidateCommitterAndReviewer, ValidateChange, VerifyGitHubIntegrity, ValidateSquashed)
 
 # Workaround for https://github.com/buildbot/buildbot/issues/4669
 from buildbot.test.fake.fakebuild import FakeBuild
@@ -5590,5 +5590,71 @@
         return self.runStep()
 
 
+class TestValidateSquashed(BuildStepMixinAdditions, unittest.TestCase):
+    def setUp(self):
+        self.longMessage = True
+        return self.setUpBuildStep()
+
+    def tearDown(self):
+        return self.tearDownBuildStep()
+
+    def test_skipped_patch(self):
+        self.setupStep(ValidateSquashed())
+        self.setProperty('patch_id', '1234')
+        self.expectOutcome(result=SKIPPED, state_string='Patches are always squashed')
+        return self.runStep()
+
+    def test_success(self):
+        self.setupStep(ValidateSquashed())
+        self.setProperty('github.number', '1234')
+        self.setProperty('github.base.ref', 'main')
+        self.setProperty('github.head.ref', 'eng/pull-request-branch')
+        self.expectRemoteCommands(
+            ExpectShell(workdir='wkdir',
+                        logEnviron=False,
+                        command=['git', 'log', '--oneline', 'eng/pull-request-branch', '^main', '--max-count=2'],
+                        )
+            + 0
+            + ExpectShell.log('stdio', stdout='e1eb24603493 (HEAD -> eng/pull-request-branch) First line of commit\n'),
+        )
+        self.expectOutcome(result=SUCCESS, state_string='Verified branch is squashed')
+        return self.runStep()
+
+    def test_failure_multiple_commits(self):
+        self.setupStep(ValidateSquashed())
+        self.setProperty('github.number', '1234')
+        self.setProperty('github.base.ref', 'main')
+        self.setProperty('github.head.ref', 'eng/pull-request-branch')
+        self.expectRemoteCommands(
+            ExpectShell(workdir='wkdir',
+                        logEnviron=False,
+                        command=['git', 'log', '--oneline', 'eng/pull-request-branch', '^main', '--max-count=2'],
+                        )
+            + 0
+            + ExpectShell.log('stdio', stdout='''e1eb24603493 (HEAD -> eng/pull-request-branch) Commit Series (3)
+08abb9ddcbb5 Commit Series (2)
+45cf3efe4dfb Commit Series (1)
+'''),
+        )
+        self.expectOutcome(result=FAILURE, state_string='Can only land squashed branches')
+        return self.runStep()
+
+    def test_failure_merged(self):
+        self.setupStep(ValidateSquashed())
+        self.setProperty('github.number', '1234')
+        self.setProperty('github.base.ref', 'main')
+        self.setProperty('github.head.ref', 'eng/pull-request-branch')
+        self.expectRemoteCommands(
+            ExpectShell(workdir='wkdir',
+                        logEnviron=False,
+                        command=['git', 'log', '--oneline', 'eng/pull-request-branch', '^main', '--max-count=2'],
+                        )
+            + 0
+            + ExpectShell.log('stdio', stdout=''),
+        )
+        self.expectOutcome(result=FAILURE, state_string='Can only land squashed branches')
+        return self.runStep()
+
+
 if __name__ == '__main__':
     unittest.main()

Modified: trunk/Tools/ChangeLog (291626 => 291627)


--- trunk/Tools/ChangeLog	2022-03-22 17:19:45 UTC (rev 291626)
+++ trunk/Tools/ChangeLog	2022-03-22 17:30:16 UTC (rev 291627)
@@ -1,3 +1,25 @@
+2022-03-22  Jonathan Bedard  <jbed...@apple.com>
+
+        [Merge-Queue] Add ValidateSquashed
+        https://bugs.webkit.org/show_bug.cgi?id=238172
+        <rdar://problem/90602594>
+
+        Reviewed by Aakash Jain.
+
+        * CISupport/ews-build/factories.py:
+        (MergeQueueFactory.__init__): Add ValidateSquashed.
+        * CISupport/ews-build/factories_unittest.py:
+        (TestExpectedBuildSteps): Ditto.
+        * CISupport/ews-build/steps.py:
+        (VerifyGitHubIntegrity.send_email_for_github_issue):
+        (ValidateSquashed): Ensure that a pull request only has a single commit.
+        (ValidateSquashed.__init__): Do not log environment variables.
+        (ValidateSquashed.start): Log commits between the HEAD branch and base branch.
+        (ValidateSquashed.getResultSummary):
+        (ValidateSquashed.evaluateCommand): Check number of commits between HEAD and base branch.
+        (ValidateSquashed.doStepIf): Only run step for pull requests.
+        (ValidateSquashed.hideStepIf): Hide step if we aren't running it.
+
 2022-03-22  J Pascoe  <j_pas...@apple.com>
 
         [WebAuthn] Pass along timeout to ASA and ignore timeout for conditional mediation requests
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to