Changeset 287045 in webkit
- Timestamp:
- Dec 14, 2021, 1:31:59 PM (5 years ago)
- Location:
- trunk/Tools
- Files:
-
- 2 added
- 7 edited
-
ChangeLog (modified) (1 diff)
-
Scripts/libraries/reporelaypy/reporelaypy/__init__.py (modified) (2 diffs)
-
Scripts/libraries/reporelaypy/reporelaypy/checkout.py (modified) (2 diffs)
-
Scripts/libraries/reporelaypy/reporelaypy/database.py (modified) (1 diff)
-
Scripts/libraries/reporelaypy/reporelaypy/hooks.py (added)
-
Scripts/libraries/reporelaypy/reporelaypy/tests/hooks_unittest.py (added)
-
Scripts/libraries/reporelaypy/reporelaypy/webserver.py (modified) (4 diffs)
-
Scripts/libraries/reporelaypy/run (modified) (4 diffs)
-
Scripts/libraries/reporelaypy/setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r287040 r287045 1 2021-12-13 Jonathan Bedard <jbedard@apple.com> 2 3 [reporelaypy] Update checkout with hook instead of polling 4 https://bugs.webkit.org/show_bug.cgi?id=234243 5 <rdar://problem/86413065> 6 7 Reviewed by Dewei Zhu. 8 9 * Scripts/libraries/reporelaypy/reporelaypy/__init__.py: Bump version, 10 export HookProcessor and HookReceiver. 11 * Scripts/libraries/reporelaypy/reporelaypy/checkout.py: 12 (Checkout.update_for): If a branch is new, we need to track it. 13 * Scripts/libraries/reporelaypy/reporelaypy/database.py: 14 (Database.__init__): Use self.host and self.password. 15 * Scripts/libraries/reporelaypy/reporelaypy/hooks.py: Added. 16 (HookProcessor): Class to process received hooks. 17 (HookReceiver): Class to receive hooks and queue them for processing. 18 * Scripts/libraries/reporelaypy/reporelaypy/tests/hooks_unittest.py: Added. 19 (HooksUnittest): 20 (HooksUnittest.setUp): 21 (HooksUnittest.test_receive): 22 (HooksUnittest.test_invalid): 23 (HooksUnittest.test_process): 24 (HooksUnittest.test_hmac): 25 (HooksUnittest.test_invalid_hmac): 26 * Scripts/libraries/reporelaypy/reporelaypy/webserver.py: Add hook routes, 27 if hooks are enabled. 28 * Scripts/libraries/reporelaypy/run: Allow caller to enable hooks. 29 * Scripts/libraries/reporelaypy/setup.py: Bump version. 30 1 31 2021-12-14 Alex Christensen <achristensen@webkit.org> 2 32 -
trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/__init__.py
r286623 r287045 45 45 ) 46 46 47 version = Version(0, 2, 0)47 version = Version(0, 3, 0) 48 48 49 49 import webkitflaskpy … … 52 52 from reporelaypy.database import Database 53 53 from reporelaypy.checkoutroute import CheckoutRoute, Redirector 54 from reporelaypy.hooks import HookProcessor, HookReceiver 54 55 55 56 AutoInstall.register(Package('fakeredis', Version(1, 5, 2))) -
trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/checkout.py
r286623 r287045 165 165 return False 166 166 167 def update_for(self, branch=None, remote='origin' ):167 def update_for(self, branch=None, remote='origin', track=False): 168 168 if not self.repository: 169 169 sys.stderr.write("Cannot update '{}', clone still pending...\n".format(branch)) … … 171 171 172 172 branch = branch or self.repository.default_branch 173 if branch == self.repository.default_branch: 173 if not self.repository.prod_branches.match(branch): 174 return False 175 elif track and branch not in self.repository.branches_for(remote=remote): 176 run( 177 [self.repository.executable(), 'branch', '--track', branch, 'remotes/{}/{}'.format(remote, branch)], 178 cwd=self.repository.root_path, 179 ) 180 self.repository.cache.populate(branch=branch) 181 elif branch == self.repository.default_branch: 174 182 self.repository.pull(remote=remote) 175 183 self.repository.cache.populate(branch=branch) 176 184 return True 177 if not self.repository.prod_branches.match(branch): 178 return False 179 if self.is_updated(branch, remote=remote): 185 elif not track and self.is_updated(branch, remote=remote): 180 186 return True 181 187 -
trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/database.py
r286576 r287045 47 47 self.password = password or Environment.instance().get(self.PASSWORD_ENV) 48 48 49 if host:49 if self.host: 50 50 import redis 51 self._redis = redis. Redis(host=host, password=password)51 self._redis = redis.StrictRedis(host=self.host, password=self.password) 52 52 else: 53 53 import fakeredis -
trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/webserver.py
r286576 r287045 21 21 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 22 23 import json 23 24 import os 24 25 … … 29 30 30 31 from flask import Flask, current_app, json as fjson 31 from reporelaypy import Checkout, CheckoutRoute, Database, Redirector 32 from reporelaypy import Checkout, CheckoutRoute, Database, Redirector, HookReceiver 32 33 33 34 app = Flask(__name__) … … 40 41 ) 41 42 43 hook_args = json.loads(os.environ.get('HOOKS', '{}')) 44 if hook_args.get('enabled', False): 45 hook_routes = HookReceiver( 46 import_name=__name__, database=database, 47 debug=hook_args.get('debug', False), secret=os.environ.get(HookReceiver.SECRET_ENV), 48 ) 49 else: 50 hook_routes = None 51 42 52 43 53 @app.route('/__health') … … 47 57 48 58 app.register_blueprint(checkout_routes) 59 if hook_routes: 60 app.register_blueprint(hook_routes) 49 61 50 62 -
trunk/Tools/Scripts/libraries/reporelaypy/run
r286623 r287045 39 39 import webkitpy 40 40 41 from reporelaypy import Checkout, Database, Redirector41 from reporelaypy import Checkout, Database, HookProcessor, HookReceiver, Redirector 42 42 from webkitcorepy import arguments, AutoInstall 43 43 from whichcraft import which … … 102 102 ) 103 103 104 group = parser.add_argument_group('Hooks') 105 group.add_argument( 106 '--hooks', '--no-hooks', action=arguments.NoAction, dest='hooks', default=False, 107 help='Enable or disable hook end-points (disabled by default)', 108 ) 109 group.add_argument( 110 '--debug', '--no-debug', action=arguments.NoAction, dest='hooks_debug', default=True, 111 help='Enable endpoint to report hooks being processed (enabled by default)', 112 ) 113 104 114 args = parser.parse_args(args=args) 105 115 … … 141 151 print(' {}: {}'.format(redirector.name, redirector.url)) 142 152 143 env = dict(153 passenv = dict( 144 154 PYTHONPATH=':'.join(sys.path), 145 155 CHECKOUT=json.dumps(checkout, cls=Checkout.Encoder), 146 REDIRECTORS=json.dumps([Redirector(url) for url in args.redirector or []], cls=Redirector.Encoder) 156 REDIRECTORS=json.dumps([Redirector(url) for url in args.redirector or []], cls=Redirector.Encoder), 157 HOOKS=json.dumps({'enabled': args.hooks, 'debug': args.hooks_debug}), 147 158 ) 148 159 149 160 if AutoInstall.directory: 150 env['AUTOINSTALL_PATH'] = AutoInstall.directory161 passenv['AUTOINSTALL_PATH'] = AutoInstall.directory 151 162 if database.host: 152 env[database.HOST_ENV] = database.host163 passenv[database.HOST_ENV] = database.host 153 164 if database.password: 154 env[database.PASSWORD_ENV] = database.password165 passenv[database.PASSWORD_ENV] = database.password 155 166 if database.default_expiration: 156 env[database.EXPIRATION_ENV] = str(database.default_expiration) 167 passenv[database.EXPIRATION_ENV] = str(database.default_expiration) 168 if os.environ.get(HookReceiver.SECRET_ENV): 169 passenv[HookReceiver.SECRET_ENV] = os.environ.get(HookReceiver.SECRET_ENV) 170 171 processor = HookProcessor(checkout=checkout, database=database) if args.hooks else None 157 172 158 173 with subprocess.Popen( 159 174 [which('gunicorn'), 'reporelaypy.webserver:app'], 160 175 cwd=os.path.dirname(os.path.dirname(reporelaypy.__file__)), 161 env= env,176 env=passenv, 162 177 ) as webserver: 163 178 last_poll = time.time() … … 170 185 last_poll = time.time() 171 186 if last_pull + args.update_interval < time.time(): 172 checkout.update_all()187 processor.process_hooks() if processor else checkout.update_all() 173 188 last_pull = time.time() 174 189 time.sleep(math.gcd(args.poll, args.update_interval)) -
trunk/Tools/Scripts/libraries/reporelaypy/setup.py
r286623 r287045 31 31 setup( 32 32 name='reporelaypy', 33 version='0. 2.0',33 version='0.3.0', 34 34 description='Library for visualizing, processing and storing test results.', 35 35 long_description=readme(),
Note:
See TracChangeset
for help on using the changeset viewer.