Skip to content

Commit

Permalink
Update the snap version of via upstream .go-version (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
addyess authored Nov 7, 2024
1 parent c871eb9 commit 7cce595
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions build-scripts/hack/update-component-versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
import sys
import yaml
from pathlib import Path
import re
import util
import urllib.request


logging.basicConfig(level=logging.INFO)

LOG = logging.getLogger(__name__)

DIR = Path(__file__).absolute().parent
SNAPCRAFT = DIR.parent.parent / "snap/snapcraft.yaml"
COMPONENTS = DIR.parent / "components"
CHARTS = DIR.parent.parent / "k8s" / "manifests" / "charts"

Expand Down Expand Up @@ -125,6 +129,8 @@ def update_component_versions(dry_run: bool):
if not dry_run:
Path(path).write_text(version.strip() + "\n")

update_go_version(dry_run)

for component, pull_helm_chart in [
("bitnami/contour", pull_contour_chart),
("metallb", pull_metallb_chart),
Expand All @@ -134,6 +140,25 @@ def update_component_versions(dry_run: bool):
pull_helm_chart()


def update_go_version(dry_run: bool):
k8s_version = (COMPONENTS / "kubernetes/version").read_text().strip()
url = f"https://raw.githubusercontent.com/kubernetes/kubernetes/refs/tags/{k8s_version}/.go-version"
with urllib.request.urlopen(url) as response:
go_version = response.read().decode("utf-8").strip()

LOG.info("Upstream go version is %s", go_version)
go_snap = f'go/{".".join(go_version.split(".")[:2])}/stable'
snapcraft_yaml = SNAPCRAFT.read_text()
if f"- {go_snap}" in snapcraft_yaml:
LOG.info("snapcraft.yaml already contains go version %s", go_snap)
return

LOG.info("Update go snap version to %s in %s", go_snap, SNAPCRAFT)
if not dry_run:
updated = re.sub(r"- go/\d+\.\d+/stable", f"- {go_snap}", snapcraft_yaml)
SNAPCRAFT.write_text(updated)


def main():
parser = argparse.ArgumentParser(
"update-component-versions.py", usage=USAGE, description=DESCRIPTION
Expand Down

0 comments on commit 7cce595

Please sign in to comment.