Skip to content

Commit 40198b0

Browse files
allmightyspiffGitHub Enterprise
authored andcommitted
Merge pull request #813 from SoftLayer/issues812
#812 adds ppc64le and s390x to the build
2 parents 8919aa7 + fd3dc1d commit 40198b0

1 file changed

Lines changed: 27 additions & 29 deletions

File tree

bin/buildAndDeploy.py

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import platform
1111
import hashlib
1212
import glob
13-
import sys
1413
from rich import print
1514
from rich.markup import escape
1615

@@ -40,19 +39,11 @@ def buildArchs() -> dict:
4039
"""Returns the list of binaries we should build"""
4140
buildArchs = {
4241
'darwin': ['arm64', 'amd64'],
43-
'linux': ['amd64', '386', 'arm64'],
42+
'linux': ['amd64', '386', 'arm64', 'ppc64le', 's390x'],
4443
'windows': ['386', 'amd64'],
4544
}
4645
return buildArchs
4746

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-
5647

5748
def runTests() -> None:
5849
"""Runs unit tests"""
@@ -76,11 +67,7 @@ def runTests() -> None:
7667
subprocess.run(go_vet, check=True)
7768
go_test = ['go', 'test'] + clean_mods
7869
print(f'[turquoise2]Running: go test $(go list ./... | grep -v "fixtures" | grep -v "vendor")')
79-
try:
80-
subprocess.run(go_test, check=True)
81-
except subprocess.CalledProcessError as e:
82-
print(f"[red]Unit tests failed")
83-
sys.exit(e.returncode)
70+
subprocess.run(go_test, check=True)
8471
go_sec = ['gosec', '-exclude-dir=fixture', '-exclude-dir=plugin/resources', '-quiet', './...']
8572
# Not using the 'real' command because this is more copy/pasteable.
8673
print('[turquoise2]Running: ' + " ".join(go_sec))
@@ -89,9 +76,6 @@ def runTests() -> None:
8976
except FileNotFoundError:
9077
gosec_instal = "curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $GOPATH/bin"
9178
print(f"[red]gosec not found. Try running:\n{gosec_instal}")
92-
93-
94-
9579

9680
### Section for i18n4go stuff ###
9781
def runI18n4go(path: str) -> None:
@@ -177,7 +161,6 @@ def add_i18n(file_name: str, updates: dict) -> None:
177161

178162
write_source_data(file_name, source_i18n)
179163

180-
181164
def del_i18n(file_name: str, updates: dict) -> None:
182165
"""Removes unneeded translations
183166
@@ -195,7 +178,6 @@ def del_i18n(file_name: str, updates: dict) -> None:
195178

196179
write_source_data(file_name, source_i18n)
197180

198-
199181
def get_source_data(file_name: str) -> dict:
200182
"""Reads from the i18n files and returns a formatted dict"""
201183
source_i18n = {}
@@ -272,11 +254,11 @@ def deploy(self):
272254
"""Uploads binaries to IBM COS"""
273255
apikey = os.getenv("IBMCLOUD_APIKEY")
274256
# if IBMCLOUD_TRACE is true the upload will print out the binary file data to the screen.
275-
os.environ["IBMCLOUD_TRACE"] = "False"
257+
os.environ["IBMCLOUD_TRACE"] = "false"
276258
if not apikey:
277259
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")
260+
login_cmd = ["ibmcloud", "login", f"--apikey={apikey}"]
261+
print(f"[yellow]Running: ibmcloud login --apikey $IBMCLOUD_APIKEY")
280262
subprocess.run(login_cmd)
281263
files = glob.glob(os.path.join(self.cwd, 'out', f"sl-{self.version}-*"))
282264
for f in files:
@@ -291,6 +273,8 @@ def getChecksums(self) -> dict:
291273
'Linux_X86': {'file': f"sl-{self.version}-linux-386", 'checksum': ''},
292274
'Linux_X64': {'file': f"sl-{self.version}-linux-amd64", 'checksum': ''},
293275
'Linux_arm64' : {'file': f"sl-{self.version}-linux-arm64", 'checksum': ''},
276+
'Linux_Ppc64le': {'file': f"sl-{self.version}-linux-ppc64le", 'checksum': ''},
277+
'Linux_s390x': {'file': f"sl-{self.version}-linux-s390x", 'checksum': ''},
294278
'MacOS': {'file': f"sl-{self.version}-darwin-amd64", 'checksum': ''},
295279
'MacOS_arm64': {'file': f"sl-{self.version}-darwin-arm64", 'checksum': ''},
296280
'Win_X86': {'file': f"sl-{self.version}-windows-386.exe", 'checksum': ''},
@@ -320,7 +304,14 @@ def runJenkins(self):
320304
'{"name":"Url_Linux_X86", "value":"https://s3.us-east.cloud-object-storage.appdomain.cloud/softlayer-cli-binaries/sl-1.4.2-linux-386"}]}' -v
321305
"""
322306
checksums = self.getChecksums()
307+
# Set this to true if you want to use the Refresh-Plugin-Version-on-YS1 job
308+
refresh = False
309+
# This create a new version
323310
jenkinsUrl = 'https://wcp-cloud-foundry-jenkins.swg-devops.com/job/Publish%20Plugin%20to%20YS1'
311+
312+
if refresh:
313+
# This updates an existing version
314+
jenkinsUrl = 'https://wcp-cloud-foundry-jenkins.swg-devops.com/job/Refresh-Plugin-Version-on-YS1'
324315
jenkins_token = os.getenv('JENKINS_TOKEN')
325316
if not jenkins_token:
326317
raise Exception("JENKINS_TOKEN is not set to an API key")
@@ -337,7 +328,11 @@ def runJenkins(self):
337328

338329
for x in checksums.keys():
339330
urlData = {'name': f"Url_{x}", "value": self.cnd_url + checksums[x]['file']}
340-
checkData = {'name': f"Checksum_{x}", "value": checksums[x]['checksum']}
331+
# This one doesn't follow the normal pattern so it needs a special case.
332+
if x == "Linux_s390x" and not refresh:
333+
checkData = {'name': f"Checksum_Linux_S390x", "value": checksums[x]['checksum']}
334+
else:
335+
checkData = {'name': f"Checksum_{x}", "value": checksums[x]['checksum']}
341336
form_json['parameter'].append(urlData)
342337
form_json['parameter'].append(checkData)
343338

@@ -348,7 +343,10 @@ def runJenkins(self):
348343
print(f"[green] Created Job! Check {jenkinsUrl}" )
349344
else:
350345
print(f"[red]Error: {result.status_code} {result.reason}")
351-
raise Excetion("Error in runJenkins()")
346+
print(f"[yellow] {result.text}")
347+
print(f"[yellow] {result.url}")
348+
print(f"[yellow] {result.request}")
349+
raise Exception("Error in runJenkins()")
352350

353351

354352

@@ -359,16 +357,17 @@ def goBuild(self, theOs: str, theArch: str) -> None:
359357
:param str theOs: OS to build for
360358
:param str theArch: Architecture to build for
361359
"""
360+
cgo_enabled = 0
362361
os.environ["GOOS"] = theOs
363362
os.environ["GOARCH"] = theArch
364-
os.environ["CGO_ENABLED"] = str(cgoEnable(theOs, theArch))
363+
os.environ["CGO_ENABLED"] = str(cgo_enabled)
365364

366365
print(f"[green]Building {theOs}-{theArch}")
367366
binaryName = os.path.join(self.cwd, 'out', f"sl-{self.version}-{theOs}-{theArch}")
368367
if theOs == "windows":
369368
binaryName = f"{binaryName}.exe"
370-
buildCmd = f"go build -ldflags \"-s -w\" -o {binaryName} ."
371-
print(f"[turquoise2]Running {buildCmd}")
369+
buildCmd = f" go build -ldflags \"-s -w\" -o {binaryName} ."
370+
print(f"[turquoise2]Running GOOS={theOs} GOARCH={theArch} CGO_ENABLED={cgo_enabled} {buildCmd}")
372371
# This command basically requires shell=True on mac because -ldflags doesn't get parsed properly withoutit.
373372
subprocess.run(buildCmd, shell=True)
374373

@@ -437,4 +436,3 @@ def i18n(ctx):
437436
# except Exception as e:
438437
# print(f"[red]{e}")
439438

440-

0 commit comments

Comments
 (0)