44import json
55from pathlib import Path
66import os
7+ import sys
78import re
89import subprocess
910import requests
1011import platform
1112import hashlib
1213import glob
13- import sys
1414from rich import print
1515from rich .markup import escape
1616
@@ -40,19 +40,11 @@ def buildArchs() -> dict:
4040 """Returns the list of binaries we should build"""
4141 buildArchs = {
4242 'darwin' : ['arm64' , 'amd64' ],
43- 'linux' : ['amd64' , '386' , 'arm64' ],
43+ 'linux' : ['amd64' , '386' , 'arm64' , 'ppc64le' , 's390x' ],
4444 'windows' : ['386' , 'amd64' ],
4545 }
4646 return buildArchs
4747
48- def cgoEnable (theOs : str , theArch : str ) -> int :
49- """Disable cgo for these archs"""
50- cgo_disable = ["amd64" , "386" , "arm64" ]
51- if theOs == "linux" and theArch in cgo_disable :
52- return 0
53- return 1
54-
55-
5648
5749def runTests () -> None :
5850 """Runs unit tests"""
@@ -72,14 +64,19 @@ def runTests() -> None:
7264
7365 go_vet = ['go' , 'vet' ] + clean_mods
7466 # Not using the 'real' command here because this looks neater.
67+
7568 print (f'[turquoise2]Running: go vet $(go list ./... | grep -v "fixtures" | grep -v "vendor")' )
76- subprocess .run (go_vet , check = True )
69+ try :
70+ subprocess .run (go_vet , check = True )
71+ except subprocess .CalledProcessError as e :
72+ print (f"[red]>>> Go Vet failed <<<" )
73+ sys .exit (e .returncode )
7774 go_test = ['go' , 'test' ] + clean_mods
7875 print (f'[turquoise2]Running: go test $(go list ./... | grep -v "fixtures" | grep -v "vendor")' )
7976 try :
8077 subprocess .run (go_test , check = True )
8178 except subprocess .CalledProcessError as e :
82- print (f"[red]Unit tests failed" )
79+ print (f"[red]>>> Go Test failed <<< " )
8380 sys .exit (e .returncode )
8481 go_sec = ['gosec' , '-exclude-dir=fixture' , '-exclude-dir=plugin/resources' , '-quiet' , './...' ]
8582 # Not using the 'real' command because this is more copy/pasteable.
@@ -89,9 +86,6 @@ def runTests() -> None:
8986 except FileNotFoundError :
9087 gosec_instal = "curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $GOPATH/bin"
9188 print (f"[red]gosec not found. Try running:\n { gosec_instal } " )
92-
93-
94-
9589
9690### Section for i18n4go stuff ###
9791def runI18n4go (path : str ) -> None :
@@ -177,7 +171,6 @@ def add_i18n(file_name: str, updates: dict) -> None:
177171
178172 write_source_data (file_name , source_i18n )
179173
180-
181174def del_i18n (file_name : str , updates : dict ) -> None :
182175 """Removes unneeded translations
183176
@@ -195,7 +188,6 @@ def del_i18n(file_name: str, updates: dict) -> None:
195188
196189 write_source_data (file_name , source_i18n )
197190
198-
199191def get_source_data (file_name : str ) -> dict :
200192 """Reads from the i18n files and returns a formatted dict"""
201193 source_i18n = {}
@@ -272,11 +264,11 @@ def deploy(self):
272264 """Uploads binaries to IBM COS"""
273265 apikey = os .getenv ("IBMCLOUD_APIKEY" )
274266 # if IBMCLOUD_TRACE is true the upload will print out the binary file data to the screen.
275- os .environ ["IBMCLOUD_TRACE" ] = "False "
267+ os .environ ["IBMCLOUD_TRACE" ] = "false "
276268 if not apikey :
277269 raise Exception ("IBMCLOUD_APIKEY needs to be set to the proper API key first." )
278- login_cmd = ["ibmcloud" , "login" , f"--apikey={ apikey } " , "-r=us-east" ]
279- print (f"[yellow]Running: ibmcloud login --apikey $IBMCLOUD_APIKEY -r us-east " )
270+ login_cmd = ["ibmcloud" , "login" , f"--apikey={ apikey } " ]
271+ print (f"[yellow]Running: ibmcloud login --apikey $IBMCLOUD_APIKEY" )
280272 subprocess .run (login_cmd )
281273 files = glob .glob (os .path .join (self .cwd , 'out' , f"sl-{ self .version } -*" ))
282274 for f in files :
@@ -291,6 +283,8 @@ def getChecksums(self) -> dict:
291283 'Linux_X86' : {'file' : f"sl-{ self .version } -linux-386" , 'checksum' : '' },
292284 'Linux_X64' : {'file' : f"sl-{ self .version } -linux-amd64" , 'checksum' : '' },
293285 'Linux_arm64' : {'file' : f"sl-{ self .version } -linux-arm64" , 'checksum' : '' },
286+ 'Linux_Ppc64le' : {'file' : f"sl-{ self .version } -linux-ppc64le" , 'checksum' : '' },
287+ 'Linux_s390x' : {'file' : f"sl-{ self .version } -linux-s390x" , 'checksum' : '' },
294288 'MacOS' : {'file' : f"sl-{ self .version } -darwin-amd64" , 'checksum' : '' },
295289 'MacOS_arm64' : {'file' : f"sl-{ self .version } -darwin-arm64" , 'checksum' : '' },
296290 'Win_X86' : {'file' : f"sl-{ self .version } -windows-386.exe" , 'checksum' : '' },
@@ -320,7 +314,14 @@ def runJenkins(self):
320314 '{"name":"Url_Linux_X86", "value":"https://s3.us-east.cloud-object-storage.appdomain.cloud/softlayer-cli-binaries/sl-1.4.2-linux-386"}]}' -v
321315 """
322316 checksums = self .getChecksums ()
317+ # Set this to true if you want to use the Refresh-Plugin-Version-on-YS1 job
318+ refresh = False
319+ # This create a new version
323320 jenkinsUrl = 'https://wcp-cloud-foundry-jenkins.swg-devops.com/job/Publish%20Plugin%20to%20YS1'
321+
322+ if refresh :
323+ # This updates an existing version
324+ jenkinsUrl = 'https://wcp-cloud-foundry-jenkins.swg-devops.com/job/Refresh-Plugin-Version-on-YS1'
324325 jenkins_token = os .getenv ('JENKINS_TOKEN' )
325326 if not jenkins_token :
326327 raise Exception ("JENKINS_TOKEN is not set to an API key" )
@@ -337,7 +338,11 @@ def runJenkins(self):
337338
338339 for x in checksums .keys ():
339340 urlData = {'name' : f"Url_{ x } " , "value" : self .cnd_url + checksums [x ]['file' ]}
340- checkData = {'name' : f"Checksum_{ x } " , "value" : checksums [x ]['checksum' ]}
341+ # This one doesn't follow the normal pattern so it needs a special case.
342+ if x == "Linux_s390x" and not refresh :
343+ checkData = {'name' : f"Checksum_Linux_S390x" , "value" : checksums [x ]['checksum' ]}
344+ else :
345+ checkData = {'name' : f"Checksum_{ x } " , "value" : checksums [x ]['checksum' ]}
341346 form_json ['parameter' ].append (urlData )
342347 form_json ['parameter' ].append (checkData )
343348
@@ -348,7 +353,10 @@ def runJenkins(self):
348353 print (f"[green] Created Job! Check { jenkinsUrl } " )
349354 else :
350355 print (f"[red]Error: { result .status_code } { result .reason } " )
351- raise Excetion ("Error in runJenkins()" )
356+ print (f"[yellow] { result .text } " )
357+ print (f"[yellow] { result .url } " )
358+ print (f"[yellow] { result .request } " )
359+ raise Exception ("Error in runJenkins()" )
352360
353361
354362
@@ -359,16 +367,17 @@ def goBuild(self, theOs: str, theArch: str) -> None:
359367 :param str theOs: OS to build for
360368 :param str theArch: Architecture to build for
361369 """
370+ cgo_enabled = 0
362371 os .environ ["GOOS" ] = theOs
363372 os .environ ["GOARCH" ] = theArch
364- os .environ ["CGO_ENABLED" ] = str (cgoEnable ( theOs , theArch ) )
373+ os .environ ["CGO_ENABLED" ] = str (cgo_enabled )
365374
366375 print (f"[green]Building { theOs } -{ theArch } " )
367376 binaryName = os .path .join (self .cwd , 'out' , f"sl-{ self .version } -{ theOs } -{ theArch } " )
368377 if theOs == "windows" :
369378 binaryName = f"{ binaryName } .exe"
370- buildCmd = f"go build -ldflags \" -s -w\" -o { binaryName } ."
371- print (f"[turquoise2]Running { buildCmd } " )
379+ buildCmd = f" go build -ldflags \" -s -w\" -o { binaryName } ."
380+ print (f"[turquoise2]Running GOOS= { theOs } GOARCH= { theArch } CGO_ENABLED= { cgo_enabled } { buildCmd } " )
372381 # This command basically requires shell=True on mac because -ldflags doesn't get parsed properly withoutit.
373382 subprocess .run (buildCmd , shell = True )
374383
@@ -437,4 +446,3 @@ def i18n(ctx):
437446 # except Exception as e:
438447 # print(f"[red]{e}")
439448
440-
0 commit comments