Title: [288314] trunk/Tools
Revision
288314
Author
[email protected]
Date
2022-01-20 12:34:39 -0800 (Thu, 20 Jan 2022)

Log Message

[EWS] Add CheckOutPullRequest step
https://bugs.webkit.org/show_bug.cgi?id=235157
<rdar://problem/87487209 >

Reviewed by Aakash Jain.

* Tools/CISupport/ews-build/factories.py:
(Factory.__init__): Add CheckOutPullRequest step.
(StyleFactory.__init__): Ditto.
(WatchListFactory.__init__): Ditto.
* Tools/CISupport/ews-build/factories_unittest.py:
(TestExpectedBuildSteps): Add CheckOutPullRequest step.
* Tools/CISupport/ews-build/steps.py:
(ApplyPatch.doStepIf): Only run step if a patch is provided.
(ApplyPatch.hideStepIf): Only display step if a patch was provided.
(ApplyPatch.getResultSummary): Add SKIPPED description.
(CheckOutPullRequest):
(CheckOutPullRequest.__init__):
(CheckOutPullRequest.doStepIf): Only run step if a pull request is provided.
(CheckOutPullRequest.hideStepIf): Only display step if a pul request was provided.
(CheckOutPullRequest.run): Configure new remote, fetch remote and checkout pull request
branch from the newly configured remote.
(CheckOutPullRequest.getResultSummary):
* Tools/CISupport/ews-build/steps_unittest.py:

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

Modified Paths

Diff

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


--- trunk/Tools/CISupport/ews-build/factories.py	2022-01-20 20:02:38 UTC (rev 288313)
+++ trunk/Tools/CISupport/ews-build/factories.py	2022-01-20 20:34:39 UTC (rev 288314)
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2021 Apple Inc. All rights reserved.
+# Copyright (C) 2018-2022 Apple Inc. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -24,7 +24,7 @@
 from buildbot.process import factory
 from buildbot.steps import trigger
 
-from steps import (ApplyPatch, ApplyWatchList, CheckOutSource, CheckOutSpecificRevision, CheckPatchRelevance,
+from steps import (ApplyPatch, ApplyWatchList, CheckOutPullRequest, CheckOutSource, CheckOutSpecificRevision, CheckPatchRelevance,
                    CheckPatchStatusOnEWSQueues, CheckStyle, CleanGitRepo, CompileJSC, CompileWebKit, ConfigureBuild, CreateLocalGITCommit,
                    DownloadBuiltProduct, ExtractBuiltProduct, FetchBranches, FindModifiedChangeLogs, FindModifiedLayoutTests,
                    InstallGtkDependencies, InstallWpeDependencies, KillOldProcesses, PrintConfiguration, PushCommitToWebKitRepo,
@@ -57,6 +57,7 @@
         self.addStep(FetchBranches())
         self.addStep(ShowIdentifier())
         self.addStep(ApplyPatch())
+        self.addStep(CheckOutPullRequest())
 
 
 class StyleFactory(factory.BuildFactory):
@@ -71,6 +72,7 @@
         self.addStep(ShowIdentifier())
         self.addStep(UpdateWorkingDirectory())
         self.addStep(ApplyPatch())
+        self.addStep(CheckOutPullRequest())
         self.addStep(CheckStyle())
 
 
@@ -86,6 +88,7 @@
         self.addStep(ShowIdentifier())
         self.addStep(UpdateWorkingDirectory())
         self.addStep(ApplyPatch())
+        self.addStep(CheckOutPullRequest())
         self.addStep(ApplyWatchList())
 
 

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


--- trunk/Tools/CISupport/ews-build/factories_unittest.py	2022-01-20 20:02:38 UTC (rev 288313)
+++ trunk/Tools/CISupport/ews-build/factories_unittest.py	2022-01-20 20:34:39 UTC (rev 288314)
@@ -1,4 +1,4 @@
-# Copyright (C) 2020-2021 Apple Inc. All rights reserved.
+# Copyright (C) 2020-2022 Apple Inc. All rights reserved.
 # Copyright (C) 2021 Igalia S.L.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -39,6 +39,7 @@
             'show-identifier',
             'update-working-directory',
             'apply-patch',
+            'checkout-pull-request',
             'check-webkit-style'
         ],
         'Apply-WatchList-EWS': [
@@ -51,6 +52,7 @@
             'show-identifier',
             'update-working-directory',
             'apply-patch',
+            'checkout-pull-request',
             'apply-watch-list'
         ],
         'GTK-Build-EWS': [
@@ -63,6 +65,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'kill-old-processes',
             'jhbuild',
             'compile-webkit',
@@ -78,6 +81,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'jhbuild',
             'download-built-product',
             'extract-built-product',
@@ -97,6 +101,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'kill-old-processes',
             'compile-webkit'
         ],
@@ -110,6 +115,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'kill-old-processes',
             'compile-webkit'
         ],
@@ -123,6 +129,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'download-built-product',
             'extract-built-product',
             'wait-for-crash-collection',
@@ -144,6 +151,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'kill-old-processes',
             'compile-webkit'
         ],
@@ -157,6 +165,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'download-built-product',
             'extract-built-product',
             'wait-for-crash-collection',
@@ -177,6 +186,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'kill-old-processes',
             'compile-webkit'
         ],
@@ -191,6 +201,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'download-built-product',
             'extract-built-product',
             'wait-for-crash-collection',
@@ -211,6 +222,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'download-built-product',
             'extract-built-product',
             'wait-for-crash-collection',
@@ -232,6 +244,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'download-built-product',
             'extract-built-product',
             'wait-for-crash-collection',
@@ -250,6 +263,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'kill-old-processes',
             'compile-webkit'
         ],
@@ -264,6 +278,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'download-built-product',
             'extract-built-product',
             'wait-for-crash-collection',
@@ -284,6 +299,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'kill-old-processes',
             'compile-webkit'
         ],
@@ -297,6 +313,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'kill-old-processes',
             'compile-webkit'
         ],
@@ -310,6 +327,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'kill-old-processes',
             'compile-webkit'
         ],
@@ -323,6 +341,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'kill-old-processes',
             'compile-webkit'
         ],
@@ -337,6 +356,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'kill-old-processes',
             'compile-webkit',
             'validate-change',
@@ -353,6 +373,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'kill-old-processes',
             'compile-webkit'
         ],
@@ -366,6 +387,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'kill-old-processes',
             'jhbuild',
             'compile-webkit'
@@ -381,6 +403,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'kill-old-processes',
             'compile-jsc',
             'jscore-test'
@@ -396,6 +419,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'kill-old-processes',
             'compile-jsc'
         ],
@@ -410,6 +434,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'download-built-product',
             'extract-built-product',
             'kill-old-processes',
@@ -426,6 +451,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'kill-old-processes',
             'compile-jsc'
         ],
@@ -440,6 +466,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'download-built-product',
             'extract-built-product',
             'kill-old-processes',
@@ -456,6 +483,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'kill-old-processes',
             'compile-jsc'
         ],
@@ -470,6 +498,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'bindings-tests'
         ],
         'WebKitPy-Tests-EWS': [
@@ -483,6 +512,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'webkitpy-tests-python2',
             'webkitpy-tests-python3',
             'set-build-summary'
@@ -497,6 +527,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'webkitperl-tests'
         ],
         'API-Tests-iOS-Simulator-EWS': [
@@ -509,6 +540,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'download-built-product',
             'extract-built-product',
             'kill-old-processes',
@@ -524,6 +556,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'download-built-product',
             'extract-built-product',
             'kill-old-processes',
@@ -539,6 +572,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'jhbuild',
             'download-built-product',
             'extract-built-product',
@@ -556,6 +590,7 @@
             'fetch-branch-references',
             'show-identifier',
             'apply-patch',
+            'checkout-pull-request',
             'build-webkit-org-unit-tests',
             'buildbot-check-config-for-build-webkit',
             'ews-unit-tests',

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


--- trunk/Tools/CISupport/ews-build/steps.py	2022-01-20 20:02:38 UTC (rev 288313)
+++ trunk/Tools/CISupport/ews-build/steps.py	2022-01-20 20:34:39 UTC (rev 288314)
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2021 Apple Inc. All rights reserved.
+# Copyright (C) 2018-2022 Apple Inc. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -521,6 +521,9 @@
     def __init__(self, **kwargs):
         super(ApplyPatch, self).__init__(timeout=10 * 60, logEnviron=False, **kwargs)
 
+    def doStepIf(self, step):
+        return self.getProperty('patch_id', False)
+
     def _get_patch(self):
         sourcestamp = self.build.getSourceStamp(self.getProperty('codebase', ''))
         if not sourcestamp or not sourcestamp.patch:
@@ -543,9 +546,11 @@
         d.addCallback(lambda res: shell.ShellCommand.start(self))
 
     def hideStepIf(self, results, step):
-        return results == SUCCESS and self.getProperty('sensitive', False)
+        return not self.doStepIf(step) or (results == SUCCESS and self.getProperty('sensitive', False))
 
     def getResultSummary(self):
+        if self.results == SKIPPED:
+            return {'step': "Skipping applying patch since patch_id isn't provided"}
         if self.results != SUCCESS:
             return {'step': 'svn-apply failed to apply patch to trunk'}
         return super(ApplyPatch, self).getResultSummary()
@@ -565,6 +570,47 @@
         return rc
 
 
+class CheckOutPullRequest(steps.ShellSequence):
+    name = 'checkout-pull-request'
+    description = ['checking-out-pull-request']
+    descriptionDone = ['Checked out pull request']
+    haltOnFailure = True
+
+    def __init__(self, **kwargs):
+        super(CheckOutPullRequest, self).__init__(timeout=10 * 60, logEnviron=False, **kwargs)
+
+    def doStepIf(self, step):
+        return self.getProperty('github.number', False)
+
+    def hideStepIf(self, results, step):
+        return not self.doStepIf(step)
+
+    def run(self):
+        self.commands = []
+
+        remote = self.getProperty('github.head.repo.full_name', 'origin').split('/')[0]
+        project = self.getProperty('github.head.repo.full_name', self.getProperty('project'))
+        branch = self.getProperty('github.head.ref', 'main')
+
+        for command in [
+            ['/bin/sh', '-c', 'git remote add {} {}{}.git & true'.format(remote, GITHUB_URL, project)],
+            ['git', 'remote', 'set-url', remote, '{}{}.git'.format(GITHUB_URL, project)],
+            ['git', 'fetch', remote],
+            ['git', 'branch', '-f', branch, 'remotes/{}/{}'.format(remote, branch)],
+            ['git', 'checkout', branch],
+        ]:
+            self.commands.append(util.ShellArg(command=command, logname='stdio', haltOnFailure=True))
+
+        return super(CheckOutPullRequest, self).run()
+
+    def getResultSummary(self):
+        if self.results == SKIPPED:
+            return {'step': 'No pull request to checkout'}
+        if self.results != SUCCESS:
+            return {'step': 'Failed to checkout branch from PR {}'.format(self.getProperty('github.number'))}
+        return super(CheckOutPullRequest, self).getResultSummary()
+
+
 class AnalyzePatch(buildstep.BuildStep):
     flunkOnFailure = True
     haltOnFailure = True
@@ -3743,6 +3789,7 @@
         return {'step': configuration}
 
 
+# FIXME: We should be able to remove this step once abandoning patch workflows
 class CleanGitRepo(steps.ShellSequence):
     name = 'clean-up-git-repo'
     haltOnFailure = False

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


--- trunk/Tools/CISupport/ews-build/steps_unittest.py	2022-01-20 20:02:38 UTC (rev 288313)
+++ trunk/Tools/CISupport/ews-build/steps_unittest.py	2022-01-20 20:34:39 UTC (rev 288314)
@@ -1,4 +1,4 @@
-# Copyright (C) 2018-2021 Apple Inc. All rights reserved.
+# Copyright (C) 2018-2022 Apple Inc. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -42,7 +42,7 @@
 
 from steps import (AnalyzeAPITestsResults, AnalyzeCompileWebKitResults, AnalyzeJSCTestsResults,
                    AnalyzeLayoutTestsResults, ApplyPatch, ApplyWatchList, ArchiveBuiltProduct, ArchiveTestResults,
-                   CheckOutSource, CheckOutSpecificRevision, CheckPatchRelevance, CheckPatchStatusOnEWSQueues, CheckStyle,
+                   CheckOutPullRequest, CheckOutSource, CheckOutSpecificRevision, CheckPatchRelevance, CheckPatchStatusOnEWSQueues, CheckStyle,
                    CleanBuild, CleanUpGitIndexLock, CleanGitRepo, CleanWorkingDirectory, CompileJSC, CompileJSCWithoutPatch,
                    CompileWebKit, CompileWebKitWithoutPatch, ConfigureBuild, ConfigureBuild, Contributors, CreateLocalGITCommit,
                    DownloadBuiltProduct, DownloadBuiltProductFromMaster, EWS_BUILD_HOSTNAME, ExtractBuiltProduct, ExtractTestResults,
@@ -3006,6 +3006,7 @@
 
     def test_success(self):
         self.setupStep(ApplyPatch())
+        self.setProperty('patch_id', '1234')
         self.assertEqual(ApplyPatch.flunkOnFailure, True)
         self.assertEqual(ApplyPatch.haltOnFailure, False)
         self.expectRemoteCommands(
@@ -3021,6 +3022,7 @@
 
     def test_failure(self):
         self.setupStep(ApplyPatch())
+        self.setProperty('patch_id', '1234')
         self.expectRemoteCommands(
             ExpectShell(workdir='wkdir',
                         timeout=600,
@@ -3036,6 +3038,12 @@
         self.assertEqual(self.getProperty('build_finish_summary'), None)
         return rc
 
+    def test_skipped(self):
+        self.setupStep(ApplyPatch())
+        self.expectHidden(True)
+        self.expectOutcome(result=SKIPPED, state_string="Skipping applying patch since patch_id isn't provided")
+        return self.runStep()
+
     def test_failure_on_commit_queue(self):
         self.setupStep(ApplyPatch())
         self.setProperty('buildername', 'Commit-Queue')
@@ -3056,6 +3064,87 @@
         return rc
 
 
+class TestCheckOutPullRequest(BuildStepMixinAdditions, unittest.TestCase):
+    def setUp(self):
+        self.longMessage = True
+        return self.setUpBuildStep()
+
+    def tearDown(self):
+        return self.tearDownBuildStep()
+
+    def test_success(self):
+        self.setupStep(CheckOutPullRequest())
+        self.setProperty('github.number', '1234')
+        self.setProperty('github.head.repo.full_name', 'Contributor/WebKit')
+        self.setProperty('github.head.ref', 'eng/pull-request-branch')
+        self.assertEqual(CheckOutPullRequest.flunkOnFailure, True)
+        self.assertEqual(CheckOutPullRequest.haltOnFailure, True)
+        self.expectRemoteCommands(
+            ExpectShell(
+                workdir='wkdir',
+                timeout=600,
+                logEnviron=False,
+                command=['/bin/sh', '-c', 'git remote add Contributor https://github.com/Contributor/WebKit.git & true'],
+            ) + 0, ExpectShell(
+                workdir='wkdir',
+                timeout=600,
+                logEnviron=False,
+                command=['git', 'remote', 'set-url', 'Contributor', 'https://github.com/Contributor/WebKit.git'],
+            ) + 0, ExpectShell(
+                workdir='wkdir',
+                timeout=600,
+                logEnviron=False,
+                command=['git', 'fetch', 'Contributor'],
+            ) + 0, ExpectShell(
+                workdir='wkdir',
+                timeout=600,
+                logEnviron=False,
+                command=['git', 'branch', '-f', 'eng/pull-request-branch', 'remotes/Contributor/eng/pull-request-branch'],
+            ) + 0, ExpectShell(
+                workdir='wkdir',
+                timeout=600,
+                logEnviron=False,
+                command=['git', 'checkout', 'eng/pull-request-branch'],
+            ) + 0,
+        )
+        self.expectOutcome(result=SUCCESS, state_string='Checked out pull request')
+        return self.runStep()
+
+    def test_failure(self):
+        self.setupStep(CheckOutPullRequest())
+        self.setProperty('github.number', '1234')
+        self.setProperty('github.head.repo.full_name', 'Contributor/WebKit')
+        self.setProperty('github.head.ref', 'eng/pull-request-branch')
+        self.assertEqual(CheckOutPullRequest.flunkOnFailure, True)
+        self.assertEqual(CheckOutPullRequest.haltOnFailure, True)
+        self.expectRemoteCommands(
+            ExpectShell(
+                workdir='wkdir',
+                timeout=600,
+                logEnviron=False,
+                command=['/bin/sh', '-c', 'git remote add Contributor https://github.com/Contributor/WebKit.git & true'],
+            ) + 0, ExpectShell(
+                workdir='wkdir',
+                timeout=600,
+                logEnviron=False,
+                command=['git', 'remote', 'set-url', 'Contributor', 'https://github.com/Contributor/WebKit.git'],
+            ) + 0, ExpectShell(
+                workdir='wkdir',
+                timeout=600,
+                logEnviron=False,
+                command=['git', 'fetch', 'Contributor'],
+            ) + 1,
+        )
+        self.expectOutcome(result=FAILURE, state_string='Failed to checkout branch from PR 1234')
+        return self.runStep()
+
+    def test_skipped(self):
+        self.setupStep(CheckOutPullRequest())
+        self.expectHidden(True)
+        self.expectOutcome(result=SKIPPED, state_string='No pull request to checkout')
+        return self.runStep()
+
+
 class TestUnApplyPatchIfRequired(BuildStepMixinAdditions, unittest.TestCase):
     def setUp(self):
         self.longMessage = True

Modified: trunk/Tools/ChangeLog (288313 => 288314)


--- trunk/Tools/ChangeLog	2022-01-20 20:02:38 UTC (rev 288313)
+++ trunk/Tools/ChangeLog	2022-01-20 20:34:39 UTC (rev 288314)
@@ -1,3 +1,30 @@
+2022-01-20  Jonathan Bedard  <[email protected]>
+
+        [EWS] Add CheckOutPullRequest step
+        https://bugs.webkit.org/show_bug.cgi?id=235157
+        <rdar://problem/87487209 >
+
+        Reviewed by Aakash Jain.
+
+        * CISupport/ews-build/factories.py:
+        (Factory.__init__): Add CheckOutPullRequest step.
+        (StyleFactory.__init__): Ditto.
+        (WatchListFactory.__init__): Ditto.
+        * CISupport/ews-build/factories_unittest.py:
+        (TestExpectedBuildSteps): Add CheckOutPullRequest step.
+        * CISupport/ews-build/steps.py:
+        (ApplyPatch.doStepIf): Only run step if a patch is provided.
+        (ApplyPatch.hideStepIf): Only display step if a patch was provided.
+        (ApplyPatch.getResultSummary): Add SKIPPED description.
+        (CheckOutPullRequest):
+        (CheckOutPullRequest.__init__):
+        (CheckOutPullRequest.doStepIf): Only run step if a pull request is provided.
+        (CheckOutPullRequest.hideStepIf): Only display step if a pul request was provided.
+        (CheckOutPullRequest.run): Configure new remote, fetch remote and checkout pull request
+        branch from the newly configured remote.
+        (CheckOutPullRequest.getResultSummary):
+        * CISupport/ews-build/steps_unittest.py:
+
 2022-01-19  Jonathan Bedard  <[email protected]>
 
         [webkitbugspy] Support automated comments
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to