Skip to content

Commit 63b6413

Browse files
committed
test: add build tags and extra ld flags in alpine build
Signed-off-by: Peefy <xpf6677@163.com>
1 parent 6420223 commit 63b6413

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

.github/workflows/go-test.yaml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,22 @@ jobs:
9999
- name: Go mod tidy
100100
run: go mod tidy
101101

102+
- name: Setup build tags for Alpine
103+
if: matrix.container != null
104+
run: |
105+
echo "GO_BUILD_TAGS=netgo static osusergo" >> $GITHUB_ENV
106+
echo "GO_LDFLAGS=-linkmode external -extldflags '-static'" >> $GITHUB_ENV
107+
102108
- name: Go code test (CGO_ENABLED=${{ matrix.cgo_enabled }})
103109
run: |
104-
CGO_ENABLED=${{ matrix.cgo_enabled }} go test ./... -v
110+
if [ -n "${{ matrix.container }}" ]; then
111+
BUILD_TAGS="$GO_BUILD_TAGS"
112+
EXTRA_LDFLAGS="$GO_LDFLAGS"
113+
fi
114+
115+
CGO_ENABLED=${{ matrix.cgo_enabled }} \
116+
go test ./... -v \
117+
-tags="${BUILD_TAGS}" \
118+
-ldflags="${EXTRA_LDFLAGS}"
105119
env:
106120
CGO_LDFLAGS: ${{ matrix.cgo_enabled == '1' && '-static' || '' }}

0 commit comments

Comments
 (0)