Skip to content

Commit 52844d7

Browse files
committed
ci(mysql): add @emigrate/mysql integration tests to GitHub Actions
1 parent fa3fb20 commit 52844d7

File tree

6 files changed

+84
-27
lines changed

6 files changed

+84
-27
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,6 @@ jobs:
1515
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
1616
DO_NOT_TRACK: 1
1717

18-
services:
19-
mysql:
20-
image: mysql:8.0
21-
env:
22-
MYSQL_ROOT_PASSWORD: root
23-
MYSQL_DATABASE: emigrate
24-
MYSQL_USER: emigrate
25-
MYSQL_PASSWORD: emigrate
26-
ports:
27-
- 3306:3306
28-
options: --health-cmd="mysqladmin ping -h localhost" --health-interval=10s --health-timeout=5s --health-retries=5
29-
3018
steps:
3119
- name: Check out code
3220
uses: actions/checkout@v4
@@ -44,16 +32,5 @@ jobs:
4432
- name: Install dependencies
4533
run: pnpm install
4634

47-
- name: Wait for MySQL to be ready
48-
run: |
49-
for i in {1..30}; do
50-
nc -z localhost 3306 && echo "MySQL is up!" && break
51-
echo "Waiting for MySQL..."
52-
sleep 2
53-
done
54-
5535
- name: Checks
56-
env:
57-
MYSQL_HOST: localhost
58-
MYSQL_PORT: 3306
5936
run: pnpm checks

.github/workflows/integration.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Integration Tests
2+
3+
on:
4+
push:
5+
branches: ['main', 'changeset-release/main']
6+
pull_request:
7+
8+
jobs:
9+
mysql_integration:
10+
name: Emigrate MySQL integration tests
11+
timeout-minutes: 15
12+
runs-on: ubuntu-latest
13+
env:
14+
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
15+
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
16+
DO_NOT_TRACK: 1
17+
18+
services:
19+
mysql:
20+
image: mysql:8.0
21+
env:
22+
MYSQL_ROOT_PASSWORD: root
23+
MYSQL_DATABASE: emigrate
24+
MYSQL_USER: emigrate
25+
MYSQL_PASSWORD: emigrate
26+
ports:
27+
- 3306:3306
28+
options: --health-cmd="mysqladmin ping -h localhost" --health-interval=10s --health-timeout=5s --health-retries=5
29+
30+
steps:
31+
- name: Check out code
32+
uses: actions/checkout@v4
33+
with:
34+
fetch-depth: 2
35+
36+
- uses: pnpm/action-setup@v4.0.0
37+
38+
- name: Setup Node.js environment
39+
uses: actions/setup-node@v4
40+
with:
41+
node-version: 22.15.0
42+
cache: 'pnpm'
43+
44+
- name: Install dependencies
45+
run: pnpm install
46+
47+
- name: Wait for MySQL to be ready
48+
run: |
49+
for i in {1..30}; do
50+
nc -z localhost 3306 && echo "MySQL is up!" && break
51+
echo "Waiting for MySQL..."
52+
sleep 2
53+
done
54+
55+
- name: Build package
56+
run: pnpm build --filter @emigrate/mysql
57+
58+
- name: Integration Tests
59+
env:
60+
MYSQL_HOST: '127.0.0.1'
61+
MYSQL_PORT: 3306
62+
run: pnpm --filter @emigrate/mysql integration

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@
6262
},
6363
"overrides": [
6464
{
65-
"files": "packages/**/*.test.ts",
65+
"files": [
66+
"packages/**/*.test.ts",
67+
"packages/**/*.integration.ts"
68+
],
6669
"rules": {
6770
"@typescript-eslint/no-floating-promises": 0,
6871
"max-params": 0

packages/mysql/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"build": "tsc --pretty",
2626
"build:watch": "tsc --pretty --watch",
2727
"lint": "xo --cwd=../.. $(pwd)",
28-
"test-disabled": "glob -c \"node --import tsx --test-reporter spec --test\" \"./src/**/*.test.ts\"",
29-
"test:watch": "glob -c \"node --watch --import tsx --test-reporter spec --test\" \"./src/**/*.test.ts\""
28+
"integration": "glob -c \"node --import tsx --test-reporter spec --test\" \"./src/**/*.integration.ts\"",
29+
"integration:watch": "glob -c \"node --watch --import tsx --test-reporter spec --test\" \"./src/**/*.integration.ts\""
3030
},
3131
"keywords": [
3232
"emigrate",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { createMysqlStorage } from './index.js';
77

88
let db: { port: number; host: string };
99

10+
const toEnd = new Set<{ end: () => Promise<void> }>();
11+
1012
describe('emigrate-mysql', async () => {
1113
before(
1214
async () => {
@@ -17,6 +19,12 @@ describe('emigrate-mysql', async () => {
1719

1820
after(
1921
async () => {
22+
for (const storage of toEnd) {
23+
// eslint-disable-next-line no-await-in-loop
24+
await storage.end();
25+
}
26+
27+
toEnd.clear();
2028
await stopDatabase();
2129
},
2230
{ timeout: 10_000 },
@@ -37,6 +45,9 @@ describe('emigrate-mysql', async () => {
3745

3846
const [storage1, storage2] = await Promise.all([initializeStorage(), initializeStorage()]);
3947

48+
toEnd.add(storage1);
49+
toEnd.add(storage2);
50+
4051
const migrations = toMigrations('/emigrate', 'migrations', [
4152
'2023-10-01-01-test.js',
4253
'2023-10-01-02-test.js',

packages/mysql/src/tests/database.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ let container: StartedTestContainer | undefined;
66

77
export const startDatabase = async (): Promise<{ port: number; host: string }> => {
88
if (process.env['CI']) {
9-
return {
9+
const config = {
1010
port: process.env['MYSQL_PORT'] ? Number.parseInt(process.env['MYSQL_PORT'], 10) : 3306,
1111
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
1212
host: process.env['MYSQL_HOST'] || 'localhost',
1313
};
14+
15+
console.log(`Connecting to MySQL from environment variables: ${JSON.stringify(config)}`);
16+
17+
return config;
1418
}
1519

1620
if (!container) {

0 commit comments

Comments
 (0)