-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (119 loc) · 4.25 KB
/
integration-test.yml
File metadata and controls
134 lines (119 loc) · 4.25 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
name: Integration Test
on:
push:
branches: ["main", "dev"]
pull_request:
branches: ["main", "dev"]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
actions: read
env:
GO_VERSION_LATEST: "1.25"
jobs:
integration-test:
name: Integration Test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' || github.event_name == 'pull_request'
strategy:
matrix:
go-version: ["1.24", "1.25"]
upload_auth: ["true", "false"]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Download dependencies
run: go mod download
- name: Build nclip binary
env:
CGO_ENABLED: 0
run: |
VERSION="test-${GITHUB_SHA:0:7}"
go build -v \
-ldflags="-s -w -X main.version=${VERSION} -X main.buildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ) -X main.gitCommit=${GITHUB_SHA:0:7}" \
-o nclip \
.
chmod +x nclip
- name: Start nclip server (filesystem backend)
env:
NCLIP_PORT: 8080
NCLIP_DATA_DIR: ./data
GIN_MODE: release
run: |
mkdir -p "${NCLIP_DATA_DIR}"
echo "Starting nclip server (filesystem backend only)..."
# When upload_auth is true, the job should set API keys so tests can auth
if [ "${{ matrix.upload_auth }}" = "true" ]; then
TEST_KEY=$(openssl rand -hex 12)
echo "NCLIP_UPLOAD_AUTH=true" >> $GITHUB_ENV
echo "NCLIP_API_KEYS=$TEST_KEY" >> $GITHUB_ENV
echo "NCLIP_TEST_API_KEY=$TEST_KEY" >> $GITHUB_ENV
export NCLIP_UPLOAD_AUTH=true
export NCLIP_API_KEYS=$TEST_KEY
export NCLIP_TEST_API_KEY=$TEST_KEY
echo "Generated test API key for upload auth"
else
echo "NCLIP_UPLOAD_AUTH=false" >> $GITHUB_ENV
export NCLIP_UPLOAD_AUTH=false
fi
# start server with logs redirected and persist pid so later steps can stop it
nohup ./nclip > nclip.log 2>&1 &
echo $! > server.pid
echo "SERVER_PID=$(cat server.pid)" >> $GITHUB_ENV
chmod +r nclip.log || true
echo "nclip started with PID: $(cat server.pid)"
- name: Wait for nclip /health
run: |
set -euo pipefail
URL="http://127.0.0.1:${NCLIP_PORT:-8080}/health"
for i in $(seq 1 60); do
if curl -sSf "$URL" >/dev/null 2>&1; then
echo "nclip ready"
exit 0
fi
echo "waiting for nclip... ($i/60)"
sleep 1
done
echo "nclip did not become ready; printing nclip.log"
sed -n '1,200p' nclip.log || true
exit 1
- name: Run integration tests
env:
NCLIP_URL: http://localhost:8080
NCLIP_UPLOAD_AUTH: ${{ matrix.upload_auth }}
NCLIP_DATA_DIR: ./data
run: |
echo "Running integration tests (upload_auth=${{ matrix.upload_auth }})..."
# Export any NCLIP_* values injected into the environment by the previous step
if [ -n "${NCLIP_API_KEYS:-}" ]; then export NCLIP_API_KEYS="$NCLIP_API_KEYS"; fi
if [ -n "${NCLIP_TEST_API_KEY:-}" ]; then export NCLIP_TEST_API_KEY="$NCLIP_TEST_API_KEY"; fi
# Run unified integration test suite (orchestrates all test scripts)
bash scripts/integration-test.sh
- name: Stop nclip server
if: always()
run: |
if [ -f server.pid ]; then
PID=$(cat server.pid)
echo "Stopping nclip server (PID: $PID)"
kill $PID || true
sleep 2
kill -9 $PID 2>/dev/null || true
fi
- name: Upload integration test artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: integration-test-artifacts-${{ matrix.go-version }}-run${{ github.run_id }}
path: |
nclip
scripts/
nclip.log
server.pid
retention-days: 7