105 lines
3.7 KiB
Python
105 lines
3.7 KiB
Python
import yaml
|
|
import re
|
|
|
|
# Load the YAML content from the file
|
|
with open('appveyor.yml', 'r') as file:
|
|
appveyor_yml = file.read()
|
|
|
|
# Parsing the YAML content
|
|
config = yaml.safe_load(appveyor_yml)
|
|
|
|
# Extract branches and configurations from the YAML
|
|
branches = {}
|
|
deployments = {}
|
|
inactive_branches = []
|
|
inactive_configs = {}
|
|
|
|
# Extract specific branch configurations
|
|
if 'for' in config:
|
|
for branch_config in config['for']:
|
|
branch_names = branch_config.get('branches', {}).get('only', [])
|
|
configurations = branch_config.get('configuration', [])
|
|
for branch in branch_names:
|
|
if branch not in branches:
|
|
branches[branch] = []
|
|
branches[branch].extend(configurations)
|
|
|
|
# Manually add common branches and configurations if not already included
|
|
if 'branches' in config:
|
|
common_branches = config['branches'].get('only', [])
|
|
for branch in common_branches:
|
|
if branch not in branches:
|
|
branches[branch] = config.get('configuration', [])
|
|
|
|
# Check for inactive branches and configurations in the comments
|
|
lines = appveyor_yml.splitlines()
|
|
for i, line in enumerate(lines):
|
|
# Check for commented branches
|
|
if re.match(r'#\s*-\s*(\w+)', line):
|
|
branch_name = re.findall(r'#\s*-\s*(\w+)', line)[0]
|
|
if 'branches' in lines[i - 1] and 'only:' in lines[i - 2]:
|
|
inactive_branches.append(branch_name.replace('-', '_'))
|
|
|
|
# Check for commented configurations
|
|
if re.match(r'#\s*-\s*(\w+)', line):
|
|
inactive_configs.setdefault(lines[i - 1].strip().split()[1], []).append(re.findall(r'#\s*-\s*(\w+)', line)[0].replace('-', '_'))
|
|
|
|
# Extract deployment configurations
|
|
if 'deploy' in config:
|
|
deployments['common'] = config['deploy']
|
|
|
|
if 'for' in config:
|
|
for branch_config in config['for']:
|
|
branch_names = branch_config.get('branches', {}).get('only', [])
|
|
if 'deploy' in branch_config:
|
|
for branch in branch_names:
|
|
if branch not in deployments:
|
|
deployments[branch] = []
|
|
deployments[branch].extend(branch_config['deploy'])
|
|
|
|
# Generate the Mermaid graph content
|
|
mermaid_graph = """
|
|
graph TD
|
|
A[Common Configuration]
|
|
"""
|
|
|
|
# Add branches to the graph
|
|
for branch in branches.keys():
|
|
branch_id = branch.replace('-', '_')
|
|
mermaid_graph += f" A --> {branch_id}\n"
|
|
|
|
# Add configurations to the branches
|
|
for branch, configs in branches.items():
|
|
branch_id = branch.replace('-', '_')
|
|
for idx, config in enumerate(configs):
|
|
config_id = f"{branch_id}{idx + 1}"
|
|
mermaid_graph += f" {branch_id} --> {config_id}[{config}]\n"
|
|
|
|
# Add deployments to the configurations
|
|
for branch, deploys in deployments.items():
|
|
branch_id = branch.replace('-', '_')
|
|
for deploy in deploys:
|
|
configuration = deploy.get('configuration')
|
|
if configuration:
|
|
config_id = f"{branch_id}{branches[branch].index(configuration) + 1}"
|
|
service_id = deploy.get('website', '').replace('-', '_')
|
|
mermaid_graph += f" {config_id} --> {service_id}[{deploy.get('provider', '')} on {branch}]\n"
|
|
|
|
# Highlight inactive branches and configurations with a dotted style
|
|
for branch in inactive_branches:
|
|
mermaid_graph += f" style {branch} fill:#f96,stroke:#333,stroke-width:2px,stroke-dasharray: 5, 5\n"
|
|
|
|
for branch, configs in inactive_configs.items():
|
|
branch_id = branch.replace('-', '_')
|
|
for config in configs:
|
|
config_id = f"{branch_id}_{config}"
|
|
mermaid_graph += f" style {config_id} fill:#bbf,stroke:#333,stroke-width:2px,stroke-dasharray: 5,5\n"
|
|
|
|
# Add styles to the graph
|
|
mermaid_graph += """
|
|
style A fill:#f9f,stroke:#333,stroke-width:2px
|
|
"""
|
|
|
|
# Output the graph
|
|
print(mermaid_graph)
|