verify-devtools-bundle.py (2354B)
1 #!/usr/bin/env python3 2 # This Source Code Form is subject to the terms of the Mozilla Public 3 # License, v. 2.0. If a copy of the MPL was not distributed with this 4 # file, # You can obtain one at http://mozilla.org/MPL/2.0/. 5 6 """ 7 Check that the current sourcemap and worker bundles built for DevTools are up to date. 8 This job should fail if any file impacting the bundle creation was modified without 9 regenerating the bundles. 10 11 This check should be run after building the bundles via: 12 cd devtools/client/debugger 13 yarn && node bin/bundle.js 14 15 Those steps are done in the devtools-verify-bundle job, prior to calling this script. 16 The script will only run `hg status devtools/` and check that no change is detected by 17 mercurial. 18 """ 19 20 import argparse 21 import json 22 import subprocess 23 import sys 24 25 # Ignore module-manifest.json updates which can randomly happen when 26 # building bundles. 27 hg_exclude = "devtools/client/debugger/bin/module-manifest.json" 28 29 print("Run `hg status devtools/`") 30 status = ( 31 subprocess.check_output(["hg", "status", "-n", "devtools/", "-X", hg_exclude]) 32 .decode("utf-8") 33 .split("\n") 34 ) 35 print(" status:") 36 print("-" * 80) 37 38 doc = "https://firefox-source-docs.mozilla.org/devtools/tests/node-tests.html#devtools-bundle" 39 40 failures = {} 41 for l in status: 42 if not l: 43 # Ignore empty lines 44 continue 45 46 failures[l] = [ 47 { 48 "path": l, 49 "line": None, 50 "column": None, 51 "level": "error", 52 "message": l 53 + " is outdated and needs to be regenerated, " 54 + f"instructions at: {doc}", 55 } 56 ] 57 58 59 diff = subprocess.check_output(["hg", "diff", "devtools/", "-X", hg_exclude]).decode( 60 "utf-8" 61 ) 62 63 # Revert all the changes created by `node bin/bundle.js` 64 subprocess.check_output(["hg", "revert", "-C", "devtools/"]) 65 66 parser = argparse.ArgumentParser() 67 parser.add_argument("--output", required=True) 68 args = parser.parse_args() 69 70 with open(args.output, "w") as fp: 71 json.dump(failures, fp, indent=2) 72 73 if len(failures) > 0: 74 print( 75 "TEST-UNEXPECTED-FAIL | devtools-bundle | DevTools bundles need to be regenerated, " 76 + f"instructions at: {doc}" 77 ) 78 79 print("The following devtools bundles were detected as outdated:") 80 for failure in failures: 81 print(failure) 82 83 print(f"diff:{diff}") 84 85 sys.exit(1)