Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: integrate github actions and setup melos #328

Merged
merged 6 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/all_packages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: all_packages

on:
push:
ahrar-deriv marked this conversation as resolved.
Show resolved Hide resolved
branches:
- master
- dev
pull_request:
branches:
- "*"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
analyze_and_test:
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v4

- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: "stable"
flutter-version: "3.10.2"
cache: true

- name: Set SSH Key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{secrets.SSH_PRIVATE_KEY}}

- name: Install Melos and run pub get
sagar-deriv marked this conversation as resolved.
Show resolved Hide resolved
uses: bluefireteam/melos-action@v1
with:
melos-version: "3.0.1"

- name: Run Analyze
run: melos run analyze

- name: Run Test
run: melos run test --no-select
19 changes: 19 additions & 0 deletions .github/workflows/pr_title.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: pr_title

on:
pull_request_target:
types:
- opened
- edited
- synchronize

permissions:
pull-requests: read

jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,40 @@ This repository contains private packages & plugins that are used by the company
| [form_builder](./packages/form_builder) | A simpler and cleaner way to create, validate and submit forms. |
| [update_checker](./packages/update_checker) | Check and retrieve update information from the server for the given package. |

## Environment Setup

We use [Melos](https://pub.dev/packages/melos) to manage the multiple packages in this repository. To get started, install Melos globally:

```bash
$ dart pub global activate melos
```

Running `pub get` on all packages, run:

```bash
$ melos bootstrap
```

`Analyze` and `Test` has already been configured in `melos.yaml` so you can do the following:

<b>Running `flutter analyze` on all packages:</b>

```bash
$ melos run analyze
```

<b>Running `flutter test` on all packages: </b>

```bash
$ melos run test --no-select
```

If you'd like to run any other command on all packages, you can configure it in `melos.yaml` or run it directly with melos:

```bash
$ melos exec --\
your command here
```



42 changes: 42 additions & 0 deletions melos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: flutter_deriv_packages
repository: https://github.com/regentmarkets/flutter-deriv-packages

packages:
- packages/*

command:
version:
# Generate commit links in package changelogs.
linkToCommits: true
workspaceChangelog: true
updateGitTagRefs: true

bootstrap:
# It seems so that running "pub get" in parallel has some issues (like
# https://github.com/dart-lang/pub/issues/3404). Disabling this feature
# makes the CI much more stable.
runPubGetInParallel: false

scripts:
analyze:
name: Flutter Analyze
description: Run flutter analyze for all packages.
## Only fail if there are errors or warnings and not on infos.
run: |
if flutter analyze 2>&1 | grep -q -E 'error:|warning:';
then exit 1
else exit 0
fi
exec:
concurrency: 1
failFast: true

test:
name: Flutter Test
description: Run flutter test for all packages.
run: flutter test --coverage
exec:
failFast: true
packageFilters:
dirExists:
- test
2 changes: 1 addition & 1 deletion packages/deriv_auth_ui/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:
git:
url: [email protected]:regentmarkets/flutter-deriv-packages.git
path: packages/deriv_auth
ref: d5bef178341a318f911b42b8105d8c3d50c6b63e
ref: dev
deriv_theme:
path: ../../deriv_theme
# git:
Expand Down
4 changes: 2 additions & 2 deletions packages/deriv_auth_ui/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:
git:
url: [email protected]:regentmarkets/flutter-deriv-packages.git
path: packages/deriv_auth
ref: d5bef178341a318f911b42b8105d8c3d50c6b63e
ref: dev
deriv_theme:
path: ../deriv_theme
# git:
Expand All @@ -40,7 +40,7 @@ dev_dependencies:
sdk: flutter
flutter_lints: ^2.0.0
mocktail: ^0.3.0
patrol: ^1.1.4
patrol_finders: ^1.0.0
bloc_test: ^9.1.3

flutter_intl:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import 'package:deriv_auth_ui/deriv_auth_ui.dart';
import 'package:deriv_ui/presentation/widgets/fullscreen_message.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:patrol/patrol.dart';

import 'package:patrol_finders/patrol_finders.dart';
import '../../base_test_app.dart';

void main() {
patrolTest('DerivUnavailableCountryLayout', (PatrolTester $) async {
patrolWidgetTest('DerivUnavailableCountryLayout', (PatrolTester $) async {
await $.pumpWidgetAndSettle(BaseTestApp(
child: DerivUnavailableCountryLayout(
userAgent: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import 'package:deriv_ui/deriv_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:patrol/patrol.dart';

import 'package:patrol_finders/patrol_finders.dart';
import '../../../pump_app.dart';

class MockDerivGetStartedSlideModel extends Mock
Expand All @@ -26,7 +25,8 @@ void main() {
when(() => mockSlideModel.supportingText).thenReturn('Supporting text');
});

patrolTest('should render DerivGetStartedLayout', (PatrolTester $) async {
patrolWidgetTest('should render DerivGetStartedLayout',
(PatrolTester $) async {
await $.pumpApp(DerivGetStartedLayout(
slides: [mockSlideModel],
appLogoIconPath: appLogoIconPath,
Expand All @@ -41,7 +41,7 @@ void main() {
expect($(SecondaryButton), findsOneWidget);
});

patrolTest('should call onLoginTapped when login button is pressed',
patrolWidgetTest('should call onLoginTapped when login button is pressed',
(PatrolTester $) async {
bool loginTapped = false;

Expand All @@ -60,7 +60,7 @@ void main() {
expect(loginTapped, isTrue);
});

patrolTest('should call onSignupTapped when signup button is pressed',
patrolWidgetTest('should call onSignupTapped when signup button is pressed',
(PatrolTester $) async {
bool signupTapped = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:patrol/patrol.dart';

import 'package:patrol_finders/patrol_finders.dart';
import '../../../mocks.dart';
import '../../../pump_app.dart';

Expand All @@ -25,7 +24,7 @@ void main() {
mockPassword = 'test1234';
});

patrolTest('renders correctly', (PatrolTester $) async {
patrolWidgetTest('renders correctly', (PatrolTester $) async {
when(() => authCubit.state).thenAnswer((_) => DerivAuthLoggedOutState());

when(() => authCubit.stream)
Expand All @@ -44,7 +43,8 @@ void main() {
expect($(ElevatedButton).$('Proceed'), findsOneWidget);
});

patrolTest('proceeds to login on correct code', (PatrolTester $) async {
patrolWidgetTest('proceeds to login on correct code',
(PatrolTester $) async {
when(() => authCubit.state).thenAnswer((_) => DerivAuthLoggedOutState());

when(() => authCubit.stream)
Expand All @@ -54,10 +54,9 @@ void main() {
email: any(named: 'email'),
password: any(named: 'password'),
otp: any(named: 'otp')))
.thenAnswer((_) async => DerivAuthLoggedInState(
authorizeEntity: const AuthorizeEntity(),
landingCompany: const LandingCompanyEntity(),
));
.thenAnswer((_) async => DerivAuthLoggedInState(const DerivAuthModel(
authorizeEntity: AuthorizeEntity(),
landingCompany: LandingCompanyEntity())));

await $.pumpApp(
BlocProvider<DerivAuthCubit>.value(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:patrol/patrol.dart';

import 'package:patrol_finders/patrol_finders.dart';
import '../../../mocks.dart';
import '../../../pump_app.dart';

Expand All @@ -23,7 +22,7 @@ void main() {

setUpAll(() => authCubit = MockAuthCubit());

patrolTest(
patrolWidgetTest(
'renders email and password field including social auth buttons.',
(PatrolTester $) async {
final mockAuthState = DerivAuthLoggedOutState();
Expand Down Expand Up @@ -54,7 +53,7 @@ void main() {
expect($(DerivSocialAuthPanel), findsOneWidget);
});

patrolTest('displays invalid email error on invalid email typed.',
patrolWidgetTest('displays invalid email error on invalid email typed.',
(PatrolTester $) async {
final mockAuthState = DerivAuthLoggedOutState();
const invalidEmail = 'invalid-email';
Expand Down Expand Up @@ -87,7 +86,7 @@ void main() {
expect($(Text).$('Enter a valid email address'), findsOneWidget);
});

patrolTest('displays loading error on AuthLoadingState',
patrolWidgetTest('displays loading error on AuthLoadingState',
(PatrolTester $) async {
final mockAuthState = DerivAuthLoadingState();

Expand All @@ -114,7 +113,7 @@ void main() {
expect($(LoadingIndicator), findsOneWidget);
});

patrolTest('calls signupTapped when signup button is pressed.',
patrolWidgetTest('calls signupTapped when signup button is pressed.',
(PatrolTester $) async {
final mockAuthState = DerivAuthLoggedOutState();

Expand Down Expand Up @@ -149,10 +148,13 @@ void main() {
expect(onSignupTappedCalled, isTrue);
});

patrolTest('calls onLoggedIn on successful login.', (PatrolTester $) async {
patrolWidgetTest('calls onLoggedIn on successful login.',
(PatrolTester $) async {
final mockAuthState = DerivAuthLoggedInState(
authorizeEntity: const AuthorizeEntity(),
landingCompany: const LandingCompanyEntity(),
const DerivAuthModel(
authorizeEntity: AuthorizeEntity(),
landingCompany: LandingCompanyEntity(),
),
);

when(() => authCubit.state).thenAnswer((_) => mockAuthState);
Expand Down Expand Up @@ -180,9 +182,12 @@ void main() {
expect(onLoggedInCalled, isTrue);
});

patrolTest('calls onLoginError on login error.', (PatrolTester $) async {
patrolWidgetTest('calls onLoginError on login error.',
(PatrolTester $) async {
final mockAuthState = DerivAuthErrorState(
message: 'error', type: AuthErrorType.failedAuthorization);
isSocialLogin: false,
message: 'error',
type: AuthErrorType.failedAuthorization);

when(() => authCubit.state).thenAnswer((_) => mockAuthState);

Expand All @@ -209,7 +214,7 @@ void main() {
expect(onLoginErrorCalled, isTrue);
});

patrolTest('calls resetPassTapped when reset button is pressed.',
patrolWidgetTest('calls resetPassTapped when reset button is pressed.',
(PatrolTester $) async {
final mockAuthState = DerivAuthLoggedOutState();

Expand Down Expand Up @@ -240,7 +245,7 @@ void main() {
expect(onResetPassTappedCalled, isTrue);
});

patrolTest(
patrolWidgetTest(
'calls onSocialAuthButtonPressed when social auth button is pressed.',
(PatrolTester $) async {
final mockAuthState = DerivAuthLoggedOutState();
Expand Down
Loading