-
Notifications
You must be signed in to change notification settings - Fork 0
448 lines (389 loc) · 13.8 KB
/
test.yml
File metadata and controls
448 lines (389 loc) · 13.8 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
name: Test
on:
push:
branches: [main, master, develop]
pull_request:
branches: [main, master, develop]
workflow_dispatch:
jobs:
test:
name: Run Tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go-version: ['1.21', '1.22']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Cache Go modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download dependencies
run: go mod download
- name: Run unit tests
shell: bash
run: go test -v -race -coverprofile=coverage.out ./...
- name: Build binary for integration tests
if: matrix.os != 'windows-latest'
shell: bash
run: go build -o shelldock .
- name: Run integration tests
if: matrix.os != 'windows-latest'
shell: bash
run: |
chmod +x test/test-suite.sh
./test/test-suite.sh
- name: Upload coverage
uses: codecov/codecov-action@v4
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.21'
with:
file: ./coverage.out
flags: unittests
name: codecov-umbrella
sandbox-test:
name: Sandbox Tests (Cross-Platform)
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('test/sandbox/Dockerfile.*') }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build shelldock for linux/amd64
run: |
mkdir -p build
GOOS=linux GOARCH=amd64 go build -o build/shelldock-linux-amd64 .
- name: Build sandbox Docker images
run: |
for platform in ubuntu debian rockylinux fedora archlinux windows; do
echo "Building $platform..."
docker buildx build \
--cache-from type=local,src=/tmp/.buildx-cache \
--cache-to type=local,dest=/tmp/.buildx-cache-new,mode=max \
--load \
-f test/sandbox/Dockerfile.$platform \
-t sandbox-$platform \
.
done
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Run sandbox tests - Ubuntu
run: |
chmod +x test/sandbox/entrypoint.sh
docker run --rm \
-e SHELLDOCK_PLATFORM=ubuntu \
-v ${{ github.workspace }}/repository:/opt/shelldock/repository:ro \
sandbox-ubuntu
- name: Run sandbox tests - Debian
run: |
docker run --rm \
-e SHELLDOCK_PLATFORM=debian \
-v ${{ github.workspace }}/repository:/opt/shelldock/repository:ro \
sandbox-debian
- name: Run sandbox tests - Rocky Linux (CentOS)
run: |
docker run --rm \
-e SHELLDOCK_PLATFORM=centos \
-v ${{ github.workspace }}/repository:/opt/shelldock/repository:ro \
sandbox-rockylinux
- name: Run sandbox tests - Fedora
run: |
docker run --rm \
-e SHELLDOCK_PLATFORM=fedora \
-v ${{ github.workspace }}/repository:/opt/shelldock/repository:ro \
sandbox-fedora
- name: Run sandbox tests - Arch Linux
run: |
docker run --rm \
-e SHELLDOCK_PLATFORM=arch \
-v ${{ github.workspace }}/repository:/opt/shelldock/repository:ro \
sandbox-archlinux
- name: Run sandbox tests - Windows (PowerShell Core)
run: |
docker run --rm \
-e SHELLDOCK_PLATFORM=windows \
-v ${{ github.workspace }}/repository:/opt/shelldock/repository:ro \
sandbox-windows
sandbox-test-darwin:
name: Sandbox Tests (macOS)
runs-on: macos-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Install coreutils (for GNU timeout)
run: brew install coreutils
- name: Build shelldock for darwin
run: |
mkdir -p build
GOARCH=$(uname -m | sed 's/x86_64/amd64/' | sed 's/arm64/arm64/')
go build -o build/shelldock-darwin-${GOARCH} .
echo "SHELLDOCK_BINARY=$(pwd)/build/shelldock-darwin-${GOARCH}" >> $GITHUB_ENV
- name: Run sandbox tests on macOS
run: |
chmod +x test/sandbox/entrypoint.sh
export SHELLDOCK_PLATFORM=darwin
export SHELLDOCK_BINARY=${{ env.SHELLDOCK_BINARY }}
export PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:/usr/local/opt/coreutils/libexec/gnubin:$PATH"
./test/sandbox/entrypoint.sh
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.21'
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: latest
args: --timeout=5m
build:
name: Build
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
goos: [linux, darwin, windows]
goarch: [amd64, arm64]
exclude:
- os: ubuntu-latest
goos: darwin
- os: ubuntu-latest
goos: windows
- os: macos-latest
goos: linux
- os: macos-latest
goos: windows
- os: windows-latest
goos: linux
- os: windows-latest
goos: darwin
- os: ubuntu-latest
goarch: arm64
goos: windows
- os: macos-latest
goarch: arm64
goos: windows
- os: windows-latest
goarch: arm64
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Build (Linux/macOS)
if: matrix.os != 'windows-latest'
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
go build -o shelldock-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goos == 'windows' && '.exe' || '' }} .
- name: Install goversioninfo (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo@latest
- name: Build (Windows)
if: matrix.os == 'windows-latest'
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
shell: pwsh
run: |
.\scripts\build-windows.ps1 -Version "0.0.0-test" -OutputName "shelldock-${{ matrix.goos }}-${{ matrix.goarch }}.exe"
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: build-${{ matrix.goos }}-${{ matrix.goarch }}
path: shelldock-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goos == 'windows' && '.exe' || '' }}
install-test:
name: Install and Test (${{ matrix.os }})
needs: build
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
goos: linux
binary_name: shelldock-linux-amd64
artifact_name: build-linux-amd64
install_path: /usr/local/bin/shelldock
- os: macos-latest
goos: darwin
binary_name: shelldock-darwin-amd64
artifact_name: build-darwin-amd64
install_path: /usr/local/bin/shelldock
- os: windows-latest
goos: windows
binary_name: shelldock-windows-amd64.exe
artifact_name: build-windows-amd64
install_path: C:\Program Files\shelldock\shelldock.exe
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download binary artifact
uses: actions/download-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: ./build
- name: List downloaded files (Linux/macOS)
if: matrix.os != 'windows-latest'
run: |
ls -la ./build/
- name: List downloaded files (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
Get-ChildItem -Path ./build -Recurse
- name: Install ShellDock (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
sudo mkdir -p /usr/local/bin
# Find the binary file (artifact may have different structure)
BINARY=$(find ./build -name "${{ matrix.binary_name }}" -o -name "shelldock-*" | head -n 1)
if [ -z "$BINARY" ]; then
echo "❌ Binary not found in build directory"
ls -la ./build/
exit 1
fi
sudo cp "$BINARY" ${{ matrix.install_path }}
sudo chmod +x ${{ matrix.install_path }}
echo "${{ matrix.install_path }}" >> $GITHUB_PATH
echo "✅ Installed from: $BINARY"
- name: Install ShellDock (macOS)
if: matrix.os == 'macos-latest'
run: |
sudo mkdir -p /usr/local/bin
# Find the binary file (artifact may have different structure)
BINARY=$(find ./build -name "${{ matrix.binary_name }}" -o -name "shelldock-*" | head -n 1)
if [ -z "$BINARY" ]; then
echo "❌ Binary not found in build directory"
ls -la ./build/
exit 1
fi
sudo cp "$BINARY" ${{ matrix.install_path }}
sudo chmod +x ${{ matrix.install_path }}
echo "${{ matrix.install_path }}" >> $GITHUB_PATH
echo "✅ Installed from: $BINARY"
- name: Install ShellDock (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
New-Item -ItemType Directory -Path "C:\Program Files\shelldock" -Force
# Find the binary file (artifact may have different structure)
$binary = Get-ChildItem -Path ./build -Recurse -Filter "shelldock*.exe" | Select-Object -First 1
if (-not $binary) {
Write-Error "Binary not found in build directory"
Get-ChildItem -Path ./build -Recurse
exit 1
}
Copy-Item $binary.FullName "${{ matrix.install_path }}"
$env:PATH += ";C:\Program Files\shelldock"
echo "C:\Program Files\shelldock" | Out-File -FilePath $env:GITHUB_PATH -Append
Write-Host "✅ Installed from: $($binary.FullName)"
- name: Verify installation (Linux/macOS)
if: matrix.os != 'windows-latest'
run: |
which shelldock || (echo "shelldock not in PATH" && exit 1)
shelldock --version
echo "✅ Installation verified"
- name: Verify installation (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
if (-not (Get-Command shelldock -ErrorAction SilentlyContinue)) {
Write-Error "shelldock not in PATH"
exit 1
}
shelldock --version
Write-Host "✅ Installation verified"
- name: Test basic commands (Linux/macOS)
if: matrix.os != 'windows-latest'
run: |
echo "Testing shelldock list..."
shelldock list
echo "Testing shelldock show test..."
shelldock show test
echo "✅ Basic commands work"
- name: Test basic commands (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
Write-Host "Testing shelldock list..."
shelldock list
Write-Host "Testing shelldock show test..."
shelldock show test
Write-Host "✅ Basic commands work"
- name: Run test command set (Linux/macOS)
if: matrix.os != 'windows-latest'
run: |
echo "Running shelldock test command set..."
shelldock test --yes
echo "✅ Test command set executed successfully"
- name: Run test command set (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
Write-Host "Running shelldock test command set..."
shelldock test --yes
Write-Host "✅ Test command set executed successfully"
- name: Test version flag
if: matrix.os != 'windows-latest'
run: |
VERSION=$(shelldock --version)
if [ -z "$VERSION" ]; then
echo "❌ Version command failed"
exit 1
fi
echo "✅ Version: $VERSION"
- name: Test version flag (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
$version = shelldock --version
if ([string]::IsNullOrEmpty($version)) {
Write-Error "Version command failed"
exit 1
}
Write-Host "✅ Version: $version"
- name: Test help command
if: matrix.os != 'windows-latest'
run: |
shelldock --help | head -n 5
echo "✅ Help command works"
- name: Test help command (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
shelldock --help | Select-Object -First 5
Write-Host "✅ Help command works"