Skip to content

Commit e78ad3b

Browse files
authored
Use musl targets for static Linux binaries (#237)
* Fix #107: Use musl targets for static Linux binaries Change Linux build targets from glibc to musl to produce truly static executables that work on all Linux distributions including NixOS. - i686-unknown-linux-gnu -> i686-unknown-linux-musl - x86_64-unknown-linux-gnu -> x86_64-unknown-linux-musl - aarch64-unknown-linux-gnu -> aarch64-unknown-linux-musl Fixes #107 * Add comprehensive E2E tests across platforms and Linux distros Enhance end-to-end testing with: 1. **Main E2E job**: Test npm package installation on all platforms - Runs on: ubuntu-latest, macos-latest, windows-latest - Tests with Node.js 20 - Full database integration tests on Linux (MySQL 5.6, 5.7, 8 & PostgreSQL 12-16) - Basic installation tests on macOS and Windows - Validates --version and --help commands 2. **E2E Linux distros with databases**: Test npm package across Linux distributions - Ubuntu 20.04, 22.04, 24.04 - Debian 11, 12 - Alpine 3.18, 3.19 (musl-native) - Fedora 38, 39 - Tests with MySQL 8 and PostgreSQL 16 - Installs Node.js in each container - Runs full integration tests with live databases 3. **Static binary Linux distro tests**: Verify musl static binaries work everywhere - Tests on all Linux distros including NixOS (issue #107) - Builds with x86_64-unknown-linux-musl target - Verifies binary is statically linked using ldd - Runs binary in each distro's container Benefits: - Ensures npm package works on all major platforms - Validates static binaries are truly portable - Tests against all supported database versions - Catches platform-specific issues before release - Specifically addresses NixOS compatibility (issue #107) * Fix static binary verification for static-pie binaries The previous check was incorrectly failing on static-pie (Position Independent Executable) binaries. A static-pie binary IS statically linked - it's a modern, more secure form of static linking. Changes: - Fix build command to include --target flag (was missing) - Update verification to accept both 'static' and 'static-pie' - Check file output for 'static' keyword instead of only ldd - Add detailed logging to show both file and ldd output - Accept 'not a dynamic executable' from ldd as valid This fixes the false positive failure in the linux-distro-static-binary-test job that was reporting 'Binary is not static!' for valid static-pie binaries. * add archlinux and nixos in e2e-linux-distros * split out compatibility-tests * update * fix * spelling * simplify node build * rename files * rename * better name * rename * cancel prev build
1 parent 3921c93 commit e78ad3b

File tree

10 files changed

+441
-192
lines changed

10 files changed

+441
-192
lines changed

.github/workflows/auto-merge-dependabot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Dependabot auto-merge
1+
name: auto-merge
22
on: pull_request
33

44
permissions:

.github/workflows/clippy.yaml

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
name: Compatibility tests
2+
3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
push:
9+
branches: [ main ]
10+
workflow_dispatch: { }
11+
schedule:
12+
- cron: "0 0 * * *" # daily at midnight UTC
13+
workflow_run:
14+
workflows: ["Release"]
15+
types:
16+
- completed
17+
18+
jobs:
19+
e2e:
20+
name: E2E tests with Node.js npm package
21+
runs-on: ${{ matrix.os }}
22+
# Skip this job for version bump commits (binary won't exist yet)
23+
if: "!contains(github.event.head_commit.message, 'Release')"
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
os: [ubuntu-latest, macos-latest, windows-latest]
28+
db:
29+
- mysql: 8
30+
- mysql: 5.7
31+
- mysql: 5.6
32+
- postgres: 16
33+
- postgres: 15
34+
- postgres: 14
35+
- postgres: 13
36+
- postgres: 12
37+
# Only run database tests on ubuntu-latest to save CI time
38+
exclude:
39+
- os: macos-latest
40+
db: { mysql: 5.7 }
41+
- os: macos-latest
42+
db: { mysql: 5.6 }
43+
- os: macos-latest
44+
db: { postgres: 15 }
45+
- os: macos-latest
46+
db: { postgres: 14 }
47+
- os: macos-latest
48+
db: { postgres: 13 }
49+
- os: macos-latest
50+
db: { postgres: 12 }
51+
- os: windows-latest
52+
db: { mysql: 5.7 }
53+
- os: windows-latest
54+
db: { mysql: 5.6 }
55+
- os: windows-latest
56+
db: { postgres: 15 }
57+
- os: windows-latest
58+
db: { postgres: 14 }
59+
- os: windows-latest
60+
db: { postgres: 13 }
61+
- os: windows-latest
62+
db: { postgres: 12 }
63+
64+
steps:
65+
- name: Checkout sources
66+
uses: actions/checkout@v3
67+
68+
- name: Setup Node.js 20
69+
uses: actions/setup-node@v3
70+
with:
71+
node-version: '20'
72+
73+
- name: Build docker-compose services for integration tests (Linux only)
74+
if: runner.os == 'Linux'
75+
run: docker compose -f docker-compose.yml up -d
76+
env:
77+
MYSQL_VERSION: ${{ matrix.db.mysql }}
78+
PG_VERSION: ${{ matrix.db.postgres }}
79+
MYSQL_MIGRATION_FILE: "${{ matrix.db.mysql == '5.6' && 'mysql_migration_5_6.sql' || 'mysql_migration.sql' }}"
80+
81+
- name: Wait for databases to be ready (Linux only)
82+
if: runner.os == 'Linux'
83+
uses: GuillaumeFalourd/wait-sleep-action@v1
84+
with:
85+
time: '10'
86+
87+
- name: Check docker-compose services (Linux only)
88+
if: runner.os == 'Linux'
89+
run: docker ps -a
90+
91+
- name: Install sqlx-ts from npm
92+
working-directory: ./node
93+
run: npm install
94+
95+
- name: Verify sqlx-ts installation
96+
working-directory: ./node
97+
shell: bash
98+
run: |
99+
./sqlx-ts --version
100+
./sqlx-ts --help
101+
102+
- name: Create test directory
103+
shell: bash
104+
run: mkdir -p tests/staging
105+
106+
- name: Add failure.ts test file (Linux only)
107+
if: runner.os == 'Linux'
108+
shell: bash
109+
run: |
110+
cat << 'EOF' > tests/staging/failure.ts
111+
import { sql } from 'sqlx-ts'
112+
113+
const selectSql4 = sql`
114+
SELECT itemz.*
115+
FROM items;
116+
`
117+
EOF
118+
119+
- name: Run failure test (Linux only)
120+
if: runner.os == 'Linux'
121+
working-directory: ./node
122+
shell: bash
123+
run: |
124+
set +e
125+
./sqlx-ts --config=../.sqlxrc.sample.json ../tests/staging
126+
EXIT_CODE=$?
127+
if [ $EXIT_CODE -eq 0 ]; then
128+
echo "Expected failure, but command succeeded."
129+
exit 1
130+
fi
131+
echo "Command failed as expected with exit code $EXIT_CODE."
132+
133+
- name: Remove failure test file
134+
if: runner.os == 'Linux'
135+
shell: bash
136+
run: rm -f tests/staging/failure.ts
137+
138+
- name: Add happy.ts test file (Linux only)
139+
if: runner.os == 'Linux'
140+
shell: bash
141+
run: |
142+
cat << 'EOF' > tests/staging/happy.ts
143+
import { sql } from 'sqlx-ts'
144+
145+
const selectSql4 = sql`
146+
SELECT items.*
147+
FROM items;
148+
`
149+
EOF
150+
151+
- name: Run happy test (Linux only)
152+
if: runner.os == 'Linux'
153+
working-directory: ./node
154+
shell: bash
155+
run: ./sqlx-ts --config=../.sqlxrc.sample.json ../tests/staging
156+
157+
- name: Test sqlx-ts on ${{ matrix.os }} (no database)
158+
if: runner.os != 'Linux'
159+
working-directory: ./node
160+
shell: bash
161+
run: |
162+
echo "✅ sqlx-ts successfully installed and runs on ${{ matrix.os }}"
163+
./sqlx-ts --version
164+
./sqlx-ts --help
165+
166+
167+
e2e-linux-distros:
168+
name: E2E npm package on Linux distros with databases
169+
runs-on: ubuntu-latest
170+
# Skip this job for version bump commits (binary won't exist yet)
171+
if: "!contains(github.event.head_commit.message, 'Release')"
172+
strategy:
173+
fail-fast: false
174+
matrix:
175+
distro:
176+
- ubuntu:20.04
177+
- ubuntu:22.04
178+
- ubuntu:24.04
179+
- debian:11
180+
- debian:12
181+
- alpine:3.18
182+
- alpine:3.19
183+
- fedora:38
184+
- fedora:39
185+
- archlinux:latest
186+
db:
187+
- mysql: 8
188+
- postgres: 16
189+
# Test fewer combinations to save CI time
190+
exclude:
191+
- distro: ubuntu:20.04
192+
db: { postgres: 16 }
193+
- distro: ubuntu:22.04
194+
db: { postgres: 16 }
195+
- distro: debian:11
196+
db: { postgres: 16 }
197+
- distro: debian:12
198+
db: { mysql: 8 }
199+
- distro: alpine:3.18
200+
db: { postgres: 16 }
201+
- distro: alpine:3.19
202+
db: { mysql: 8 }
203+
- distro: fedora:38
204+
db: { postgres: 16 }
205+
- distro: fedora:39
206+
db: { mysql: 8 }
207+
208+
steps:
209+
- name: Checkout sources
210+
uses: actions/checkout@v3
211+
212+
- name: Build docker-compose services
213+
run: docker compose -f docker-compose.yml up -d
214+
env:
215+
MYSQL_VERSION: ${{ matrix.db.mysql }}
216+
PG_VERSION: ${{ matrix.db.postgres }}
217+
MYSQL_MIGRATION_FILE: "${{ matrix.db.mysql == '5.6' && 'mysql_migration_5_6.sql' || 'mysql_migration.sql' }}"
218+
219+
- name: Wait for databases to be ready
220+
uses: GuillaumeFalourd/wait-sleep-action@v1
221+
with:
222+
time: '10'
223+
224+
- name: Create test file
225+
run: |
226+
mkdir -p tests/staging
227+
cat << 'TESTEOF' > tests/staging/distro-test.ts
228+
import { sql } from 'sqlx-ts'
229+
230+
const selectSql = sql`
231+
SELECT items.*
232+
FROM items;
233+
`
234+
TESTEOF
235+
236+
- name: Test npm install and run in ${{ matrix.distro }} container
237+
run: |
238+
docker run --rm \
239+
--network host \
240+
-v $(pwd):/workspace \
241+
-w /workspace \
242+
${{ matrix.distro }} sh -c '
243+
# Install Node.js based on distro
244+
if command -v apk > /dev/null; then
245+
# Alpine
246+
apk add --no-cache nodejs npm bash
247+
elif command -v apt-get > /dev/null; then
248+
# Debian/Ubuntu
249+
apt-get update && apt-get install -y curl
250+
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
251+
apt-get install -y nodejs
252+
elif command -v dnf > /dev/null; then
253+
# Fedora
254+
dnf install -y nodejs npm
255+
fi
256+
257+
# Install sqlx-ts
258+
cd node
259+
npm install
260+
261+
# Verify installation
262+
./sqlx-ts --version
263+
./sqlx-ts --help
264+
265+
# Run integration test
266+
./sqlx-ts --config=../.sqlxrc.sample.json ../tests/staging
267+
268+
echo "✅ sqlx-ts npm package works on ${{ matrix.distro }} with DB"
269+
'

.github/workflows/coverage.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: coverage
22

3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref }}
5+
cancel-in-progress: true
6+
37
on:
48
schedule:
59
- cron: '0 1 * * *'

.github/workflows/deploy-gh-pages.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy docs/install-script to gh-pages branch for public use
1+
name: gh-pages
22
on:
33
push:
44
branches: [main]

0 commit comments

Comments
 (0)