@@ -19,7 +19,9 @@ package main
1919import (
2020 "log"
2121 "os"
22+ "os/exec"
2223 "regexp"
24+ "strconv"
2325 "strings"
2426)
2527
@@ -84,6 +86,42 @@ func main() {
8486 log .Fatalf ("the environment variable 'DEP' needs to be set" )
8587 }
8688 depName = standrizeComponentName (depName )
89+
90+ // Handle special cases
91+ switch depName {
92+ case "docsy" :
93+ version , err := getDocsyVersion ()
94+ if err != nil {
95+ log .Fatalf ("failed to get docsy version: %v" , err )
96+ }
97+ os .Stdout .WriteString (version )
98+ return
99+ case "kubeadm-constants" :
100+ version , err := getKubeadmConstantsVersion ()
101+ if err != nil {
102+ log .Fatalf ("failed to get kubeadm constants version: %v" , err )
103+ }
104+ os .Stdout .WriteString (version )
105+ return
106+ case "kubernetes" :
107+ version , err := getKubernetesVersion ()
108+ if err != nil {
109+ log .Fatalf ("failed to get kubernetes version: %v" , err )
110+ }
111+ os .Stdout .WriteString (version )
112+ return
113+ case "kubernetes-versions-list" :
114+ version , err := getKubernetesVersionsList ()
115+ if err != nil {
116+ log .Fatalf ("failed to get kubernetes versions list: %v" , err )
117+ }
118+ os .Stdout .WriteString (version )
119+ return
120+ case "site-node" :
121+ // Use regular handling for site-node-version (same as "node" from netlify.toml)
122+ depName = "node"
123+ }
124+
87125 dep , ok := dependencies [depName ]
88126 if ! ok {
89127 log .Fatalf ("%s is not a valid dependency" , depName )
@@ -109,6 +147,97 @@ func standrizeComponentName(name string) string {
109147 // Convert the component name to lowercase and replace underscores with hyphens
110148 name = strings .ToLower (name )
111149 name = strings .ReplaceAll (name , "_" , "-" )
112- name = strings .ReplaceAll (name , "-version" , "" )
150+
151+ // Remove "-version" suffix only at the end to avoid breaking words like "versions"
152+ name = strings .TrimSuffix (name , "-version" )
113153 return name
114154}
155+
156+ // getDocsyVersion returns the current commit hash of the docsy submodule
157+ func getDocsyVersion () (string , error ) {
158+ // Change to parent directory since we're running from hack/
159+ cmd := exec .Command ("git" , "submodule" , "status" , "site/themes/docsy" )
160+ cmd .Dir = ".." // Change to the repo root
161+ output , err := cmd .Output ()
162+ if err != nil {
163+ return "" , err
164+ }
165+
166+ // Output format: " commit-hash path/to/submodule (tag or branch)"
167+ // We want just the commit hash (first 8 characters for short hash)
168+ parts := strings .Fields (string (output ))
169+ if len (parts ) < 1 {
170+ return "" , log .New (os .Stderr , "" , 0 ).Output (1 , "no commit hash found in git submodule status" )
171+ }
172+
173+ commitHash := strings .TrimSpace (parts [0 ])
174+ // Remove leading space or other characters and take first 8 characters
175+ if len (commitHash ) > 8 {
176+ commitHash = commitHash [:8 ]
177+ }
178+ return commitHash , nil
179+ }
180+
181+ // getKubeadmConstantsVersion returns a summary of kubeadm constants versions
182+ func getKubeadmConstantsVersion () (string , error ) {
183+ // Read the constants file to get a representative version
184+ data , err := os .ReadFile ("../pkg/minikube/constants/constants_kubeadm_images.go" )
185+ if err != nil {
186+ return "" , err
187+ }
188+
189+ // Look for the latest kubernetes version entry in the KubeadmImages map
190+ re := regexp .MustCompile (`"(v\d+\.\d+\.\d+[^"]*)":\s*{` )
191+ matches := re .FindAllSubmatch (data , - 1 )
192+ if len (matches ) == 0 {
193+ return "no-versions" , nil
194+ }
195+
196+ // Return the last (latest) version found
197+ lastMatch := matches [len (matches )- 1 ]
198+ return string (lastMatch [1 ]), nil
199+ }
200+
201+ // getKubernetesVersion returns the default kubernetes version
202+ func getKubernetesVersion () (string , error ) {
203+ data , err := os .ReadFile ("../pkg/minikube/constants/constants.go" )
204+ if err != nil {
205+ return "" , err
206+ }
207+
208+ // Look for DefaultKubernetesVersion
209+ re := regexp .MustCompile (`DefaultKubernetesVersion = "(.*?)"` )
210+ matches := re .FindSubmatch (data )
211+ if len (matches ) < 2 {
212+ return "" , log .New (os .Stderr , "" , 0 ).Output (1 , "DefaultKubernetesVersion not found" )
213+ }
214+
215+ return string (matches [1 ]), nil
216+ }
217+
218+ // getKubernetesVersionsList returns a count of supported kubernetes versions
219+ func getKubernetesVersionsList () (string , error ) {
220+ data , err := os .ReadFile ("../pkg/minikube/constants/constants_kubernetes_versions.go" )
221+ if err != nil {
222+ return "" , err
223+ }
224+
225+ // Count the number of versions in ValidKubernetesVersions
226+ re := regexp .MustCompile (`"v\d+\.\d+\.\d+[^"]*"` )
227+ matches := re .FindAll (data , - 1 )
228+
229+ if len (matches ) == 0 {
230+ return "0-versions" , nil
231+ }
232+
233+ // Return count and range if available
234+ if len (matches ) >= 2 {
235+ first := string (matches [0 ])
236+ last := string (matches [len (matches )- 1 ])
237+ first = strings .Trim (first , "\" " )
238+ last = strings .Trim (last , "\" " )
239+ return first + ".." + last + " (" + strconv .Itoa (len (matches )) + " versions)" , nil
240+ }
241+
242+ return strings .Trim (string (matches [0 ]), "\" " ), nil
243+ }
0 commit comments