Skip to content

Use chart-release to manage index updates #1082

@mgoerens

Description

@mgoerens

Currently we update the index.yaml with a series of git commands:

def update_index_and_push(
indexfile,
indexdir,
repository,
branch,
category,
organization,
chart,
version,
chart_url,
chart_entry,
pr_number,
web_catalog_only,
):
token = os.environ.get("GITHUB_TOKEN")
print(f"Downloading {indexfile}")
r = requests.get(
f"https://raw.githubusercontent.com/{repository}/{branch}/{indexfile}"
)
original_etag = r.headers.get("etag")
now = datetime.now(timezone.utc).astimezone().isoformat()
if r.status_code == 200:
data = yaml.load(r.text, Loader=Loader)
data["generated"] = now
else:
data = {"apiVersion": "v1", "generated": now, "entries": {}}
print("[INFO] Updating the chart entry with new version")
crtentries = []
entry_name = os.environ.get("CHART_ENTRY_NAME")
if not entry_name:
print("[ERROR] Internal error: missing chart entry name")
sys.exit(1)
d = data["entries"].get(entry_name, [])
for v in d:
if v["version"] == version:
continue
crtentries.append(v)
chart_entry["urls"] = [chart_url]
if not web_catalog_only:
set_package_digest(chart_entry)
chart_entry["annotations"]["charts.openshift.io/submissionTimestamp"] = now
crtentries.append(chart_entry)
data["entries"][entry_name] = crtentries
print("[INFO] Add and commit changes to git")
out = yaml.dump(data, Dumper=Dumper)
print(f"{indexfile} content:\n", out)
with open(os.path.join(indexdir, indexfile), "w") as fd:
fd.write(out)
old_cwd = os.getcwd()
os.chdir(indexdir)
out = subprocess.run(["git", "status"], cwd=indexdir, capture_output=True)
print("Git status:")
print(out.stdout.decode("utf-8"))
print(out.stderr.decode("utf-8"))
out = subprocess.run(
["git", "add", os.path.join(indexdir, indexfile)],
cwd=indexdir,
capture_output=True,
)
print(out.stdout.decode("utf-8"))
err = out.stderr.decode("utf-8")
if err.strip():
print(
f"Error adding {indexfile} to git staging area",
"index directory",
indexdir,
"branch",
branch,
)
out = subprocess.run(["git", "status"], cwd=indexdir, capture_output=True)
print("Git status:")
print(out.stdout.decode("utf-8"))
print(out.stderr.decode("utf-8"))
out = subprocess.run(
[
"git",
"commit",
"-m",
f"{organization}-{chart}-{version} {indexfile} (#{pr_number})",
],
cwd=indexdir,
capture_output=True,
)
print(out.stdout.decode("utf-8"))
err = out.stderr.decode("utf-8")
if err.strip():
print(
f"Error committing {indexfile}",
"index directory",
indexdir,
"branch",
branch,
"error:",
err,
)
r = requests.head(
f"https://raw.githubusercontent.com/{repository}/{branch}/{indexfile}"
)
etag = r.headers.get("etag")
if original_etag and etag and (original_etag != etag):
print(
f"{indexfile} not updated. ETag mismatch.",
"original ETag",
original_etag,
"new ETag",
etag,
"index directory",
indexdir,
"branch",
branch,
)
sys.exit(1)
out = subprocess.run(["git", "status"], cwd=indexdir, capture_output=True)
print("Git status:")
print(out.stdout.decode("utf-8"))
print(out.stderr.decode("utf-8"))
out = subprocess.run(
[
"git",
"push",
f"https://x-access-token:{token}@github.com/{repository}",
f"HEAD:refs/heads/{branch}",
"-f",
],
cwd=indexdir,
capture_output=True,
)
print(out.stdout.decode("utf-8"))
print(out.stderr.decode("utf-8"))
if out.returncode:
print(
f"{indexfile} not updated. Push failed.",
"index directory",
indexdir,
"branch",
branch,
)
sys.exit(1)
os.chdir(old_cwd)

chart-releaser provides a way to update an index, see https://github.com/helm/chart-releaser/blob/main/doc/cr_index.md

We should make use of it, via a dedicated action, see https://github.com/helm/chart-releaser-action

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions