[3.2] Add pre-commit to update release manifest #220
@@ -17,7 +17,7 @@ jobs:
|
||||
object-format: 'sha256'
|
||||
- name: Setup dependencies
|
||||
run: |
|
||||
zypper in -y python3-PyYAML
|
||||
zypper in -y python3-ruamel.yaml
|
||||
- name: Check release manifest
|
||||
run: |
|
||||
python3 .obs/manifest-check.py
|
||||
python3 .obs/manifest-check.py --check
|
||||
|
51
.obs/manifest-check.py
Normal file → Executable file
51
.obs/manifest-check.py
Normal file → Executable file
@@ -1,11 +1,15 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import yaml
|
||||
import ruamel.yaml
|
||||
import pathlib
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
yaml = ruamel.yaml.YAML()
|
||||
|
||||
def get_chart_version(chart_name: str) -> str:
|
||||
with open(f"./{chart_name}/Chart.yaml") as f:
|
||||
chart = yaml.safe_load(f)
|
||||
chart = yaml.load(f)
|
||||
return chart["version"]
|
||||
|
||||
def get_charts(chart):
|
||||
@@ -21,22 +25,57 @@ def get_charts(chart):
|
||||
|
||||
def get_charts_list():
|
||||
with open("./release-manifest-image/release_manifest.yaml") as f:
|
||||
manifest = yaml.safe_load(f)
|
||||
manifest = yaml.load(f)
|
||||
charts = {}
|
||||
for chart in manifest["spec"]["components"]["workloads"]["helm"]:
|
||||
charts.update(get_charts(chart))
|
||||
return charts
|
||||
|
||||
def main():
|
||||
print("Checking charts versions in release manifest")
|
||||
def check_charts(fix: bool) -> bool:
|
||||
success = True
|
||||
charts = get_charts_list()
|
||||
to_fix = {}
|
||||
for chart in charts:
|
||||
expected_version = get_chart_version(chart)
|
||||
if expected_version != charts[chart]:
|
||||
success = False
|
||||
to_fix[f'%%CHART_REPO%%/%%IMG_PREFIX%%{chart}'] = expected_version
|
||||
print(f"{chart}: Expected: {expected_version}, Got: {charts[chart]}")
|
||||
if not success:
|
||||
if fix and not success:
|
||||
fix_charts(to_fix)
|
||||
return True
|
||||
return success
|
||||
|
||||
def fix_charts(to_fix):
|
||||
manifest_path = pathlib.Path("./release-manifest-image/release_manifest.yaml")
|
||||
manifest = yaml.load(manifest_path)
|
||||
yaml.indent(mapping=2, sequence=4, offset=2)
|
||||
yaml.width = 4096
|
||||
for chart_index, chart in enumerate(manifest["spec"]["components"]["workloads"]["helm"]):
|
||||
changed = False
|
||||
if chart["chart"] in to_fix.keys():
|
||||
changed = True
|
||||
chart["version"] = to_fix[chart["chart"]]
|
||||
for subchart_index, subchart in enumerate(chart.get("addonCharts", [])):
|
||||
if subchart["chart"] in to_fix.keys():
|
||||
changed = True
|
||||
subchart["version"] = to_fix[subchart["chart"]]
|
||||
chart["addonCharts"][subchart_index] = subchart
|
||||
for subchart_index, subchart in enumerate(chart.get("dependencyCharts", [])):
|
||||
if subchart["chart"] in to_fix.keys():
|
||||
changed = True
|
||||
subchart["version"] = to_fix[subchart["chart"]]
|
||||
chart["dependencyCharts"][subchart_index] = subchart
|
||||
if changed:
|
||||
manifest["spec"]["components"]["workloads"]["helm"][chart_index] = chart
|
||||
yaml.dump(manifest, manifest_path)
|
||||
|
||||
def main():
|
||||
print("Checking charts versions in release manifest")
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-c', '--check', action='store_true')
|
||||
args = parser.parse_args()
|
||||
if not check_charts(not args.check):
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("All local charts in release manifest are using the right version")
|
||||
|
10
.pre-commit-config.yaml
Normal file
10
.pre-commit-config.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
repos:
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: check-manifest
|
||||
name: "Check release-manifest"
|
||||
entry: .obs/manifest-check.py
|
||||
language: python
|
||||
additional_dependencies: ['ruamel.yaml']
|
||||
pass_filenames: false
|
||||
always_run: true
|
@@ -76,13 +76,13 @@ spec:
|
||||
version: 0.0.0
|
||||
type: HelmChart
|
||||
operatingSystem:
|
||||
version: "6.0"
|
||||
zypperID: "SL-Micro"
|
||||
cpeScheme: "cpe:/o:suse:sl-micro:6.0"
|
||||
prettyName: "SUSE Linux Micro 6.0"
|
||||
version: '6.0'
|
||||
zypperID: SL-Micro
|
||||
cpeScheme: cpe:/o:suse:sl-micro:6.0
|
||||
prettyName: SUSE Linux Micro 6.0
|
||||
supportedArchs:
|
||||
- "x86_64"
|
||||
- "aarch64"
|
||||
- x86_64
|
||||
- aarch64
|
||||
workloads:
|
||||
helm:
|
||||
- prettyName: Rancher
|
||||
|
Reference in New Issue
Block a user