1
+ # .github/actions/helm-chart-generator/action.yml
2
+ name : ' Helm Chart HTML Generator'
3
+ description : ' Generates a static HTML page from Helm chart index.yaml file'
4
+
5
+ inputs :
6
+ index_file :
7
+ description : ' Path to the index.yaml file'
8
+ required : false
9
+ default : ' index.yaml'
10
+ output_file :
11
+ description : ' Output HTML file path'
12
+ required : false
13
+ default : ' index.html'
14
+
15
+ runs :
16
+ using : " composite"
17
+ steps :
18
+ - name : Setup Python
19
+ uses : actions/setup-python@v4
20
+ with :
21
+ python-version : ' 3.x'
22
+
23
+ - name : Install Dependencies
24
+ shell : bash
25
+ run : |
26
+ python -m pip install --upgrade pip
27
+ pip install pyyaml
28
+
29
+ - name : Run Generator Script
30
+ shell : python
31
+ env :
32
+ INDEX_FILE : ${{ inputs.index_file }}
33
+ OUTPUT_FILE : ${{ inputs.output_file }}
34
+ run : |
35
+ import os
36
+ import sys
37
+ import yaml
38
+ from datetime import datetime
39
+
40
+ # Debug information
41
+ print("Environment variables:")
42
+ for key, value in os.environ.items():
43
+ if key.startswith(('INDEX_', 'OUTPUT_')):
44
+ print(f"{key}: {value}")
45
+
46
+ # Get input parameters directly from environment
47
+ index_file = os.environ['INDEX_FILE']
48
+ output_file = os.environ['OUTPUT_FILE']
49
+
50
+ print(f"Looking for index file: {index_file}")
51
+ print(f"Will write to output file: {output_file}")
52
+
53
+ # Verify input file exists
54
+ if not os.path.exists(index_file):
55
+ print(f"Error: Index file '{index_file}' not found!")
56
+ print(f"Absolute path attempted: {os.path.abspath(index_file)}")
57
+ sys.exit(1)
58
+
59
+ # Read YAML file
60
+ try:
61
+ with open(index_file, 'r') as f:
62
+ data = yaml.safe_load(f)
63
+ except Exception as e:
64
+ print(f"Error reading YAML file: {e}")
65
+ sys.exit(1)
66
+
67
+ # Generate HTML
68
+ html = f"""
69
+ <!DOCTYPE html>
70
+ <html>
71
+ <head>
72
+ <meta charset="UTF-8">
73
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
74
+ <title>Helm Charts Repository</title>
75
+ <style>
76
+ body {{ font-family: Arial, sans-serif; margin: 40px auto; max-width: 1200px; padding: 0 20px; }}
77
+ .chart {{ border: 1px solid #ddd; margin: 20px 0; padding: 20px; border-radius: 8px; }}
78
+ .chart-header {{ display: flex; align-items: center; justify-content: space-between; }}
79
+ .chart-icon {{ max-width: 100px; }}
80
+ .version {{ background: #f5f5f5; padding: 15px; margin: 10px 0; border-radius: 5px; }}
81
+ .download-btn {{
82
+ display: inline-block;
83
+ padding: 10px 20px;
84
+ background: #0066cc;
85
+ color: white;
86
+ text-decoration: none;
87
+ border-radius: 5px;
88
+ margin-top: 10px;
89
+ }}
90
+ .download-btn:hover {{ background: #0052a3; }}
91
+ </style>
92
+ </head>
93
+ <body>
94
+ <h1>Helm Charts Repository</h1>
95
+ """
96
+
97
+ # Add chart entries
98
+ for chart_name, versions in data.get('entries', {}).items():
99
+ for version in versions:
100
+ html += f"""
101
+ <div class="chart">
102
+ <div class="chart-header">
103
+ <h2>{chart_name}</h2>
104
+ {f'<img src="{version["icon"]}" class="chart-icon" alt="Chart icon">' if 'icon' in version else ''}
105
+ </div>
106
+ <p>{version.get('description', '')}</p>
107
+ <div class="version">
108
+ <h3>Version {version['version']}</h3>
109
+ <p>App Version: {version.get('appVersion', 'N/A')}</p>
110
+ <p>Created: {version.get('created', 'N/A')}</p>
111
+ <a href="{version['urls'][0]}" class="download-btn">Download Chart</a>
112
+ </div>
113
+ </div>
114
+ """
115
+
116
+ html += f"""
117
+ <footer>
118
+ <p>Generated on {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}</p>
119
+ </footer>
120
+ </body>
121
+ </html>
122
+ """
123
+
124
+ # Write HTML file
125
+ try:
126
+ with open(output_file, 'w') as f:
127
+ f.write(html)
128
+ print(f"Successfully generated {output_file}")
129
+ except Exception as e:
130
+ print(f"Error writing HTML file: {e}")
131
+ sys.exit(1)
0 commit comments