Skip to content

Commit b857d8c

Browse files
committed
add github action
1 parent 9528baf commit b857d8c

File tree

2 files changed

+195
-0
lines changed

2 files changed

+195
-0
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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)

.github/workflows/release.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Release Charts
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
release:
10+
permissions:
11+
contents: write # to push chart release and create a release (helm/chart-releaser-action)
12+
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout Code
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Configure Git
21+
run: |
22+
git config user.name "$GITHUB_ACTOR"
23+
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
24+
- name: Set up Helm
25+
uses: azure/setup-helm@v3.5
26+
with:
27+
version: v3.9.2
28+
29+
- name: Run chart-releaser
30+
uses: helm/chart-releaser-action@v1.6.0
31+
env:
32+
CR_TOKEN: "${{ github.token }}"
33+
34+
generate-page:
35+
runs-on: ubuntu-latest
36+
permissions:
37+
contents: write # Needed to commit the generated file
38+
needs:
39+
- release
40+
steps:
41+
- uses: actions/checkout@v4
42+
with:
43+
ref: gh-pages
44+
fetch-depth: 0
45+
46+
- name: debug-print
47+
run: |
48+
echo "Current directory is $(pwd)"
49+
echo "Contents of the directory are $(ls -la)"
50+
echo "Contents of the directory are $(ls -la /home/runner/work/helm-release/helm-release/)"
51+
52+
- name: Generate Helm Charts HTML
53+
uses: ./.github/actions/generate-helm-html-index
54+
with:
55+
index-file: 'index.yaml'
56+
output-file: 'index.html'
57+
58+
- name: Commit and Push
59+
run: |
60+
git config --local user.email "action@github.com"
61+
git config --local user.name "GitHub Action"
62+
git add index.html
63+
git commit -m "Update Helm charts page" || exit 0 # Don't fail if no changes
64+
git push

0 commit comments

Comments
 (0)