mirror of
https://github.com/k8s-at-home/charts.git
synced 2025-01-23 23:49:12 +00:00
ci: Renovate annotations update
This commit is contained in:
parent
aaedd037d2
commit
c0e176fcb9
70
.github/scripts/renovate-releasenotes.py
vendored
70
.github/scripts/renovate-releasenotes.py
vendored
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import typer
|
import typer
|
||||||
|
|
||||||
@ -8,7 +9,9 @@ from loguru import logger
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
|
from ruamel.yaml.comments import CommentedMap
|
||||||
from ruamel.yaml.scalarstring import LiteralScalarString
|
from ruamel.yaml.scalarstring import LiteralScalarString
|
||||||
|
from typing import List
|
||||||
|
|
||||||
app = typer.Typer(add_completion=False)
|
app = typer.Typer(add_completion=False)
|
||||||
|
|
||||||
@ -33,24 +36,16 @@ def _setup_logging(debug):
|
|||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def main(
|
def main(
|
||||||
chart_folder: Path = typer.Argument(
|
chart_folders: List[Path] = typer.Argument(
|
||||||
..., help="Folder containing the chart to process"),
|
..., help="Folders containing the chart to process"),
|
||||||
check_branch: str = typer.Option(
|
check_branch: str = typer.Option(
|
||||||
None, help="The branch to compare against."),
|
None, help="The branch to compare against."),
|
||||||
|
chart_base_folder: Path = typer.Option(
|
||||||
|
"charts", help="The base folder where the charts reside."),
|
||||||
debug: bool = False,
|
debug: bool = False,
|
||||||
):
|
):
|
||||||
_setup_logging(debug)
|
_setup_logging(debug)
|
||||||
|
|
||||||
if not chart_folder.is_dir():
|
|
||||||
logger.error(f"Could not find folder {str(chart_folder)}")
|
|
||||||
raise typer.Exit()
|
|
||||||
|
|
||||||
chart_metadata_file = chart_folder.joinpath('Chart.yaml')
|
|
||||||
|
|
||||||
if not chart_metadata_file.is_file():
|
|
||||||
logger.error(f"Could not find file {str(chart_metadata_file)}")
|
|
||||||
raise typer.Exit()
|
|
||||||
|
|
||||||
git_repository = Repo(search_parent_directories=True)
|
git_repository = Repo(search_parent_directories=True)
|
||||||
|
|
||||||
if check_branch:
|
if check_branch:
|
||||||
@ -59,11 +54,6 @@ def main(
|
|||||||
(ref for ref in git_repository.remotes.origin.refs if ref.name == check_branch),
|
(ref for ref in git_repository.remotes.origin.refs if ref.name == check_branch),
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
|
|
||||||
if not branch:
|
|
||||||
logger.error(f"Could not find branch {check_branch}")
|
|
||||||
raise typer.Exit()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.info(f"Trying to determine default branch...")
|
logger.info(f"Trying to determine default branch...")
|
||||||
branch = next(
|
branch = next(
|
||||||
@ -71,14 +61,32 @@ def main(
|
|||||||
None
|
None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not branch:
|
||||||
|
logger.error(
|
||||||
|
f"Could not find branch {check_branch} to compare against.")
|
||||||
|
raise typer.Exit(1)
|
||||||
|
|
||||||
logger.info(f"Comparing against branch {branch}")
|
logger.info(f"Comparing against branch {branch}")
|
||||||
|
|
||||||
|
for chart_folder in chart_folders:
|
||||||
|
chart_folder = chart_base_folder.joinpath(chart_folder)
|
||||||
|
if not chart_folder.is_dir():
|
||||||
|
logger.error(f"Could not find folder {str(chart_folder)}")
|
||||||
|
raise typer.Exit(1)
|
||||||
|
|
||||||
|
chart_metadata_file = chart_folder.joinpath('Chart.yaml')
|
||||||
|
|
||||||
|
if not chart_metadata_file.is_file():
|
||||||
|
logger.error(f"Could not find file {str(chart_metadata_file)}")
|
||||||
|
raise typer.Exit(1)
|
||||||
|
|
||||||
logger.info(f"Updating changelog annotation for chart {chart_folder}")
|
logger.info(f"Updating changelog annotation for chart {chart_folder}")
|
||||||
|
|
||||||
yaml = YAML(typ=['rt', 'string'])
|
yaml = YAML(typ=['rt', 'string'])
|
||||||
yaml.indent(mapping=2, sequence=4, offset=2)
|
yaml.indent(mapping=2, sequence=4, offset=2)
|
||||||
yaml.explicit_start = True
|
yaml.explicit_start = True
|
||||||
yaml.preserve_quotes = True
|
yaml.preserve_quotes = True
|
||||||
|
yaml.width = 4096
|
||||||
|
|
||||||
old_chart_metadata = yaml.load(
|
old_chart_metadata = yaml.load(
|
||||||
git_repository.git.show(f"{branch}:{chart_metadata_file}")
|
git_repository.git.show(f"{branch}:{chart_metadata_file}")
|
||||||
@ -100,7 +108,8 @@ def main(
|
|||||||
old_dep = None
|
old_dep = None
|
||||||
if "alias" in dependency.keys():
|
if "alias" in dependency.keys():
|
||||||
old_dep = next(
|
old_dep = next(
|
||||||
(old_dep for old_dep in old_chart_dependencies if "alias" in old_dep.keys() and old_dep["alias"] == dependency["alias"]),
|
(old_dep for old_dep in old_chart_dependencies if "alias" in old_dep.keys(
|
||||||
|
) and old_dep["alias"] == dependency["alias"]),
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@ -109,23 +118,36 @@ def main(
|
|||||||
None
|
None
|
||||||
)
|
)
|
||||||
|
|
||||||
if old_dep and dependency["version"] != old_dep["version"]:
|
add_annotation = False
|
||||||
|
if old_dep:
|
||||||
|
if dependency["version"] != old_dep["version"]:
|
||||||
|
add_annotation = True
|
||||||
|
else:
|
||||||
|
add_annotation = True
|
||||||
|
|
||||||
|
if add_annotation:
|
||||||
if "alias" in dependency.keys():
|
if "alias" in dependency.keys():
|
||||||
annotations.append({
|
annotations.append({
|
||||||
"kind": "changed",
|
"kind": "changed",
|
||||||
"description": f"Upgraded {dependency['name']} chart dependency to version {dependency['version']} for alias '{dependency['alias']}'"
|
"description": f"Upgraded `{dependency['name']}` chart dependency to version {dependency['version']} for alias '{dependency['alias']}'"
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
annotations.append({
|
annotations.append({
|
||||||
"kind": "changed",
|
"kind": "changed",
|
||||||
"description": f"Upgraded {dependency['name']} chart dependency to version {dependency['version']}"
|
"description": f"Upgraded `{dependency['name']}` chart dependency to version {dependency['version']}"
|
||||||
})
|
})
|
||||||
|
|
||||||
annotations = YAML(typ=['rt', 'string']).dump_to_string(annotations)
|
|
||||||
|
|
||||||
if annotations:
|
if annotations:
|
||||||
new_chart_metadata["annotations"]["artifacthub.io/changes"] = LiteralScalarString(annotations)
|
annotations = YAML(typ=['rt', 'string']
|
||||||
|
).dump_to_string(annotations)
|
||||||
|
|
||||||
|
if not "annotations" in new_chart_metadata:
|
||||||
|
new_chart_metadata["annotations"] = CommentedMap()
|
||||||
|
|
||||||
|
new_chart_metadata["annotations"]["artifacthub.io/changes"] = LiteralScalarString(
|
||||||
|
annotations)
|
||||||
yaml.dump(new_chart_metadata, chart_metadata_file)
|
yaml.dump(new_chart_metadata, chart_metadata_file)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app()
|
app()
|
||||||
|
8
.github/workflows/charts-changelog.yaml
vendored
8
.github/workflows/charts-changelog.yaml
vendored
@ -57,13 +57,7 @@ jobs:
|
|||||||
CHECK_BRANCH: "origin/${{ github.event.repository.default_branch }}"
|
CHECK_BRANCH: "origin/${{ github.event.repository.default_branch }}"
|
||||||
run: |
|
run: |
|
||||||
pip install -r ./.github/scripts/requirements.txt
|
pip install -r ./.github/scripts/requirements.txt
|
||||||
CHARTS=(${{ inputs.modifiedCharts }})
|
./.github/scripts/renovate-releasenotes.py --check-branch "$CHECK_BRANCH" ${{ inputs.modifiedCharts }}
|
||||||
for i in "${CHARTS[@]}"
|
|
||||||
do
|
|
||||||
IFS='/' read -r -a chart_parts <<< "$i"
|
|
||||||
./.github/scripts/renovate-releasenotes.py --check-branch "$CHECK_BRANCH" "charts/${chart_parts[0]}/${chart_parts[1]}"
|
|
||||||
echo ""
|
|
||||||
done
|
|
||||||
|
|
||||||
- name: Create commit
|
- name: Create commit
|
||||||
id: create-commit
|
id: create-commit
|
||||||
|
Loading…
Reference in New Issue
Block a user