From a823da1f299447c95fd4a77ab3c169866abd943e Mon Sep 17 00:00:00 2001 From: naiba Date: Wed, 29 Nov 2023 15:45:32 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20static=20link?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 2 +- .github/workflows/test-on-pr.yml | 18 +++++++++++++++--- .github/workflows/test.yml | 17 ++++++++++++++--- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7ab82bc94b..c13f2eeb9b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,7 +30,7 @@ jobs: v: true x: false race: false - ldflags: -s -w -X github.com/naiba/nezha/service/singleton.Version=${{ steps.extract_branch.outputs.tag }} + ldflags: -s -w --extldflags '-static -fpic' -X github.com/naiba/nezha/service/singleton.Version=${{ steps.extract_branch.outputs.tag }} buildmode: default - name: fix dist diff --git a/.github/workflows/test-on-pr.yml b/.github/workflows/test-on-pr.yml index 79a9682d4a..bed02be7dd 100644 --- a/.github/workflows/test-on-pr.yml +++ b/.github/workflows/test-on-pr.yml @@ -17,10 +17,22 @@ jobs: - name: Unit test run: | go test -v ./... - - name: Build test - run: | - go build cmd/dashboard/main.go - name: Run Gosec Security Scanner uses: securego/gosec@master with: args: --exclude=G104,G402 ./... + - name: xgo build + uses: crazy-max/ghaction-xgo@v2 + with: + xgo_version: latest + go_version: 1.21 + dest: dist + pkg: cmd/dashboard + prefix: dashboard + targets: linux/amd64,linux/arm64,linux/arm-7,linux/s390x,linux/riscv64 # linux/386, + v: true + x: false + race: false + ldflags: -s -w --extldflags '-static -fpic' -X github.com/naiba/nezha/service/singleton.Version=test + buildmode: default + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dbf9aff817..98578957d2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,10 +26,21 @@ jobs: - name: Unit test run: | go test -v ./... - - name: Build test - run: | - go build cmd/dashboard/main.go - name: Run Gosec Security Scanner uses: securego/gosec@master with: args: --exclude=G104,G402 ./... + - name: xgo build + uses: crazy-max/ghaction-xgo@v2 + with: + xgo_version: latest + go_version: 1.21 + dest: dist + pkg: cmd/dashboard + prefix: dashboard + targets: linux/amd64,linux/arm64,linux/arm-7,linux/s390x,linux/riscv64 # linux/386, + v: true + x: false + race: false + ldflags: -s -w --extldflags '-static -fpic' -X github.com/naiba/nezha/service/singleton.Version=test + buildmode: default