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