forked from SAP/cf-cli-java-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate_plugin_repo.py
More file actions
106 lines (92 loc) · 3.68 KB
/
generate_plugin_repo.py
File metadata and controls
106 lines (92 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
"""
Generate plugin repository YAML file for CF CLI plugin repository.
This script creates the YAML file in the required format for the CF CLI plugin repository.
"""
import os
import sys
import yaml
import hashlib
import requests
from datetime import datetime
from pathlib import Path
def calculate_sha1(file_path):
"""Calculate SHA1 checksum of a file."""
sha1_hash = hashlib.sha1()
with open(file_path, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
sha1_hash.update(chunk)
return sha1_hash.hexdigest()
def get_version_from_tag():
"""Get version from git tag or environment variable."""
version = os.environ.get('GITHUB_REF_NAME', '')
if version.startswith('v'):
version = version[1:] # Remove 'v' prefix
return version or "dev"
def generate_plugin_repo_yaml():
"""Generate the plugin repository YAML file."""
version = get_version_from_tag()
repo_url = "https://github.com/SAP/cf-cli-java-plugin"
# Define the binary platforms and their corresponding file extensions
platforms = {
"linux64": "cf-cli-java-plugin-linux-amd64",
"osx": "cf-cli-java-plugin-macos-arm64",
"win64": "cf-cli-java-plugin-windows-amd64"
}
binaries = []
dist_dir = Path("dist")
for platform, filename in platforms.items():
file_path = dist_dir / filename
if file_path.exists():
checksum = calculate_sha1(file_path)
binary_info = {
"checksum": checksum,
"platform": platform,
"url": f"{repo_url}/releases/download/v{version}/{filename}"
}
binaries.append(binary_info)
print(f"Added {platform}: {filename} (checksum: {checksum})")
else:
print(f"Warning: Binary not found for {platform}: {filename}")
if not binaries:
print("Error: No binaries found in dist/ directory")
sys.exit(1)
# Create the plugin repository entry
plugin_entry = {
"authors": [{
"contact": "johannes.bechberger@sap.com",
"homepage": "https://github.com/SAP",
"name": "Johannes Bechberger"
}],
"binaries": binaries,
"company": "SAP",
"created": "2024-01-01T00:00:00Z", # Initial creation date
"description": "Plugin for profiling Java applications and getting heap and thread-dumps",
"homepage": repo_url,
"name": "java",
"updated": datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"),
"version": version
}
# Write the YAML file
output_file = Path("plugin-repo-entry.yml")
with open(output_file, 'w') as f:
yaml.dump(plugin_entry, f, default_flow_style=False, sort_keys=False)
print(f"Generated plugin repository YAML file: {output_file}")
print(f"Version: {version}")
print(f"Binaries: {len(binaries)} platforms")
# Also create a human-readable summary
summary_file = Path("plugin-repo-summary.txt")
with open(summary_file, 'w') as f:
f.write(f"CF CLI Java Plugin Repository Entry\n")
f.write(f"====================================\n\n")
f.write(f"Version: {version}\n")
f.write(f"Updated: {plugin_entry['updated']}\n")
f.write(f"Binaries: {len(binaries)} platforms\n\n")
f.write("Platform checksums:\n")
for binary in binaries:
f.write(f" {binary['platform']}: {binary['checksum']}\n")
f.write(f"\nRepository URL: {repo_url}\n")
f.write(f"Release URL: {repo_url}/releases/tag/v{version}\n")
print(f"Generated summary file: {summary_file}")
if __name__ == "__main__":
generate_plugin_repo_yaml()