Skip to content

Commit

Permalink
Split plugin into multiple actions
Browse files Browse the repository at this point in the history
  • Loading branch information
dotdoom committed Aug 4, 2019
1 parent dc453d8 commit c40fad5
Show file tree
Hide file tree
Showing 17 changed files with 646 additions and 760 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -33,7 +33,7 @@ jobs:
# run tests!
- run:
name: run tests
command: bundle exec rake
command: bundle exec rake && bundle exec fastlane end_to_end_test

# collect reports
- store_test_results:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -11,3 +11,5 @@ fastlane/report.xml
coverage
test-results
/vendor

/.vscode
44 changes: 44 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,44 @@
## Tests

### Re-generating demo project

Create a new Flutter project:

```shell
$ flutter create demo
$ cd demo
```

Edit pubspec.yaml:

```diff
dev_dependencies:
flutter_test:
sdk: flutter

+ intl_translation: any
+ build_runner: any
```

Install dependencies:

```shell
$ flutter packages get
```

Create file `lib/intl/intl.dart`:

```dart
import 'dart:async';
import 'messages_all.dart';
import 'package:intl/intl.dart';
class DemoIntl {
String get helloWorld => Intl.message(
'Hello, World!',
name: 'helloWorld',
desc: 'Text displayed in the center of the login screen',
);
}
```
20 changes: 11 additions & 9 deletions README.md
Expand Up @@ -6,8 +6,8 @@

This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-flutter`, add it to your project by running:

```bash
fastlane add_plugin flutter
```shell
$ fastlane add_plugin flutter
```

## About flutter
Expand All @@ -16,21 +16,23 @@ Flutter actions plugin for Fastlane.

## Example

Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.

**Note to author:** Please set up a sample project to make it easy for users to explore what your plugin does. Provide everything that is necessary to try out the plugin in this project (including a sample Xcode/Android project if necessary)
Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin.

## Run tests for this plugin

To run both the tests, and code style validation, run

```
rake
```shell
$ bundle install
$ bundle exec rake
$ bundle exec fastlane end_to_end_test
```

To automatically fix many of the styling issues, use
```
rubocop -a

```shell
$ bundle install
$ bundle exec rubocop -a
```

## Issues and Feedback
Expand Down
135 changes: 127 additions & 8 deletions fastlane/Fastfile
@@ -1,13 +1,132 @@
default_platform(:android)

desc "Useful on CI, this lane installs Flutter and accepts some of the Android"
desc "SDK licenses. Note that it does not install Android SDK itself, which is"
desc "installed by Gradle automatically during the first build."
desc "Nevertheless, ANDROID_SDK_ROOT or ANDROID_HOME environment variable must"
desc "point to a destination directory (which might be empty)."
lane :bootstrap do
flutter_bootstrap(android_licenses: {
'android-sdk-license' => '24333f8a63b6825ea9c5514f83c2829b004d1fee',
})
end

desc "Generate files, format, lint and build project."
lane :build do
flutter(action: 'l10n',
l10n_strings_file: 'lib/messages.dart',
l10n_reformat_arb: true)
flutter(action: 'format')
flutter(action: 'analyze')
# Generate intl and other files.
flutter_generate(
# File with all the Intl.message() calls.
intl_strings_file: 'lib/strings.dart',
# Actual locale of default values provided in that Dart file.
intl_strings_locale: 'en_US',
)

# Reformat the source code.
flutter(args: %w(format .))

# Uncomment the following on CI. For Git repositories, it will verify that
# 'format' and 'generate' actions didn't change anything from what a developer
# has been doing.
# ensure_git_status_clean

# Lint (statically find errors).
flutter(args: %w(analyze lib))

# Build a debug version of the app (release will require signing config).
flutter_build(
debug: true,
# Uncomment to build an AAB instead of an APK (requires adb, why?!).
# build: 'appbundle',
# Override version from pubspec.yaml.
build_number: 123,
build_name: '1.2.3',
)
end

platform :android do
lane :build do
flutter(action: 'build', debug: true)
######## Internal tests for the plugin ########

desc "This is an internal test for Fastlane Flutter plugin. You shouldn't"
desc "need to do anything like that in your Fastfile."
desc "It uses 'bootstrap' lane from above to install Flutter, then creates a"
desc "temporary (but real) Flutter project, and builds it via 'build' lane."
lane :end_to_end_test do
Dir.mktmpdir('fastlane-plugin-flutter-') do |root|
# Override environment in case Flutter / Android SDK is preinstalled. In
# this test, we want to really test full installation procedure.
ENV.delete('ANDROID_HOME')
ENV['ANDROID_SDK_ROOT'] = File.join(root, 'android')
ENV['FLUTTER_SDK_ROOT'] = File.join(root, 'flutter')

# Install our dependencies to this temporary directory.
bootstrap

app = File.join(root, 'fastlanetest')
flutter(args: ['create', app])

# A little hack. Since Fastlane always runs actions in 1 directory level
# above current, we have to chdir 1 level into application dir structure:
# https://docs.fastlane.tools/advanced/fastlane/#directory-behavior
fastlane = File.join(app, 'fastlane')
Dir.mkdir(fastlane)
Dir.chdir(fastlane) do
# Add dependencies on built_value and intl, and add some code to trigger
# (and validate) generators.
pubspec = File.join('..', 'pubspec.yaml')
File.write(pubspec, File.read(pubspec).sub(
"dependencies:",
"dependencies:\n" \
" built_value:\n"
).sub(
"dev_dependencies:",
"dev_dependencies:\n" \
" build_runner:\n" \
" built_value_generator:\n" \
" intl_translation:\n"
))

File.write(File.join('..', 'lib', 'strings.dart'), <<-'DART')
import 'package:intl/intl.dart';
class Strings {
static String get helloWorld => Intl.message(
'Hello World',
name: 'helloWorld',
desc: 'Hello World text on the splash screen',
);
}
DART

File.write(File.join('..', 'lib', 'message.dart'), <<-'DART')
import 'package:built_value/built_value.dart';
part 'message.g.dart';
abstract class Message implements Built<Message, MessageBuilder> {
String get text;
factory Message([void Function(MessageBuilder) updates]) = _$Message;
Message._();
}
DART

File.write(File.join('..', 'lib', 'splash.dart'), <<-'DART')
import 'strings.dart';
import 'message.dart';
// messages_all.dart file should be generated by Intl.
import 'messages_all.dart' as messages_all;
Future<Message> splashScreenMessage() async {
await messages_all.initializeMessages('en_US');
// MessageBuilder class should be generated by built_value.
return (MessageBuilder()..text = Strings.helloWorld).build();
}
DART

# Now that we've created our test application, run a real lane.
build

# Call build one more time with files already generated, as we expect it
# to be idempotent.
build

# Call bootstrap one more time with Flutter already installed. This is
# to ensure that upgrade path in our plugin is working correctly.
bootstrap
end
end
end
1 change: 0 additions & 1 deletion fastlane/Pluginfile

This file was deleted.

0 comments on commit c40fad5

Please sign in to comment.