github.com/jfrog/frogbot@v1.1.1-0.20231221090046-821a26f50338/release/buildAndUpload.sh (about) 1 #!/bin/bash 2 set -eu 3 4 #function build(pkg, goos, goarch, exeName) 5 build () { 6 pkg="$1" 7 export GOOS="$2" 8 export GOARCH="$3" 9 exeName="$4" 10 echo "Building $exeName for $GOOS-$GOARCH ..." 11 12 CGO_ENABLED=0 jf go build -o "$exeName" -ldflags '-w -extldflags "-static" -X github.com/jfrog/frogbot/utils.FrogbotVersion='"$version" 13 chmod +x "$exeName" 14 15 # Run verification after building plugin for the correct platform of this image. 16 if [[ "$pkg" = "frogbot-linux-386" ]]; then 17 verifyVersionMatching 18 fi 19 } 20 21 #function buildAndUpload(pkg, goos, goarch, fileExtension) 22 buildAndUpload () { 23 pkg="$1" 24 goos="$2" 25 goarch="$3" 26 fileExtension="$4" 27 exeName="frogbot$fileExtension" 28 29 build "$pkg" "$goos" "$goarch" "$exeName" 30 31 destPath="$pkgPath/$version/$pkg/$exeName" 32 echo "Uploading $exeName to $destPath ..." 33 jf rt u "./$exeName" "$destPath" 34 } 35 36 # Verify version provided in pipelines UI matches version in frogbot source code. 37 verifyVersionMatching () { 38 echo "Verifying provided version matches built version..." 39 res=$(eval "./frogbot -v") 40 exitCode=$? 41 if [[ $exitCode -ne 0 ]]; then 42 echo "Error: Failed verifying version matches" 43 exit $exitCode 44 fi 45 46 # Get the version which is after the last space. (expected output to -v for example: "Frogbot version version v2.0.0") 47 echo "Output: $res" 48 builtVersion="${res##* }" 49 # Compare versions 50 if [[ "$builtVersion" != "$version" ]]; then 51 echo "Versions dont match. Provided: $version, Actual: $builtVersion" 52 exit 1 53 fi 54 echo "Versions match." 55 } 56 57 version="$1" 58 pkgPath="ecosys-frogbot/v2" 59 60 # Build and upload for every architecture. 61 # Keep 'linux-386' first to prevent unnecessary uploads in case the built version doesn't match the provided one. 62 buildAndUpload 'frogbot-linux-386' 'linux' '386' '' 63 buildAndUpload 'frogbot-linux-amd64' 'linux' 'amd64' '' 64 buildAndUpload 'frogbot-linux-s390x' 'linux' 's390x' '' 65 buildAndUpload 'frogbot-linux-arm64' 'linux' 'arm64' '' 66 buildAndUpload 'frogbot-linux-arm' 'linux' 'arm' '' 67 buildAndUpload 'frogbot-linux-ppc64' 'linux' 'ppc64' '' 68 buildAndUpload 'frogbot-linux-ppc64le' 'linux' 'ppc64le' '' 69 buildAndUpload 'frogbot-mac-386' 'darwin' 'amd64' '' 70 buildAndUpload 'frogbot-windows-amd64' 'windows' 'amd64' '.exe' 71 72 jf rt u "./buildscripts/getFrogbot.sh" "$pkgPath/$version/" --flat