2
2
import json
3
3
import re
4
4
5
+
5
6
def get_git_tags ():
6
7
try :
7
8
result = subprocess .run (
8
- ["git" , "tag" , "--points-at" , "HEAD" ], capture_output = True , text = True , check = True
9
+ ["git" , "tag" , "--points-at" , "HEAD" ],
10
+ capture_output = True ,
11
+ text = True ,
12
+ check = True ,
9
13
)
10
14
return result .stdout .strip ().splitlines ()
11
15
except subprocess .CalledProcessError :
12
16
# if no tags are found, return an empty list
13
17
return []
14
18
19
+
15
20
def extract_name_and_version_from_tag (tag ):
16
21
match = re .match (r"(pixi-build-[a-zA-Z-]+)-v(\d+\.\d+\.\d+)" , tag )
17
22
if match :
18
23
return match .group (1 ), match .group (2 )
19
- raise ValueError (f"Invalid Git tag format: { tag } . Expected format: pixi-build-[name]-v[version]" )
24
+ raise ValueError (
25
+ f"Invalid Git tag format: { tag } . Expected format: pixi-build-[name]-v[version]"
26
+ )
20
27
21
28
22
29
def generate_matrix ():
@@ -32,20 +39,20 @@ def generate_matrix():
32
39
# this is to overcome the issue of matrix generation from github actions side
33
40
# https://github.com/orgs/community/discussions/67591
34
41
targets = [
35
- {"target" : "linux-64" , "os" : "ubuntu-20.04 " },
42
+ {"target" : "linux-64" , "os" : "ubuntu-latest " },
36
43
{"target" : "linux-aarch64" , "os" : "ubuntu-latest" },
37
44
{"target" : "linux-ppc64le" , "os" : "ubuntu-latest" },
38
45
{"target" : "win-64" , "os" : "windows-latest" },
39
46
{"target" : "osx-64" , "os" : "macos-13" },
40
- {"target" : "osx-arm64" , "os" : "macos-14" }
47
+ {"target" : "osx-arm64" , "os" : "macos-14" },
41
48
]
42
49
43
50
git_tags = get_git_tags ()
44
51
45
52
# Extract bin names, versions, and generate env and recipe names
46
53
matrix = []
47
54
48
- if not "packages" in metadata :
55
+ if "packages" not in metadata :
49
56
raise ValueError ("No packages found using cargo metadata" )
50
57
51
58
# verify that the tags match the package versions
@@ -62,7 +69,9 @@ def generate_matrix():
62
69
continue # Skip packages that do not match the tag
63
70
64
71
if package ["version" ] != tag_version :
65
- raise ValueError (f"Version mismatch: Git tag version { tag_version } does not match Cargo version { package ["version" ]} for { package ["name" ]} " )
72
+ raise ValueError (
73
+ f"Version mismatch: Git tag version { tag_version } does not match Cargo version { package ['version' ]} for { package ['name' ]} "
74
+ )
66
75
67
76
tagged_packages [git_tag ] = package
68
77
package_tagged = True
@@ -73,25 +82,29 @@ def generate_matrix():
73
82
continue
74
83
75
84
for target in targets :
76
- matrix .append ({
77
- "bin" : package ["name" ],
78
- "version" : package ["version" ],
79
- "env_name" : package ["name" ].replace ("-" , "_" ).upper () + "_VERSION" ,
80
- "crate_name" : package ["name" ],
81
- "target" : target ["target" ],
82
- "os" : target ["os" ]
83
- })
85
+ matrix .append (
86
+ {
87
+ "bin" : package ["name" ],
88
+ "version" : package ["version" ],
89
+ "env_name" : package ["name" ].replace ("-" , "_" ).upper ()
90
+ + "_VERSION" ,
91
+ "crate_name" : package ["name" ],
92
+ "target" : target ["target" ],
93
+ "os" : target ["os" ],
94
+ }
95
+ )
84
96
85
97
if tagged_packages :
86
98
for git_tag , has_a_package in tagged_packages .items ():
87
99
if not has_a_package :
88
- raise ValueError (f"Git tag { git_tag } does not match any package in Cargo.toml" )
89
-
100
+ raise ValueError (
101
+ f"Git tag { git_tag } does not match any package in Cargo.toml"
102
+ )
90
103
91
104
matrix_json = json .dumps (matrix )
92
105
93
-
94
106
print (matrix_json )
95
107
108
+
96
109
if __name__ == "__main__" :
97
110
generate_matrix ()
0 commit comments