-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (60 loc) · 1.98 KB
/
go.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: Bulid
on: [push, pull_request,workflow_dispatch]
env:
BINARY_PREFIX: "BFHelper"
BINARY_SUFFIX: ""
COMMIT_ID: "${{ github.sha }}"
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
goos: [linux,windows,darwin]
goarch: ["386",arm,arm64,amd64]
# mac无需构建386和arm
# windows由于libc不能构建arm
exclude:
- goos: darwin
goarch: "386"
- goos: darwin
goarch: arm
- goos: windows
goarch: arm
fail-fast: true
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
cache: true
go-version: '1.22'
- name: Cache Go Modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: go-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
go-${{ runner.os }}-
- name: Build binary file
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
IS_PR: ${{ !!github.head_ref }}
# 如果是windows, 添加.exe后缀
# 如果是拉取请求触发, 显示拉取请求, 不构建
run: |
if [ $GOOS = "windows" ]; then export BINARY_SUFFIX="$BINARY_SUFFIX.exe"; fi
if $IS_PR ; then echo $PR_PROMPT; fi
export BINARY_NAME="${BINARY_PREFIX}v${COMMIT_ID::5}_${GOOS}_${GOARCH}${BINARY_SUFFIX}"
export CGO_ENABLED=0
export LD_FLAGS="-checklinkname=0 -w -s -X github.com/KomeiDiSanXian/BFHelper/kanban/banner.Version=${COMMIT_ID::7}"
go build -o "output/$BINARY_NAME" -trimpath -ldflags "$LD_FLAGS" .
- name: Upload artifact
uses: actions/upload-artifact@v4
if: ${{ !github.head_ref }}
with:
name: ${{ matrix.goos }}_${{ matrix.goarch }}
path: output/