Add script to batch update travis and appveyor yml files (#834) [ci skip]
This commit is contained in:
parent
ee839e712d
commit
c4888b97a2
|
|
@ -23,3 +23,4 @@ node_modules
|
|||
.deps
|
||||
global.json
|
||||
msbuild.ProjectImports.zip
|
||||
.env
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/dev/tools/korebuild.schema.json",
|
||||
"$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/release/2.1/tools/korebuild.schema.json",
|
||||
"channel": "release/2.1"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
PyYAML==3.12
|
||||
termcolor==1.1.0
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import collections
|
||||
import glob
|
||||
import yaml
|
||||
from os import path
|
||||
from termcolor import colored, cprint
|
||||
from yaml.constructor import Constructor
|
||||
|
||||
def dump_format(dump, tag, mapping, flow_style=None):
|
||||
"""
|
||||
Better output formatting for YAML dictionaries
|
||||
"""
|
||||
value = []
|
||||
node = yaml.MappingNode(tag, value, flow_style=flow_style)
|
||||
if dump.alias_key is not None:
|
||||
dump.represented_objects[dump.alias_key] = node
|
||||
best_style = True
|
||||
if hasattr(mapping, 'items'):
|
||||
mapping = mapping.items()
|
||||
for item_key, item_value in mapping:
|
||||
node_key = dump.represent_data(item_key)
|
||||
node_value = dump.represent_data(item_value)
|
||||
if not (isinstance(node_key, yaml.ScalarNode) and not node_key.style):
|
||||
best_style = False
|
||||
if not (isinstance(node_value, yaml.ScalarNode) and not node_value.style):
|
||||
best_style = False
|
||||
value.append((node_key, node_value))
|
||||
if flow_style is None:
|
||||
if dump.default_flow_style is not None:
|
||||
node.flow_style = dump.default_flow_style
|
||||
else:
|
||||
node.flow_style = best_style
|
||||
return node
|
||||
|
||||
|
||||
def add_bool_as_scalar(self, node):
|
||||
"""
|
||||
Don't auto-parse boolean values
|
||||
"""
|
||||
if node.value == 'true' or node.value == 'false' :
|
||||
return self.construct_yaml_bool(node)
|
||||
return self.construct_scalar(node)
|
||||
|
||||
_mapping_tag = yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG
|
||||
|
||||
def dict_representer(dumper, data):
|
||||
return dumper.represent_mapping(_mapping_tag, data.iteritems())
|
||||
|
||||
|
||||
def dict_constructor(loader, node):
|
||||
return collections.OrderedDict(loader.construct_pairs(node))
|
||||
|
||||
def update(pattern, updater):
|
||||
print('\n\n\n')
|
||||
cprint(pattern, 'magenta')
|
||||
|
||||
for f in glob.glob(path.join(repo_root, "modules", "*", pattern)):
|
||||
yml = path.join(repo_root, f)
|
||||
|
||||
if not path.exists(yml):
|
||||
cprint("File does not exist: {}".format(yml), 'red')
|
||||
continue
|
||||
|
||||
print("Updating {}".format(yml))
|
||||
document = yaml.load(open(yml, 'r'))
|
||||
document = updater(document)
|
||||
yml_file = open(yml, 'w')
|
||||
yml_file.write(yaml.safe_dump(document, default_flow_style=False, indent=2))
|
||||
yml_file.close()
|
||||
|
||||
#
|
||||
# Config yaml parser
|
||||
#
|
||||
|
||||
# Do not reorder keys in yaml file
|
||||
yaml.add_representer(collections.OrderedDict, dict_representer)
|
||||
yaml.add_constructor(_mapping_tag, dict_constructor)
|
||||
# Pretty print dictionaries
|
||||
yaml.SafeDumper.add_representer(collections.OrderedDict,
|
||||
lambda dumper, value: dump_format(dumper, u'tag:yaml.org,2002:map', value))
|
||||
# Don't parse booleans - treat them as scalars
|
||||
yaml.Loader.add_constructor(u'tag:yaml.org,2002:bool', add_bool_as_scalar)
|
||||
yaml.SafeLoader.add_constructor(u'tag:yaml.org,2002:bool', add_bool_as_scalar)
|
||||
|
||||
#
|
||||
# Main
|
||||
#
|
||||
|
||||
repo_root = path.dirname(path.dirname(path.abspath(__file__)))
|
||||
|
||||
def transform_yaml_doc(document):
|
||||
if not 'branches' in document:
|
||||
document['branches'] = {}
|
||||
document['branches']['only'] = [
|
||||
'dev', '/^release\/.*$/', '/^(.*\/)?ci-.*$/']
|
||||
return document
|
||||
|
||||
update(".travis.yml", transform_yaml_doc)
|
||||
update(".appveyor.yml", transform_yaml_doc)
|
||||
Loading…
Reference in New Issue