Skip to content

Commit

Permalink
Merge pull request #1351 from ErikJiang/fix_artifact_doc
Browse files Browse the repository at this point in the history
fix rls version handing in artifacts doc
  • Loading branch information
ErikJiang authored Aug 30, 2024
2 parents 08a1646 + f4e11d7 commit 97928e6
Showing 1 changed file with 38 additions and 36 deletions.
74 changes: 38 additions & 36 deletions artifacts/gen_artifact_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,44 +43,46 @@


if __name__ == '__main__':
try:
repo_name="kubean-manifest"
subprocess.run(["/usr/bing/git", "clone", f"https://github.com/{IMAGE_REPO}/{repo_name}.git"], check=True)
manifests_path=f'{repo_name}/manifests'
rls_pattern = re.compile(r'manifest-(\d+\.\d+)-.*\.yml')

repo_name="kubean-manifest"
subprocess.getoutput(f"git clone https://github.com/{IMAGE_REPO}/{repo_name}.git")
manifests_path=f'{repo_name}/manifests'
rls_pattern = re.compile(r'manifest-(\d+\.\d+)-.*\.yml')
releases = {}
for manifest in os.listdir(manifests_path):
match = rls_pattern.match(manifest)
if match:
rls_version = match.group(1)
if rls_version not in releases:
releases.setdefault(rls_version, [])
with open(f'{manifests_path}/{manifest}', 'r') as stream:
data = yaml.safe_load(stream)
commit_short_sha = data.get('metadata', {}).get('annotations', {}).get('kubean.io/sprayCommit')
commit_timestamp = int(data.get('metadata', {}).get('annotations', {}).get('kubean.io/sprayTimestamp'))
commit_date = datetime.fromtimestamp(commit_timestamp)
components = data.get('spec', {}).get('components', {})
kube_info = next(item for item in data.get('spec', {}).get('components', {}) if item['name'] == 'kube')
kube_version_range = kube_info.get('versionRange', [])
sorted_versions = sorted(kube_version_range, key=lambda x: [int(x) if x.isdigit() else x for x in re.split('([0-9]+)', x)], reverse=True)
releases[rls_version].append({
'commit_short_sha': commit_short_sha,
'commit_timestamp': commit_timestamp,
'commit_date': commit_date,
'kube_version_range': sorted_versions})

releases = {}
for manifest in os.listdir(manifests_path):
match = rls_pattern.match(manifest)
if match:
rls_version = match.group(1)
releases[rls_version] = []
with open(f'{manifests_path}/{manifest}', 'r') as stream:
data = yaml.safe_load(stream)
commit_short_sha = data.get('metadata', {}).get('annotations', {}).get('kubean.io/sprayCommit')
commit_timestamp = int(data.get('metadata', {}).get('annotations', {}).get('kubean.io/sprayTimestamp'))
commit_date = datetime.fromtimestamp(commit_timestamp)
components = data.get('spec', {}).get('components', {})
kube_info = next(item for item in data.get('spec', {}).get('components', {}) if item['name'] == 'kube')
kube_version_range = kube_info.get('versionRange', [])
sorted_versions = sorted(kube_version_range, key=lambda x: [int(x) if x.isdigit() else x for x in re.split('([0-9]+)', x)], reverse=True)
releases[rls_version].append({
'commit_short_sha': commit_short_sha,
'commit_timestamp': commit_timestamp,
'commit_date': commit_date,
'kube_version_range': sorted_versions})
for key in releases.keys():
releases[key].sort(key=lambda item:item['commit_timestamp'], reverse=True)

for key in releases.keys():
releases[key].sort(key=lambda item:item['commit_timestamp'], reverse=True)
# print(f'releases: {releases}')

# print(f'releases: {releases}')
t = Template(KUBEAN_PATCH_TEMPLATE)
md_contents = t.render(releases=releases, image_registry='ghcr.io', repo_name=IMAGE_REPO)
# print(md_contents)

t = Template(KUBEAN_PATCH_TEMPLATE)
md_contents = t.render(releases=releases, image_registry='ghcr.io', repo_name=IMAGE_REPO)
# print(md_contents)

artifact_md = open('artifacts.md', 'w')
artifact_md.write(md_contents)
artifact_md.close()

subprocess.getoutput(f"rm -rf {repo_name}")
with open('artifacts.md', 'w') as artifact_md:
artifact_md.write(md_contents)
except Exception as e:
print(f" An error occurred: {e}")
finally:
subprocess.getoutput(f"rm -rf {repo_name}")

0 comments on commit 97928e6

Please sign in to comment.