From c044432540b9a8fe588adbdd10f96e5ee8a9b206 Mon Sep 17 00:00:00 2001 From: Xinyi Ye Date: Mon, 5 Feb 2024 14:54:13 -0800 Subject: [PATCH] ci: add pr test and lint --- .github/workflows/ci.yml | 28 +++++++++++++++++ .github/workflows/semantic-pr.yml | 43 ++++++++++++++++++++++++++ CONTRIBUTING.md | 23 +++++++++++++- example/lib/app_state.dart | 1 - example/lib/deviceid_sessionid.dart | 4 +-- example/lib/event_form.dart | 2 +- example/lib/flush_thresholds_form.dart | 2 +- example/lib/group_form.dart | 2 +- example/lib/group_identify_form.dart | 2 +- example/lib/identify_form.dart | 2 +- example/lib/my_app.dart | 2 +- example/lib/revenue_form.dart | 2 +- example/lib/user_id_form.dart | 4 +-- lib/web/amplitude_js.dart | 2 ++ 14 files changed, 106 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/semantic-pr.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b5c9f67 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,28 @@ +name: Test and Lint + +on: [pull_request] + +jobs: + test: + name: Check the source code + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Flutter + uses: subosito/flutter-action@v2 + with: + channel: 'stable' + + - name: Check Flutter version + run: flutter --version + + - name: Install packages + run: flutter pub get + + - name: Linter + run: flutter analyze + + - name: Test + run: flutter test \ No newline at end of file diff --git a/.github/workflows/semantic-pr.yml b/.github/workflows/semantic-pr.yml new file mode 100644 index 0000000..7998352 --- /dev/null +++ b/.github/workflows/semantic-pr.yml @@ -0,0 +1,43 @@ +name: Semantic PR Check + +on: + pull_request: + types: [opened, synchronize, edited] + +jobs: + pr-title-check: + name: Check PR for semantic title + runs-on: ubuntu-latest + steps: + - name: PR title is valid + if: > + startsWith(github.event.pull_request.title, 'feat:') || startsWith(github.event.pull_request.title, 'feat(') || + startsWith(github.event.pull_request.title, 'fix:') || startsWith(github.event.pull_request.title, 'fix(') || + startsWith(github.event.pull_request.title, 'perf:') || startsWith(github.event.pull_request.title, 'perf(') || + startsWith(github.event.pull_request.title, 'docs:') || startsWith(github.event.pull_request.title, 'docs(') || + startsWith(github.event.pull_request.title, 'test:') || startsWith(github.event.pull_request.title, 'test(') || + startsWith(github.event.pull_request.title, 'refactor:') || startsWith(github.event.pull_request.title, 'refactor(') || + startsWith(github.event.pull_request.title, 'style:') || startsWith(github.event.pull_request.title, 'style(') || + startsWith(github.event.pull_request.title, 'build:') || startsWith(github.event.pull_request.title, 'build(') || + startsWith(github.event.pull_request.title, 'ci:') || startsWith(github.event.pull_request.title, 'ci(') || + startsWith(github.event.pull_request.title, 'chore:') || startsWith(github.event.pull_request.title, 'chore(') || + startsWith(github.event.pull_request.title, 'revert:') || startsWith(github.event.pull_request.title, 'revert(') + run: | + echo 'Title checks passed' + + - name: PR title is invalid + if: > + !startsWith(github.event.pull_request.title, 'feat:') && !startsWith(github.event.pull_request.title, 'feat(') && + !startsWith(github.event.pull_request.title, 'fix:') && !startsWith(github.event.pull_request.title, 'fix(') && + !startsWith(github.event.pull_request.title, 'perf:') && !startsWith(github.event.pull_request.title, 'perf(') && + !startsWith(github.event.pull_request.title, 'docs:') && !startsWith(github.event.pull_request.title, 'docs(') && + !startsWith(github.event.pull_request.title, 'test:') && !startsWith(github.event.pull_request.title, 'test(') && + !startsWith(github.event.pull_request.title, 'refactor:') && !startsWith(github.event.pull_request.title, 'refactor(') && + !startsWith(github.event.pull_request.title, 'style:') && !startsWith(github.event.pull_request.title, 'style(') && + !startsWith(github.event.pull_request.title, 'build:') && !startsWith(github.event.pull_request.title, 'build(') && + !startsWith(github.event.pull_request.title, 'ci:') && !startsWith(github.event.pull_request.title, 'ci(') && + !startsWith(github.event.pull_request.title, 'chore:') && !startsWith(github.event.pull_request.title, 'chore(') && + !startsWith(github.event.pull_request.title, 'revert:') && !startsWith(github.event.pull_request.title, 'revert(') + run: | + echo 'Pull request title is not valid. Please check github.com/amplitude/Amplitude-Flutter/blob/main/CONTRIBUTING.md#pr-commit-title-conventions' + exit 1 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e203b5d..3c41556 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,4 +20,25 @@ You can checkout the the official Flutter documentation on [getting started](htt Checkout the [set up and editor](https://flutter.dev/docs/get-started/editor?tab=vscode) and [test drive](https://flutter.dev/docs/get-started/test-drive) sections of the official Flutter documentation on setting up your environment. -You should then be able to run the Flutter project in `example/` which has the Amplitude Flutter SDK installed. \ No newline at end of file +You should then be able to run the Flutter project in `example/` which has the Amplitude Flutter SDK installed. + +## Practices + +### PR Commit Title Conventions + +PR titles should follow [conventional commit standards](https://www.conventionalcommits.org/en/v1.0.0/). This helps automate the release process. + +#### Commit Types + +- **Special Case**: Any commit with `BREAKING CHANGES` in the body: Creates major release +- `feat()`: New features (minimum minor release) +- `fix()`: Bug fixes (minimum patch release) +- `perf()`: Performance improvement +- `docs()`: Documentation updates +- `test()`: Test updates +- `refactor()`: Code change that neither fixes a bug nor adds a feature +- `style()`: Code style changes (e.g. formatting, commas, semi-colons) +- `build()`: Changes that affect the build system or external dependencies (e.g. Yarn, Npm) +- `ci()`: Changes to our CI configuration files and scripts +- `chore()`: Other changes that don't modify src or test files +- `revert()`: Revert commit diff --git a/example/lib/app_state.dart b/example/lib/app_state.dart index 38527ed..5e48e6e 100644 --- a/example/lib/app_state.dart +++ b/example/lib/app_state.dart @@ -1,5 +1,4 @@ import 'package:amplitude_flutter/amplitude.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; class AppState extends InheritedWidget { diff --git a/example/lib/deviceid_sessionid.dart b/example/lib/deviceid_sessionid.dart index 85ad6da..046068f 100644 --- a/example/lib/deviceid_sessionid.dart +++ b/example/lib/deviceid_sessionid.dart @@ -13,7 +13,7 @@ class _DeviceIdSessionIdState extends State { children: [ Row( children: [ - Text('Device Id', style: Theme.of(context).textTheme.headline5), + Text('Device Id', style: Theme.of(context).textTheme.headlineSmall), ], ), Row( @@ -28,7 +28,7 @@ class _DeviceIdSessionIdState extends State { ), Row( children: [ - Text('Session Id', style: Theme.of(context).textTheme.headline5), + Text('Session Id', style: Theme.of(context).textTheme.headlineSmall), ], ), Row(children: [ diff --git a/example/lib/event_form.dart b/example/lib/event_form.dart index 67dffd3..77a8858 100644 --- a/example/lib/event_form.dart +++ b/example/lib/event_form.dart @@ -22,7 +22,7 @@ class _EventFormState extends State { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text('Event', style: Theme.of(context).textTheme.headline5), + Text('Event', style: Theme.of(context).textTheme.headlineSmall), const SizedBox(height: 10), TextField( decoration: InputDecoration( diff --git a/example/lib/flush_thresholds_form.dart b/example/lib/flush_thresholds_form.dart index 4af02c0..c0191ca 100644 --- a/example/lib/flush_thresholds_form.dart +++ b/example/lib/flush_thresholds_form.dart @@ -39,7 +39,7 @@ class _FlushThresholdFormState extends State { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text('Flush Intervals', style: Theme.of(context).textTheme.headline5), + Text('Flush Intervals', style: Theme.of(context).textTheme.headlineSmall), const SizedBox(height: 10), TextField( decoration: InputDecoration( diff --git a/example/lib/group_form.dart b/example/lib/group_form.dart index 42925aa..ac671e1 100644 --- a/example/lib/group_form.dart +++ b/example/lib/group_form.dart @@ -29,7 +29,7 @@ class _GroupFormState extends State { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text('Group / Account', style: Theme.of(context).textTheme.headline5), + Text('Group / Account', style: Theme.of(context).textTheme.headlineSmall), const SizedBox(height: 10), Row(children: [ Expanded( diff --git a/example/lib/group_identify_form.dart b/example/lib/group_identify_form.dart index d140e51..8d500b4 100644 --- a/example/lib/group_identify_form.dart +++ b/example/lib/group_identify_form.dart @@ -41,7 +41,7 @@ class _GroupIdentifyFormState extends State { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text('Group Identify', style: Theme.of(context).textTheme.headline5), + Text('Group Identify', style: Theme.of(context).textTheme.headlineSmall), const SizedBox(height: 10), Row(children: [ Expanded( diff --git a/example/lib/identify_form.dart b/example/lib/identify_form.dart index dff2b1c..743c637 100644 --- a/example/lib/identify_form.dart +++ b/example/lib/identify_form.dart @@ -35,7 +35,7 @@ class _IdentifyFormState extends State { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text('Identify', style: Theme.of(context).textTheme.headline5), + Text('Identify', style: Theme.of(context).textTheme.headlineSmall), const SizedBox(height: 10), Row(children: [ Expanded( diff --git a/example/lib/my_app.dart b/example/lib/my_app.dart index a19aae9..654145b 100644 --- a/example/lib/my_app.dart +++ b/example/lib/my_app.dart @@ -112,7 +112,7 @@ class _MyAppState extends State { child: const Text('Flush Events'), onPressed: _flushEvents, ), - Text(_message, style: Theme.of(context).textTheme.bodyText1) + Text(_message, style: Theme.of(context).textTheme.bodyLarge) ], ), ), diff --git a/example/lib/revenue_form.dart b/example/lib/revenue_form.dart index b17ae5e..d019703 100644 --- a/example/lib/revenue_form.dart +++ b/example/lib/revenue_form.dart @@ -38,7 +38,7 @@ class _RevenueFormState extends State { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text('Revenue', style: Theme.of(context).textTheme.headline5), + Text('Revenue', style: Theme.of(context).textTheme.headlineSmall), const SizedBox(height: 10), TextField( decoration: dec.copyWith(labelText: 'Product Id'), diff --git a/example/lib/user_id_form.dart b/example/lib/user_id_form.dart index 277aa5f..d30ddd5 100644 --- a/example/lib/user_id_form.dart +++ b/example/lib/user_id_form.dart @@ -19,7 +19,7 @@ class _UserIdFormState extends State { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text('Current User Id', style: Theme.of(context).textTheme.headline5), + Text('Current User Id', style: Theme.of(context).textTheme.headlineSmall), FutureBuilder( future: AppState.of(context).analytics.getUserId(), builder: (BuildContext context, AsyncSnapshot snapshot) { @@ -27,7 +27,7 @@ class _UserIdFormState extends State { }, ), const SizedBox(height: 10), - Text('User Id', style: Theme.of(context).textTheme.headline5), + Text('User Id', style: Theme.of(context).textTheme.headlineSmall), const SizedBox(height: 10), new TextField( autocorrect: false, diff --git a/lib/web/amplitude_js.dart b/lib/web/amplitude_js.dart index 4e7a1a5..98a2bea 100644 --- a/lib/web/amplitude_js.dart +++ b/lib/web/amplitude_js.dart @@ -38,7 +38,9 @@ class Amplitude { String groupType, String groupName, Identify groupIdentify, + // ignore: non_constant_identifier_names Function? opt_callback, + // ignore: non_constant_identifier_names Function? opt_error_callback, bool? outOfSession); external bool setOffline(bool enabled);