Skip to content

Commit

Permalink
chore: Generate coverage reports and upload them. (#1110)
Browse files Browse the repository at this point in the history
* chore: Update CI to generate coverage report.

* chore: Upload coverage results

* removed unneccessary code

* update command name

* test command

* verify melos path

* Update workflow to format and upload the report

* fix functions ci

* update path of functionc ci

* fix path for all ci

* fix: Update type for customAccessToken

* set concurrency to 1 for realtime tests

* fix: failing realtime tests

* add stub to realtime

* more stubs

* update analyzer check in ci

* Run tests on every PR for every packages and upload combined coverage report

* Let the coverage workflow take care of everything about test coverage

* update coverage workflow to setup test infra

* add sleep after docker compose up

* move the sleep

* take down docker after testing

* go back to the infra directory for taking down docker

* revert changes on the individual CI files

* Properly upload code coverage to coverall
  • Loading branch information
dshukertjr authored Jan 30, 2025
1 parent d04d9e6 commit 6976fae
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 5 deletions.
96 changes: 96 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Combined Coverage Report

on:
push:
branches:
- main
pull_request:

jobs:
coverage:
name: Generate Combined Coverage
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: subosito/flutter-action@v2
with:
flutter-version: '3.x'
channel: 'stable'

- name: Install dependencies
run: |
dart pub global activate melos
dart pub global activate coverage
dart pub global activate combine_coverage
melos bootstrap
- name: Run tests with coverage for all packages
run: |
# Create directory for combined coverage
mkdir coverage
# Run tests for each package and generate coverage
cd packages
for d in */ ; do
cd "$d"
if [ -f "pubspec.yaml" ]; then
echo "Running tests for $d"
if [[ "$d" == "supabase_flutter/"* ]]; then
flutter test --coverage --concurrency=1
else
# Set up Docker containers based on package
if [[ "$d" == "postgrest/"* ]]; then
cd ../../infra/postgrest
docker compose down
docker compose up -d
cd ../../packages/postgrest
dart test --coverage=coverage --concurrency=1
dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o coverage/lcov.info -i coverage
cd ../../infra/postgrest
docker compose down
sleep 5s
cd ../../packages/postgrest
elif [[ "$d" == "gotrue/"* ]]; then
cd ../../infra/gotrue
docker compose down
docker compose up -d
cd ../../packages/gotrue
dart test --coverage=coverage --concurrency=1
dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o coverage/lcov.info -i coverage
cd ../../infra/gotrue
docker compose down
sleep 5s
cd ../../packages/gotrue
elif [[ "$d" == "storage_client/"* ]]; then
cd ../../infra/storage_client
docker compose down
docker compose up -d
cd ../../packages/storage_client
dart test --coverage=coverage --concurrency=1
dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o coverage/lcov.info -i coverage
cd ../../infra/storage_client
docker compose down
sleep 5s
cd ../../packages/storage_client
else
cd ../../packages/$d
dart test --coverage=coverage --concurrency=1
dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o coverage/lcov.info -i coverage
fi
fi
fi
cd ..
done
cd ..
- name: Combine coverage reports
run: |
dart pub global run combine_coverage:combine_coverage --repo-path="./" --output-directory="coverage"
- name: Upload combined coverage report
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./coverage/lcov.info
5 changes: 5 additions & 0 deletions .github/workflows/functions_client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ jobs:
run: dart format lib test -l 80 --set-exit-if-changed

- name: analyzer
if: ${{ matrix.sdk == 'stable'}}
run: dart analyze --fatal-warnings --fatal-infos .

- name: analyzer
if: ${{ matrix.sdk == 'beta' || matrix.sdk == 'dev' }}
run: dart analyze

- name: Run tests
run: dart test
5 changes: 5 additions & 0 deletions .github/workflows/gotrue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ jobs:
run: dart format lib test -l 80 --set-exit-if-changed

- name: analyzer
if: ${{ matrix.sdk == 'stable'}}
run: dart analyze --fatal-warnings --fatal-infos .

- name: analyzer
if: ${{ matrix.sdk == 'beta' || matrix.sdk == 'dev' }}
run: dart analyze

- name: Build Docker image
run: |
cd ../../infra/gotrue
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/postgrest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ jobs:
run: dart format lib test -l 80 --set-exit-if-changed

- name: analyzer
if: ${{ matrix.sdk == 'stable'}}
run: dart analyze --fatal-warnings --fatal-infos .

- name: analyzer
if: ${{ matrix.sdk == 'beta' || matrix.sdk == 'dev' }}
run: dart analyze

- name: Build Docker image
run: |
cd ../../infra/postgrest
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/realtime_client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ jobs:
run: dart format lib test -l 80 --set-exit-if-changed

- name: analyzer
if: ${{ matrix.sdk == 'stable'}}
run: dart analyze --fatal-warnings --fatal-infos .

- name: analyzer
if: ${{ matrix.sdk == 'beta' || matrix.sdk == 'dev' }}
run: dart analyze

- name: Run tests
run: dart test
run: dart test --concurrency=1
5 changes: 5 additions & 0 deletions .github/workflows/storage_client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ jobs:
run: dart format lib test -l 80 --set-exit-if-changed

- name: analyzer
if: ${{ matrix.sdk == 'stable'}}
run: dart analyze --fatal-warnings --fatal-infos .

- name: analyzer
if: ${{ matrix.sdk == 'beta' || matrix.sdk == 'dev' }}
run: dart analyze

- name: Build Docker image
run: |
cd ../../infra/storage_client
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/supabase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ jobs:
run: dart format lib test -l 80 --set-exit-if-changed

- name: analyzer
if: ${{ matrix.sdk == 'stable'}}
run: dart analyze --fatal-warnings --fatal-infos .

- name: analyzer
if: ${{ matrix.sdk == 'beta' || matrix.sdk == 'dev' }}
run: dart analyze

- name: Run tests
run: dart test --concurrency=1
2 changes: 1 addition & 1 deletion .github/workflows/supabase_flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ jobs:
- name: Verify if Flutter web build is successful
run: |
cd example
flutter build web
flutter build web
5 changes: 5 additions & 0 deletions .github/workflows/yet_another_json_isolate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ jobs:
run: dart format lib test -l 80 --set-exit-if-changed

- name: analyzer
if: ${{ matrix.sdk == 'stable'}}
run: dart analyze --fatal-warnings --fatal-infos .

- name: analyzer
if: ${{ matrix.sdk == 'beta' || matrix.sdk == 'dev' }}
run: dart analyze

- name: Run tests
run: dart test
3 changes: 2 additions & 1 deletion melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ scripts:
exec: dart pub outdated

update-version:
description: Updates the version.dart file for each packages except yet_another_json_isolate
run: |
# Loop through the packages directory
for d in packages/*/ ; do
Expand All @@ -53,4 +54,4 @@ scripts:
rm packages/yet_another_json_isolate/lib/src/version.dart
# Stage the version.dart file change
git add packages/*/lib/src/version.dart
description: Updates the version.dart file for each packages except yet_another_json_isolate
2 changes: 1 addition & 1 deletion packages/realtime_client/lib/src/realtime_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class RealtimeClient {
int longpollerTimeout = 20000;
SocketStates? connState;
// This is called `accessToken` in realtime-js
Future<String> Function()? customAccessToken;
Future<String?> Function()? customAccessToken;

/// Initializes the Socket
///
Expand Down
6 changes: 5 additions & 1 deletion packages/realtime_client/test/socket_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ void main() {
mockedSink = MockWebSocketSink();

when(() => mockedSocketChannel.sink).thenReturn(mockedSink);
when(() => mockedSocketChannel.ready).thenAnswer((_) => Future.value());
when(() => mockedSink.close()).thenAnswer((_) => Future.value());
});

test('sends data to connection when connected', () {
Expand All @@ -407,7 +409,7 @@ void main() {
.called(1);
});

test('buffers data when not connected', () {
test('buffers data when not connected', () async {
mockedSocket.connect();
mockedSocket.connState = SocketStates.connecting;

Expand Down Expand Up @@ -575,6 +577,8 @@ void main() {
mockedSink = MockWebSocketSink();

when(() => mockedSocketChannel.sink).thenReturn(mockedSink);
when(() => mockedSink.close()).thenAnswer((_) => Future.value());
when(() => mockedSocketChannel.ready).thenAnswer((_) => Future.value());

mockedSocket.connect();
});
Expand Down

0 comments on commit 6976fae

Please sign in to comment.