Title: [292060] trunk/Tools
Revision
292060
Author
jbed...@apple.com
Date
2022-03-29 13:06:07 -0700 (Tue, 29 Mar 2022)

Log Message

[Merge-Queue] Canonicalize commit
https://bugs.webkit.org/show_bug.cgi?id=238453
<rdar://problem/90921217>

Reviewed by Dewei Zhu.

Before pushing to Subversion, we want to include the canonical
link in the commit message.

* Tools/CISupport/ews-build/factories.py:
(MergeQueueFactory.__init__): Add Canonicalize step.
* Tools/CISupport/ews-build/factories_unittest.py:
(TestExpectedBuildSteps): Ditto.
* Tools/CISupport/ews-build/steps.py:
(Canonicalize):
(Canonicalize.__init__):
(Canonicalize.doStepIf): Only canonicalize pull requests.
(Canonicalize.hideStepIf): Hide step if we aren't doing it.
(Canonicalize.run): Update the base branch, rebase the source branch
then move the base branch to the tip of the source branch. Finally,
canonicalize the new commit.
(Canonicalize.getResultSummary):
* Tools/CISupport/ews-build/steps_unittest.py:

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

Modified Paths

Diff

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


--- trunk/Tools/CISupport/ews-build/factories.py	2022-03-29 19:49:08 UTC (rev 292059)
+++ trunk/Tools/CISupport/ews-build/factories.py	2022-03-29 20:06:07 UTC (rev 292060)
@@ -24,8 +24,8 @@
 from buildbot.process import factory
 from buildbot.steps import trigger
 
-from steps import (AddReviewerToCommitMessage, AddReviewerToChangeLog, ApplyPatch, ApplyWatchList, CheckOutPullRequest, CheckOutSource,
-                   CheckOutSpecificRevision, CheckChangeRelevance,
+from steps import (AddReviewerToCommitMessage, AddReviewerToChangeLog, ApplyPatch, ApplyWatchList, Canonicalize, CheckOutPullRequest,
+                   CheckOutSource, CheckOutSpecificRevision, CheckChangeRelevance,
                    CheckPatchStatusOnEWSQueues, CheckStyle, CleanGitRepo, CompileJSC, CompileWebKit, ConfigureBuild, CreateLocalGITCommit,
                    DownloadBuiltProduct, ExtractBuiltProduct, FetchBranches, FindModifiedChangeLogs, FindModifiedLayoutTests,
                    InstallGtkDependencies, InstallWpeDependencies, KillOldProcesses, PrintConfiguration, PushCommitToWebKitRepo,
@@ -336,3 +336,4 @@
         self.addStep(AddReviewerToChangeLog())
         self.addStep(ValidateCommitMessage())
         self.addStep(ValidateChangeLogAndReviewer())
+        self.addStep(Canonicalize())

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


--- trunk/Tools/CISupport/ews-build/factories_unittest.py	2022-03-29 19:49:08 UTC (rev 292059)
+++ trunk/Tools/CISupport/ews-build/factories_unittest.py	2022-03-29 20:06:07 UTC (rev 292060)
@@ -643,6 +643,7 @@
             'add-reviewer-to-changelog',
             'validate-commit-message',
             'validate-changelog-and-reviewer',
+            'canonicalize-commit',
         ],
     }
 

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


--- trunk/Tools/CISupport/ews-build/steps.py	2022-03-29 19:49:08 UTC (rev 292059)
+++ trunk/Tools/CISupport/ews-build/steps.py	2022-03-29 20:06:07 UTC (rev 292060)
@@ -4785,3 +4785,41 @@
 
     def hideStepIf(self, results, step):
         return not self.doStepIf(step)
+
+
+class Canonicalize(steps.ShellSequence, ShellMixin):
+    name = 'canonicalize-commit'
+    description = ['canonicalize-commit']
+    descriptionDone = ['Canonicalize Commit']
+    haltOnFailure = True
+
+    def __init__(self, **kwargs):
+        super(Canonicalize, self).__init__(logEnviron=False, timeout=300, **kwargs)
+
+    def run(self):
+        self.commands = []
+
+        base_ref = self.getProperty('github.base.ref', DEFAULT_BRANCH)
+        head_ref = self.getProperty('github.head.ref', DEFAULT_BRANCH)
+
+        for command in [
+            ['git', 'pull', 'origin', base_ref],
+            ['git', 'branch', '-f', base_ref, head_ref],
+            ['python3', 'Tools/Scripts/git-webkit', 'canonicalize', '-n', '1'],
+        ]:
+            self.commands.append(util.ShellArg(command=command, logname='stdio', haltOnFailure=True))
+
+        return super(Canonicalize, self).run()
+
+    def getResultSummary(self):
+        if self.results == SKIPPED:
+            return {'step': 'Cannot canonicalize patches'}
+        if self.results != SUCCESS:
+            return {'step': 'Failed to canonicalize commit'}
+        return {'step': 'Canonicalized commit'}
+
+    def doStepIf(self, step):
+        return self.getProperty('github.number', False)
+
+    def hideStepIf(self, results, step):
+        return not self.doStepIf(step)

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


--- trunk/Tools/CISupport/ews-build/steps_unittest.py	2022-03-29 19:49:08 UTC (rev 292059)
+++ trunk/Tools/CISupport/ews-build/steps_unittest.py	2022-03-29 20:06:07 UTC (rev 292060)
@@ -43,7 +43,7 @@
 
 from steps import (AddReviewerToCommitMessage, AddReviewerToChangeLog, AnalyzeAPITestsResults, AnalyzeCompileWebKitResults, AnalyzeJSCTestsResults,
                    AnalyzeLayoutTestsResults, ApplyPatch, ApplyWatchList, ArchiveBuiltProduct, ArchiveTestResults, BugzillaMixin,
-                   CheckOutPullRequest, CheckOutSource, CheckOutSpecificRevision, CheckChangeRelevance, CheckPatchStatusOnEWSQueues, CheckStyle,
+                   Canonicalize, CheckOutPullRequest, CheckOutSource, CheckOutSpecificRevision, CheckChangeRelevance, CheckPatchStatusOnEWSQueues, CheckStyle,
                    CleanBuild, CleanUpGitIndexLock, CleanGitRepo, CleanWorkingDirectory, CompileJSC, CompileJSCWithoutChange,
                    CompileWebKit, CompileWebKitWithoutChange, ConfigureBuild, ConfigureBuild, Contributors, CreateLocalGITCommit,
                    DownloadBuiltProduct, DownloadBuiltProductFromMaster, EWS_BUILD_HOSTNAME, ExtractBuiltProduct, ExtractTestResults,
@@ -5955,5 +5955,74 @@
         return self.runStep()
 
 
+class TestCanonicalize(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(Canonicalize())
+        self.setProperty('patch_id', '1234')
+        self.expectOutcome(result=SKIPPED, state_string='Cannot canonicalize patches')
+        return self.runStep()
+
+    def test_success(self):
+        self.setupStep(Canonicalize())
+        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',
+                timeout=300,
+                logEnviron=False,
+                command=['git', 'pull', 'origin', 'main'],
+            ) + 0, ExpectShell(
+                workdir='wkdir',
+                timeout=300,
+                logEnviron=False,
+                command=['git', 'branch', '-f', 'main', 'eng/pull-request-branch'],
+            ) + 0, ExpectShell(
+                workdir='wkdir',
+                timeout=300,
+                logEnviron=False,
+                command=['python3', 'Tools/Scripts/git-webkit', 'canonicalize', '-n', '1'],
+            ) + 0,
+        )
+        self.expectOutcome(result=SUCCESS, state_string='Canonicalized commit')
+        return self.runStep()
+
+    def test_failure(self):
+        self.setupStep(Canonicalize())
+        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',
+                timeout=300,
+                logEnviron=False,
+                command=['git', 'pull', 'origin', 'main'],
+            ) + 0, ExpectShell(
+                workdir='wkdir',
+                timeout=300,
+                logEnviron=False,
+                command=['git', 'branch', '-f', 'main', 'eng/pull-request-branch'],
+            ) + 0, ExpectShell(
+                workdir='wkdir',
+                timeout=300,
+                logEnviron=False,
+                command=['python3', 'Tools/Scripts/git-webkit', 'canonicalize', '-n', '1'],
+            ) + 1,
+        )
+        self.expectOutcome(result=FAILURE, state_string='Failed to canonicalize commit')
+        return self.runStep()
+
+
 if __name__ == '__main__':
     unittest.main()

Modified: trunk/Tools/ChangeLog (292059 => 292060)


--- trunk/Tools/ChangeLog	2022-03-29 19:49:08 UTC (rev 292059)
+++ trunk/Tools/ChangeLog	2022-03-29 20:06:07 UTC (rev 292060)
@@ -1,5 +1,31 @@
 2022-03-29  Jonathan Bedard  <jbed...@apple.com>
 
+        [Merge-Queue] Canonicalize commit
+        https://bugs.webkit.org/show_bug.cgi?id=238453
+        <rdar://problem/90921217>
+
+        Reviewed by Dewei Zhu.
+
+        Before pushing to Subversion, we want to include the canonical
+        link in the commit message.
+
+        * CISupport/ews-build/factories.py:
+        (MergeQueueFactory.__init__): Add Canonicalize step.
+        * CISupport/ews-build/factories_unittest.py:
+        (TestExpectedBuildSteps): Ditto.
+        * CISupport/ews-build/steps.py:
+        (Canonicalize):
+        (Canonicalize.__init__):
+        (Canonicalize.doStepIf): Only canonicalize pull requests.
+        (Canonicalize.hideStepIf): Hide step if we aren't doing it.
+        (Canonicalize.run): Update the base branch, rebase the source branch
+        then move the base branch to the tip of the source branch. Finally,
+        canonicalize the new commit.
+        (Canonicalize.getResultSummary):
+        * CISupport/ews-build/steps_unittest.py:
+
+2022-03-29  Jonathan Bedard  <jbed...@apple.com>
+
         [Merge-Queue] Add Reviewers to ChangeLog files
         https://bugs.webkit.org/show_bug.cgi?id=238396
         <rdar://problem/90860335>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to