From 5f9e29f091506f1d5413a2ab6c3c1e539fed3cc0 Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 20 Jun 2024 14:55:12 -0700 Subject: [PATCH] ci: build linux x64 lib file (#567) --- .releaserc.json | 21 +++++++++++---------- build.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 build.sh diff --git a/.releaserc.json b/.releaserc.json index 76f81c81..161a81ff 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -1,8 +1,5 @@ { - "branches": [ - "main", - "next" - ], + "branches": ["main", "next"], "plugins": [ "@semantic-release/commit-analyzer", "@semantic-release/release-notes-generator", @@ -12,20 +9,24 @@ { "assets": [ { - "path": "rpc_linux_x64", + "path": "rpc_linux_x64.tar.gz", "label": "Linux x64 RPC Executable" }, { - "path": "rpc_linux_x86", + "path": "rpc_linux_x86.tar.gz", "label": "Linux x86 RPC Executable" }, { - "path": "rpc_windows_x64.exe", + "path": "rpc_windows_x64.zip", "label": "Windows x64 RPC Executable" }, { - "path": "rpc_windows_x86.exe", + "path": "rpc_windows_x86.zip", "label": "Windows x86 RPC Executable" + }, + { + "path": "rpc_so_x64.tar.gz", + "label": "Linux x64 RPC Library" } ] } @@ -34,11 +35,11 @@ [ "@semantic-release/exec", { - "prepareCmd": "docker build -t vprodemo.azurecr.io/rpc-go:v${nextRelease.version} . && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags \"-s -w -X 'rpc/pkg/utils.ProjectVersion=${nextRelease.version}'\" -trimpath -o rpc_linux_x64 ./cmd/main.go && CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags \"-s -w -X 'rpc/pkg/utils.ProjectVersion=${nextRelease.version}'\" -trimpath -o rpc_linux_x86 ./cmd/main.go && CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags \"-s -w -X 'rpc/pkg/utils.ProjectVersion=${nextRelease.version}'\" -trimpath -o rpc_windows_x64.exe ./cmd/main.go && CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags \"-s -w -X 'rpc/pkg/utils.ProjectVersion=${nextRelease.version}'\" -trimpath -o rpc_windows_x86.exe ./cmd/main.go", + "prepareCmd": "./build.sh ${nextRelease.version}", "publishCmd": "docker push vprodemo.azurecr.io/rpc-go:v${nextRelease.version}", "verifyReleaseCmd": "echo v${nextRelease.version} > .nextVersion" } ], "@semantic-release/git" ] -} \ No newline at end of file +} diff --git a/build.sh b/build.sh new file mode 100644 index 00000000..db6ac3dc --- /dev/null +++ b/build.sh @@ -0,0 +1,29 @@ +# Get version from the first argument +version=$1 + +docker build -t vprodemo.azurecr.io/rpc-go:v$version . + +# Build for Linux +CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X 'rpc/pkg/utils.ProjectVersion=$version'" -trimpath -o rpc_linux_x64 ./cmd/main.go +CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags "-s -w -X 'rpc/pkg/utils.ProjectVersion=$version'" -trimpath -o rpc_linux_x86 ./cmd/main.go + +# Build for Windows +CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -X 'rpc/pkg/utils.ProjectVersion=$version'" -trimpath -o rpc_windows_x64.exe ./cmd/main.go +CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -ldflags "-s -w -X 'rpc/pkg/utils.ProjectVersion=$version'" -trimpath -o rpc_windows_x86.exe ./cmd/main.go + +# Build library for Linux +CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -trimpath -buildmode=c-shared -o rpc.so.$version ./cmd + +# Mark the Unix system outputs as executable +chmod +x rpc_linux_x64 +chmod +x rpc_linux_x86 + +# Add them to tar files respectively +tar cvfpz rpc_linux_x64.tar.gz rpc_linux_x64 +tar cvfpz rpc_linux_x86.tar.gz rpc_linux_x86 +tar cvfpz rpc_linux_x86.tar.gz rpc_linux_x86 +tar cvfpz rpc_so_x64.tar.gz rpc.so.$version + +# Add Windows build to a zip file +zip rpc_windows_x64.zip rpc_windows_x64.exe +zip rpc_windows_x86.zip rpc_windows_x86.exe \ No newline at end of file