Skip to content

Commit b0294c5

Browse files
grdsdevclaude
andcommitted
ci: create reusable workflow and refactor package tests (Phase 3)
Major refactoring to reduce duplication and improve maintainability: - Create reusable workflow template (.github/workflows/dart-package-test.yml) - Supports both Docker and non-Docker packages - Handles test concurrency configuration - Includes Docker cleanup with always() condition - Supports melos --no-flutter flag - Refactor 7 package workflows to use reusable template: - functions_client.yml - gotrue.yml (with Docker) - postgrest.yml (with Docker) - realtime_client.yml - storage_client.yml (with Docker) - supabase.yml - yet_another_json_isolate.yml - Add test:coverage script to melos.yaml for running tests with coverage Benefits: - Reduces workflow code by ~80% (from ~80 lines to ~30 lines per workflow) - Centralizes workflow logic for easier maintenance - Ensures consistent behavior across all packages - Docker cleanup now guaranteed with always() condition - Easier to add new packages with consistent testing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent fb41fc5 commit b0294c5

File tree

9 files changed

+175
-412
lines changed

9 files changed

+175
-412
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Dart Package Test (Reusable)
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
package-name:
7+
required: true
8+
type: string
9+
description: 'The name of the package to test (e.g., gotrue, postgrest)'
10+
working-directory:
11+
required: true
12+
type: string
13+
description: 'The working directory for the package (e.g., packages/gotrue)'
14+
needs-docker:
15+
required: false
16+
type: boolean
17+
default: false
18+
description: 'Whether this package needs Docker services to run tests'
19+
docker-compose-dir:
20+
required: false
21+
type: string
22+
description: 'The directory containing docker-compose.yml (e.g., infra/gotrue)'
23+
test-concurrency:
24+
required: false
25+
type: number
26+
default: 0
27+
description: 'Test concurrency level (0 means no flag, 1 means --concurrency=1)'
28+
melos-no-flutter:
29+
required: false
30+
type: boolean
31+
default: false
32+
description: 'Whether to use --no-flutter flag with melos bootstrap'
33+
34+
jobs:
35+
test:
36+
name: Test SDK ${{ matrix.sdk }}
37+
timeout-minutes: 20
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
os: [ubuntu-latest]
42+
sdk: [stable, beta, dev]
43+
44+
defaults:
45+
run:
46+
working-directory: ${{ inputs.working-directory }}
47+
48+
runs-on: ${{ matrix.os }}
49+
50+
steps:
51+
- name: Checkout repository
52+
uses: actions/checkout@v4
53+
54+
- name: Setup Dart
55+
uses: dart-lang/setup-dart@v1
56+
with:
57+
sdk: ${{ matrix.sdk }}
58+
59+
- name: Cache pub dependencies
60+
uses: actions/cache@v4
61+
with:
62+
path: |
63+
${{ env.PUB_CACHE }}
64+
~/.pub-cache
65+
key: ${{ runner.os }}-pub-${{ matrix.sdk }}-${{ hashFiles('**/pubspec.lock') }}
66+
restore-keys: |
67+
${{ runner.os }}-pub-${{ matrix.sdk }}-
68+
${{ runner.os }}-pub-
69+
70+
- name: Bootstrap workspace
71+
run: |
72+
cd ../../
73+
dart pub global activate melos
74+
if [ "${{ inputs.melos-no-flutter }}" == "true" ]; then
75+
melos bootstrap --no-flutter
76+
else
77+
melos bootstrap
78+
fi
79+
80+
- name: dartfmt
81+
if: ${{ matrix.sdk == 'stable'}}
82+
run: dart format lib test -l 80 --set-exit-if-changed
83+
84+
- name: analyzer
85+
run: |
86+
if [ "${{ matrix.sdk }}" == "stable" ]; then
87+
dart analyze --fatal-warnings .
88+
else
89+
dart analyze
90+
fi
91+
92+
- name: Start Docker services
93+
if: ${{ inputs.needs-docker }}
94+
run: |
95+
cd ../../${{ inputs.docker-compose-dir }}
96+
docker compose up -d
97+
98+
- name: Wait for services to be ready
99+
if: ${{ inputs.needs-docker }}
100+
run: sleep 5
101+
102+
- name: Run tests
103+
run: |
104+
if [ "${{ inputs.test-concurrency }}" == "1" ]; then
105+
dart test --concurrency=1
106+
else
107+
dart test
108+
fi
109+
110+
- name: Stop Docker services
111+
if: ${{ inputs.needs-docker && always() }}
112+
run: |
113+
cd ../../${{ inputs.docker-compose-dir }}
114+
docker compose down

.github/workflows/functions_client.yml

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ on:
77
paths:
88
- 'packages/functions_client/**'
99
- '.github/workflows/functions_client.yml'
10+
- '.github/workflows/dart-package-test.yml'
1011
- 'packages/yet_another_json_isolate/**'
1112

1213
pull_request:
1314
paths:
1415
- 'packages/functions_client/**'
1516
- '.github/workflows/functions_client.yml'
17+
- '.github/workflows/dart-package-test.yml'
1618
- 'packages/yet_another_json_isolate/**'
1719

1820
concurrency:
@@ -24,58 +26,8 @@ permissions:
2426

2527
jobs:
2628
test:
27-
name: Test SDK ${{ matrix.sdk }}
28-
timeout-minutes: 20
29-
30-
strategy:
31-
fail-fast: false
32-
matrix:
33-
os: [ubuntu-latest]
34-
sdk: [stable, beta, dev]
35-
36-
defaults:
37-
run:
38-
working-directory: packages/functions_client
39-
40-
runs-on: ${{ matrix.os }}
41-
42-
steps:
43-
- name: Checks-out repo
44-
uses: actions/checkout@v4
45-
46-
- name: Setup Dart
47-
uses: dart-lang/setup-dart@v1
48-
with:
49-
sdk: ${{ matrix.sdk }}
50-
51-
- name: Cache pub dependencies
52-
uses: actions/cache@v4
53-
with:
54-
path: |
55-
${{ env.PUB_CACHE }}
56-
~/.pub-cache
57-
key: ${{ runner.os }}-pub-${{ matrix.sdk }}-${{ hashFiles('**/pubspec.lock') }}
58-
restore-keys: |
59-
${{ runner.os }}-pub-${{ matrix.sdk }}-
60-
${{ runner.os }}-pub-
61-
62-
- name: Bootstrap workspace
63-
run: |
64-
cd ../../
65-
dart pub global activate melos
66-
melos bootstrap --no-flutter
67-
68-
- name: dartfmt
69-
if: ${{ matrix.sdk == 'stable'}}
70-
run: dart format lib test -l 80 --set-exit-if-changed
71-
72-
- name: analyzer
73-
run: |
74-
if [ "${{ matrix.sdk }}" == "stable" ]; then
75-
dart analyze --fatal-warnings .
76-
else
77-
dart analyze
78-
fi
79-
80-
- name: Run tests
81-
run: dart test
29+
uses: ./.github/workflows/dart-package-test.yml
30+
with:
31+
package-name: functions_client
32+
working-directory: packages/functions_client
33+
melos-no-flutter: true

.github/workflows/gotrue.yml

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ on:
77
paths:
88
- 'packages/gotrue/**'
99
- '.github/workflows/gotrue.yml'
10+
- '.github/workflows/dart-package-test.yml'
1011

1112
pull_request:
1213
paths:
1314
- 'packages/gotrue/**'
1415
- '.github/workflows/gotrue.yml'
16+
- '.github/workflows/dart-package-test.yml'
1517

1618
concurrency:
1719
group: ${{ github.workflow }}-${{ github.ref }}
@@ -22,66 +24,10 @@ permissions:
2224

2325
jobs:
2426
test:
25-
name: Test SDK ${{ matrix.sdk }}
26-
timeout-minutes: 20
27-
strategy:
28-
fail-fast: false
29-
matrix:
30-
os: [ubuntu-latest]
31-
sdk: [stable, beta, dev]
32-
33-
defaults:
34-
run:
35-
working-directory: packages/gotrue
36-
37-
runs-on: ${{ matrix.os }}
38-
39-
steps:
40-
- name: Checks-out repo
41-
uses: actions/checkout@v4
42-
43-
- name: Setup Dart
44-
uses: dart-lang/setup-dart@v1
45-
with:
46-
sdk: ${{ matrix.sdk }}
47-
48-
- name: Cache pub dependencies
49-
uses: actions/cache@v4
50-
with:
51-
path: |
52-
${{ env.PUB_CACHE }}
53-
~/.pub-cache
54-
key: ${{ runner.os }}-pub-${{ matrix.sdk }}-${{ hashFiles('**/pubspec.lock') }}
55-
restore-keys: |
56-
${{ runner.os }}-pub-${{ matrix.sdk }}-
57-
${{ runner.os }}-pub-
58-
59-
- name: Bootstrap workspace
60-
run: |
61-
cd ../../
62-
dart pub global activate melos
63-
melos bootstrap --no-flutter
64-
65-
- name: dartfmt
66-
if: ${{ matrix.sdk == 'stable'}}
67-
run: dart format lib test -l 80 --set-exit-if-changed
68-
69-
- name: analyzer
70-
run: |
71-
if [ "${{ matrix.sdk }}" == "stable" ]; then
72-
dart analyze --fatal-warnings .
73-
else
74-
dart analyze
75-
fi
76-
77-
- name: Build Docker image
78-
run: |
79-
cd ../../infra/gotrue
80-
docker compose down
81-
docker compose up -d
82-
83-
- name: Wait for services to be ready
84-
run: sleep 5
85-
86-
- name: Run tests
87-
run: dart test --concurrency=1
27+
uses: ./.github/workflows/dart-package-test.yml
28+
with:
29+
package-name: gotrue
30+
working-directory: packages/gotrue
31+
needs-docker: true
32+
docker-compose-dir: infra/gotrue
33+
test-concurrency: 1

.github/workflows/postgrest.yml

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ on:
77
paths:
88
- 'packages/postgrest/**'
99
- '.github/workflows/postgrest.yml'
10+
- '.github/workflows/dart-package-test.yml'
1011
- 'packages/yet_another_json_isolate/**'
1112

1213
pull_request:
1314
paths:
1415
- 'packages/postgrest/**'
1516
- '.github/workflows/postgrest.yml'
17+
- '.github/workflows/dart-package-test.yml'
1618
- 'packages/yet_another_json_isolate/**'
1719

1820
concurrency:
@@ -24,66 +26,11 @@ permissions:
2426

2527
jobs:
2628
test:
27-
name: Test SDK ${{ matrix.sdk }}
28-
timeout-minutes: 20
29-
strategy:
30-
fail-fast: false
31-
matrix:
32-
os: [ubuntu-latest]
33-
sdk: [stable, beta, dev]
34-
35-
defaults:
36-
run:
37-
working-directory: packages/postgrest
38-
39-
runs-on: ${{ matrix.os }}
40-
41-
steps:
42-
- name: Checks-out repo
43-
uses: actions/checkout@v4
44-
45-
- name: Setup Dart
46-
uses: dart-lang/setup-dart@v1
47-
with:
48-
sdk: ${{ matrix.sdk }}
49-
50-
- name: Cache pub dependencies
51-
uses: actions/cache@v4
52-
with:
53-
path: |
54-
${{ env.PUB_CACHE }}
55-
~/.pub-cache
56-
key: ${{ runner.os }}-pub-${{ matrix.sdk }}-${{ hashFiles('**/pubspec.lock') }}
57-
restore-keys: |
58-
${{ runner.os }}-pub-${{ matrix.sdk }}-
59-
${{ runner.os }}-pub-
60-
61-
- name: Bootstrap workspace
62-
run: |
63-
cd ../../
64-
dart pub global activate melos
65-
melos bootstrap --no-flutter
66-
67-
- name: dartfmt
68-
if: ${{ matrix.sdk == 'stable'}}
69-
run: dart format lib test -l 80 --set-exit-if-changed
70-
71-
- name: analyzer
72-
run: |
73-
if [ "${{ matrix.sdk }}" == "stable" ]; then
74-
dart analyze --fatal-warnings .
75-
else
76-
dart analyze
77-
fi
78-
79-
- name: Build Docker image
80-
run: |
81-
cd ../../infra/postgrest
82-
docker compose down
83-
docker compose up -d
84-
85-
- name: Wait for services to be ready
86-
run: sleep 5
87-
88-
- name: Run tests
89-
run: dart test --concurrency=1
29+
uses: ./.github/workflows/dart-package-test.yml
30+
with:
31+
package-name: postgrest
32+
working-directory: packages/postgrest
33+
needs-docker: true
34+
docker-compose-dir: infra/postgrest
35+
test-concurrency: 1
36+
melos-no-flutter: true

0 commit comments

Comments
 (0)