script improved
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
import yaml
|
import yaml
|
||||||
|
import re
|
||||||
|
|
||||||
# Load the YAML content from the file
|
# Load the YAML content from the file
|
||||||
with open('appveyor.yml', 'r') as file:
|
with open('appveyor.yml', 'r') as file:
|
||||||
@ -11,6 +12,7 @@ config = yaml.safe_load(appveyor_yml)
|
|||||||
branches = {}
|
branches = {}
|
||||||
deployments = {}
|
deployments = {}
|
||||||
inactive_branches = []
|
inactive_branches = []
|
||||||
|
inactive_configs = {}
|
||||||
|
|
||||||
# Extract specific branch configurations
|
# Extract specific branch configurations
|
||||||
if 'for' in config:
|
if 'for' in config:
|
||||||
@ -29,11 +31,13 @@ if 'branches' in config:
|
|||||||
if branch not in branches:
|
if branch not in branches:
|
||||||
branches[branch] = config.get('configuration', [])
|
branches[branch] = config.get('configuration', [])
|
||||||
|
|
||||||
# Check for inactive branches in the comments
|
# Check for inactive branches and configurations in the comments
|
||||||
lines = appveyor_yml.splitlines()
|
lines = appveyor_yml.splitlines()
|
||||||
for i, line in enumerate(lines):
|
for i, line in enumerate(lines):
|
||||||
|
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('-', '_'))
|
||||||
if line.strip().startswith('#') and i + 2 < len(lines) and 'branches:' in lines[i + 1] and 'only:' in lines[i + 2]:
|
if line.strip().startswith('#') and i + 2 < len(lines) and 'branches:' in lines[i + 1] and 'only:' in lines[i + 2]:
|
||||||
inactive_branches.append(lines[i + 2].split(':')[1].strip())
|
inactive_branches.append(lines[i + 2].split(':')[1].strip().replace('-', '_'))
|
||||||
|
|
||||||
# Extract deployment configurations
|
# Extract deployment configurations
|
||||||
if 'deploy' in config:
|
if 'deploy' in config:
|
||||||
@ -51,35 +55,41 @@ if 'for' in config:
|
|||||||
# Generate the Mermaid graph content
|
# Generate the Mermaid graph content
|
||||||
mermaid_graph = """
|
mermaid_graph = """
|
||||||
graph TD
|
graph TD
|
||||||
A[Common Configuration] --> B[master]
|
A[Common Configuration]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Add branches to the graph
|
# Add branches to the graph
|
||||||
for branch in branches.keys():
|
for branch in branches.keys():
|
||||||
if branch != 'master':
|
branch_id = branch.replace('-', '_')
|
||||||
mermaid_graph += f" A --> {branch.replace('-', '_')}\n"
|
mermaid_graph += f" A --> {branch_id}\n"
|
||||||
|
|
||||||
# Add configurations to the branches
|
# Add configurations to the branches
|
||||||
for branch, configs in branches.items():
|
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 deploy in deployments.get(branch, []):
|
||||||
|
configuration = deploy.get('configuration')
|
||||||
|
if configuration == config:
|
||||||
|
service = deploy.get('service', '')
|
||||||
|
mermaid_graph += f" {config_id} --> {service_id}[{deploy.get('on', {}).get('configuration', '')} 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:
|
for config in configs:
|
||||||
mermaid_graph += f" {branch.replace('-', '_')} --> {branch.replace('-', '_')}{config}\n"
|
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 deployments to the configurations
|
|
||||||
for branch, deploys in deployments.items():
|
|
||||||
for deploy in deploys:
|
|
||||||
configuration = deploy.get('configuration')
|
|
||||||
website = deploy.get('website')
|
|
||||||
if configuration and website:
|
|
||||||
mermaid_graph += f" {branch.replace('-', '_')}{configuration.replace('_', '')} --> {branch.replace('-', '_')}{website.replace('-', '_')}\n"
|
|
||||||
|
|
||||||
# Highlight inactive branches
|
|
||||||
for inactive_branch in inactive_branches:
|
|
||||||
mermaid_graph += f" style {inactive_branch.replace('-', '_')} fill:#f96,stroke:#333,stroke-width:2px,stroke-dasharray: 5, 5\n"
|
|
||||||
|
|
||||||
# Add styles to the graph
|
# Add styles to the graph
|
||||||
mermaid_graph += """
|
mermaid_graph += """
|
||||||
style A fill:#f9f,stroke:#333,stroke-width:2px
|
style A fill:#f9f,stroke:#333,stroke-width:2px
|
||||||
style B fill:#bbf,stroke:#333,stroke-width:2px
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Output the graph
|
||||||
print(mermaid_graph)
|
print(mermaid_graph)
|
||||||
|
Reference in New Issue
Block a user