-
Notifications
You must be signed in to change notification settings - Fork 3
199 lines (161 loc) · 6.48 KB
/
Copy pathbuild.yml
File metadata and controls
199 lines (161 loc) · 6.48 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
name: Build
on:
push:
branches: [main]
pull_request:
jobs:
test:
name: Vet & test (race)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.26'
cache: true
cache-dependency-path: go.sum
- name: Install CGO deps
run: |
sudo apt-get update
sudo apt-get install -y build-essential libasound2-dev
- name: Vet
run: go vet ./...
- name: Test (race detector)
env:
CGO_ENABLED: 1
run: go test -race ./...
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.26'
cache: true
cache-dependency-path: go.sum
- name: Install CGO deps
run: |
sudo apt-get update
sudo apt-get install -y build-essential libasound2-dev
- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: latest
build:
name: Build (${{ matrix.goos }}/${{ matrix.goarch }})
strategy:
fail-fast: false
matrix:
include:
- goos: linux
goarch: amd64
runner: ubuntu-latest
- goos: linux
goarch: arm64
runner: ubuntu-24.04-arm
- goos: windows
goarch: amd64
runner: ubuntu-latest
- goos: windows
goarch: arm64
runner: ubuntu-latest
- goos: darwin
goarch: amd64
runner: ubuntu-latest
- goos: darwin
goarch: arm64
runner: ubuntu-latest
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.26'
cache: true
cache-dependency-path: go.sum
- name: Install CGO deps (Linux only)
if: matrix.goos == 'linux'
run: |
sudo apt-get update
sudo apt-get install -y build-essential libasound2-dev
- name: Set binary extension
id: bin
run: |
if [ "${{ matrix.goos }}" = "windows" ]; then
echo "ext=.exe" >> $GITHUB_OUTPUT
else
echo "ext=" >> $GITHUB_OUTPUT
fi
- name: Set CGO flag
id: cgo
run: |
if [ "${{ matrix.goos }}" = "linux" ]; then
echo "enabled=1" >> $GITHUB_OUTPUT
else
echo "enabled=0" >> $GITHUB_OUTPUT
fi
- name: Build Discord bot
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: ${{ steps.cgo.outputs.enabled }}
run: |
set -e
BUILD_DATE=$(date -u +"%Y-%m-%dT%H-%M-%SZ")
GIT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "none")
mkdir -p dist
go build -trimpath \
-ldflags="-s -w \
-X github.com/keshon/buildinfo.Version=dev \
-X github.com/keshon/buildinfo.Commit=${GIT_COMMIT} \
-X github.com/keshon/buildinfo.BuildTime=${BUILD_DATE} \
-X github.com/keshon/buildinfo.Project=Melodix \
-X 'github.com/keshon/buildinfo.Description=Discord music bot that allows you to play music from YouTube, SoundCloud and internet radio streams.'" \
-o dist/melodix-discord${{ steps.bin.outputs.ext }} \
./cmd/discord/
- name: Build CLI player
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: ${{ steps.cgo.outputs.enabled }}
run: |
set -e
BUILD_DATE=$(date -u +"%Y-%m-%dT%H-%M-%SZ")
GIT_COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "none")
go build -trimpath \
-ldflags="-s -w \
-X github.com/keshon/buildinfo.Version=dev \
-X github.com/keshon/buildinfo.Commit=${GIT_COMMIT} \
-X github.com/keshon/buildinfo.BuildTime=${BUILD_DATE} \
-X github.com/keshon/buildinfo.Project=Melodix \
-X 'github.com/keshon/buildinfo.Description=CLI music player - same playback engine as the Discord bot.'" \
-o dist/melodix-cli${{ steps.bin.outputs.ext }} \
./cmd/cli/
- name: Prepare build bundle
run: |
PKG_ROOT="melodix-${{ matrix.goos }}-${{ matrix.goarch }}"
mkdir -p "${PKG_ROOT}"
cp "dist/melodix-discord${{ steps.bin.outputs.ext }}" "${PKG_ROOT}/"
cp "dist/melodix-cli${{ steps.bin.outputs.ext }}" "${PKG_ROOT}/"
cp README.md LICENSE "${PKG_ROOT}/"
if [ -f .env.example ]; then
cp .env.example "${PKG_ROOT}/.env"
fi
mkdir -p "${PKG_ROOT}/data"
if [ -d assets ]; then
cp -R assets "${PKG_ROOT}/"
fi
zip -r "dist/${PKG_ROOT}.zip" "${PKG_ROOT}"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: melodix-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/melodix-${{ matrix.goos }}-${{ matrix.goarch }}.zip
retention-days: 14