-
Notifications
You must be signed in to change notification settings - Fork 3
94 lines (81 loc) · 2.54 KB
/
release.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
env:
CLOUDCAT: "cloudcat"
BINARY_SUFFIX: ""
CCATCTL: "ccatctl"
COMMIT_ID: "${{ github.sha }}"
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/amd64, darwin/arm64
goos: [linux, windows, darwin]
goarch: ["386", amd64, arm, arm64]
exclude:
- goos: darwin
goarch: arm
- goos: darwin
goarch: "386"
fail-fast: true
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
- name: Tests
run: |
go test $(go list ./...)
- name: Build binary file
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
if [ $GOOS = "windows" ]; then export BINARY_SUFFIX="$BINARY_SUFFIX.exe"; fi
export CGO_ENABLED=0
export LD_FLAGS="-w -s -X github.com/scriptscat/cloudcat/configs.Version=${COMMIT_ID::7}"
go build -o "bin/${CLOUDCAT}${BINARY_SUFFIX}" -trimpath -ldflags "$LD_FLAGS" ./cmd/cloudcat
go build -o "bin/${CCATCTL}${BINARY_SUFFIX}" -trimpath -ldflags "$LD_FLAGS" ./cmd/ccatctl
cd bin
if [ "${{ matrix.goos }}" = "windows" ]; then
zip -j "${CLOUDCAT}_${GOOS}_${GOARCH}.zip" "${CCATCTL}.exe" "${CLOUDCAT}.exe"
else
tar czvf "${CLOUDCAT}_${GOOS}_${GOARCH}.tar.gz" "${CCATCTL}" "${CLOUDCAT}"
fi
- name: Upload artifact
uses: actions/upload-artifact@v3
if: ${{ matrix.goos != 'windows' }}
with:
name: ${{ matrix.goos }}_${{ matrix.goarch }}
path: bin/*.tar.gz
- name: Upload windows artifact
uses: actions/upload-artifact@v3
if: ${{ matrix.goos == 'windows' }}
with:
name: ${{ matrix.goos }}_${{ matrix.goarch }}
path: bin/*.zip
release:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# 拿到build产物
- uses: actions/download-artifact@v3
with:
path: bin/
- uses: ncipollo/release-action@v1
with:
artifacts: "bin/*/*.tar.gz,bin/*/*.zip"
body: "no describe"
# 判断是否为预发布(包含alpha、beta等关键字)
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') }}