@@ -48,10 +48,15 @@ def generate_matrix(path_to_data, libs_per_job, delimiter):
48
48
'''
49
49
Generates a matrix in the format of GAV coordinate tuples (depending on the selected number of libraries per action job) for GitHub actions.
50
50
'''
51
- with open (os .path .join (path_to_data , 'popular-maven-libraries.json' ), 'r' ) as f :
52
- data = json .load (f )
53
- with open (os .path .join (path_to_data , 'excluded-popular-maven-libraries.json' ), 'r' ) as f :
54
- exclude_data = json .load (f )
51
+ try :
52
+ with open (os .path .join (path_to_data , 'popular-maven-libraries.json' ), 'r' ) as f :
53
+ data = json .load (f )
54
+ with open (os .path .join (path_to_data , 'excluded-popular-maven-libraries.json' ), 'r' ) as f :
55
+ exclude_data = json .load (f )
56
+ except (FileNotFoundError , json .JSONDecodeError ) as e :
57
+ print (f"Error loading files: { e } " )
58
+ sys .exit (1 )
59
+
55
60
matrix = {'coordinates' : []}
56
61
excluded_coordinates = {f'{ lib ['group_id' ]} :{ lib ['artifact_id' ]} :{ lib ['version' ]} ' for lib in exclude_data }
57
62
libs_in_job = []
@@ -67,11 +72,14 @@ def generate_matrix(path_to_data, libs_per_job, delimiter):
67
72
if len (libs_in_job ) > 0 :
68
73
matrix ['coordinates' ].append (delimiter .join (libs_in_job ))
69
74
70
- try :
71
- with open (os .environ ['GITHUB_OUTPUT' ], 'a' ) as f :
72
- print (f"matrix={ json .dumps (matrix )} " , file = f )
73
- except IOError :
74
- print ("Error: Failed opening GITHUB_OUTPUT. Stopping action..." )
75
+ try :
76
+ github_output = os .getenv ('GITHUB_OUTPUT' )
77
+ if github_output is None :
78
+ raise EnvironmentError ("GITHUB_OUTPUT environment variable not set" )
79
+ with open (github_output , 'a' ) as f :
80
+ f .write (f"matrix={ json .dumps (matrix )} \n " )
81
+ except (IOError , EnvironmentError ) as e :
82
+ print (f"Error writing to GITHUB_OUTPUT: { e } " )
75
83
sys .exit (1 )
76
84
77
85
def build_layers (native_image_path , coordinates , delimiter ):
@@ -87,12 +95,13 @@ def build_layers(native_image_path, coordinates, delimiter):
87
95
for gav in coordinates_list :
88
96
currDir = os .getcwd ()
89
97
group_id , artifact_id , version = gav .split (':' )
98
+
90
99
subprocess .run (['mvn' , 'dependency:get' , f'-Dartifact={ gav } ' , '-Dtransitive=true' ])
91
100
92
- home_path = str (Path .home ())
93
- library_path = os .path .join (home_path , '.m2' , 'repository' , group_id .replace ('.' ,'/' ), artifact_id , version )
101
+ library_path = os .path .join (Path .home (), '.m2' , 'repository' , group_id .replace ('.' ,'/' ), artifact_id , version )
94
102
jar_path = os .path .join (library_path , f'{ artifact_id } -{ version } .jar' )
95
103
subprocess .run (['cp' , f'{ os .path .join (library_path , f'{ artifact_id } -{ version } .pom' )} ' , f'{ os .path .join (library_path , 'pom.xml' )} ' ])
104
+
96
105
if Path (library_path ).exists ():
97
106
subprocess .run (['mkdir' , gav ])
98
107
os .chdir (gav )
@@ -104,6 +113,7 @@ def build_layers(native_image_path, coordinates, delimiter):
104
113
subprocess .run (command )
105
114
print (f'Command: { ' ' .join (command )} ' )
106
115
os .chdir ('..' )
116
+
107
117
os .chdir (currDir )
108
118
109
119
if __name__ == '__main__' :
0 commit comments