def update(package_json): os.chdir(os.path.dirname(package_json)) print(package_json.split('/')[-2]) updating = [] out = subprocess.check_output(['git', 'diff', '--name-only']).decode() if 'package.json' in out: print('WARNING: package.json has local changes') return with open(package_json, 'r') as f: j = json.load(f, object_pairs_hook=OrderedDict) for package, version in j['devDependencies'].items(): if lib.get_npm_version(package) != version: i = (package, version, lib.get_npm_version(package)) print('Updating %s: %s --> %s' % i) updating.append(i) j['devDependencies'][package] = lib.get_npm_version(package) if not updating: print('Nothing to update') return with open(package_json, 'w') as f: out = json.dumps(j, indent=' ') f.write(out + '\n') subprocess.call(['npm', 'install']) try: subprocess.check_call(['npm', 'test']) except subprocess.CalledProcessError: print('Error updating %s' % package_json) return msg = 'build: Updating development dependencies\n\n' for tup in updating: msg += '* %s: %s → %s\n' % tup print(msg) lib.commit_and_push(files=['package.json'], msg=msg, branch='master', topic='bump-dev-deps')
def update(composer_json): os.chdir(os.path.dirname(composer_json)) print(composer_json.split('/')[-2]) updating = [] out = subprocess.check_output(['git', 'diff', '--name-only']).decode() if 'composer.json' in out: print('WARNING: composer.json has local changes') return with open(composer_json, 'r') as f: j = json.load(f, object_pairs_hook=OrderedDict) if 'require-dev' not in j: print('No dev deps') return if not j.get('scripts', {}).get('test'): print('No scripts.test command') return for package, version in j['require-dev'].items(): if package not in PACKAGES: print('Skipping ' + package) continue if lib.get_packagist_version(package) != version: i = (package, version, lib.get_packagist_version(package)) print('Updating %s: %s --> %s' % i) updating.append(i) j['require-dev'][package] = lib.get_packagist_version(package) if not updating: print('Nothing to update') return with open(composer_json, 'w') as f: out = json.dumps(j, indent='\t') f.write(out + '\n') subprocess.call(['composer', 'update']) try: subprocess.check_call(['composer', 'test']) except subprocess.CalledProcessError: print('Tests fail %s!' % composer_json) msg = 'build: Updating development dependencies\n\n' for tup in updating: msg += '* %s: %s → %s\n' % tup print(msg) lib.commit_and_push(files=['composer.json'], msg=msg, branch='master', topic='bump-dev-deps')
print('Error: npm test failed.') sys.exit(0) else: print('Yay, npm test passed!') # Add node_modules to gitignore... if os.path.exists('.gitignore'): add = True with open('.gitignore') as f: for line in f.read().splitlines(): if line.strip().startswith('node_modules'): add = False break if add: with open('.gitignore', 'a') as f: f.write('node_modules/\n') print('Added "node_modules/" to .gitignore') else: with open('.gitignore', 'w') as f: f.write('node_modules/\n') print('Created .gitignore with "node_modules/"') msg = 'build: Configure banana-checker and jsonlint' if len(sys.argv) > 1: msg += '\n\nChange-Id: %s' % sys.argv[1] lib.commit_and_push(files=['package.json', 'Gruntfile.js', '.gitignore'], msg=msg, branch='master', topic='banana') log1 = subprocess.check_output(['git', 'log', '--oneline', '-n', '1']) sha1 = log1.decode().split(' ', 1)[0] subprocess.call(['ssh', '-p', '29418', 'gerrit.wikimedia.org', 'gerrit', 'review', '-m', '"check experimental"', sha1]) sys.exit(0)