Skip to content
Draft
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

- Remove deprecated "codesign" parameter.
- Support `build: "ipa"` option to `flutter_build()` and deprecate supplying
parameters to [gym](https://docs.fastlane.tools/actions/gym/).

## 0.5.0

- Do not print a warning message when not able to parse "flutter build" output
Expand Down
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
Automated end-to-end test (download Flutter, create an app, build it) on the
following platforms:

* macOS (iOS)
* macOS (Android)
* Ubuntu Linux (Android)
* Windows (Android)
- macOS (iOS)
- macOS (Android)
- Ubuntu Linux (Android)
- Windows (Android)

## Getting Started

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:
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:

```shell
$ fastlane add_plugin flutter
Expand All @@ -27,7 +28,8 @@ Flutter actions plugin for Fastlane.

## Example

Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin.
Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this
plugin.

## Run tests for this plugin

Expand All @@ -48,16 +50,22 @@ $ bundle exec rubocop -a

## Issues and Feedback

For any other issues and feedback about this plugin, please submit it to this repository.
For any other issues and feedback about this plugin, please submit it to this
repository.

## Troubleshooting

If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
If you have trouble using plugins, check out the
[Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/)
guide.

## Using _fastlane_ Plugins

For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
For more information about how the `fastlane` plugin system works, check out the
[Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).

## About _fastlane_

_fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
_fastlane_ is the easiest way to automate beta deployments and releases for your
iOS and Android apps. To learn more, check out
[fastlane.tools](https://fastlane.tools).
19 changes: 4 additions & 15 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,10 @@ lane :build do
build_args: build_args,
)

# NOTE: for iOS, output_file will point to a .app directory instead of an
# .ipa file: see https://github.com/flutter/flutter/issues/13065.
#
# flutter_build action helps you by setting up GYM_xxx environment variables
# so that you can use gym() without parameters immediately afterwards:
#
# gym(silent: true, suppress_xcode_output: true)
#
# We do not run gym() here because it requires a provisioning profile, which
# is not installed on the test server.
#
# Once gym() completes, it sets SharedValues::IPA_OUTPUT_PATH context variable
# which is then automatically detected by upload_to_testflight or
# upload_to_app_store actions, so those do not need to be configured any
# further.
# Once flutter_build() completes, it sets context variables which are then
# automatically detected by upload_to_testflight (pilot), upload_to_app_store
# (deliver) and upload_to_play_store (supply) actions, so those do not need to
# be configured any further.

UI.success("Built #{output_file}!")
end
Expand Down
89 changes: 44 additions & 45 deletions lib/fastlane/plugin/flutter/actions/flutter_build_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,12 @@ module SharedValues
class FlutterBuildAction < Action
extend FlutterActionBase

FASTLANE_PLATFORM_TO_BUILD = {
ios: 'ios',
android: 'apk',
}

def self.run(params)
# "flutter build" args list.
build_args = []

if params[:build]
build_args.push(params[:build])
else
if fastlane_platform = (lane_context[SharedValues::PLATFORM_NAME] ||
lane_context[SharedValues::DEFAULT_PLATFORM])
build_args.push(FASTLANE_PLATFORM_TO_BUILD[fastlane_platform])
else
UI.user_error!('flutter_build action "build" parameter is not ' \
'specified and cannot be inferred from Fastlane context.')
end
end

process_deprecated_params(params, build_args)
build_type = params[:build] || guess_build_type(params)
build_args.push(build_type)

if params[:debug]
build_args.push('--debug')
Expand Down Expand Up @@ -68,19 +52,60 @@ def self.run(params)

# Fill in some well-known context variables so that next commands may
# pick them up.
case params[:build]
case build_type
when 'apk'
lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH] =
lane_context[SharedValues::FLUTTER_OUTPUT]
when 'appbundle'
lane_context[SharedValues::GRADLE_AAB_OUTPUT_PATH] =
lane_context[SharedValues::FLUTTER_OUTPUT]
when 'ipa'
lane_context[SharedValues::IPA_OUTPUT_PATH] =
lane_context[SharedValues::FLUTTER_OUTPUT]
end

lane_context[SharedValues::FLUTTER_OUTPUT]
end

def self.guess_build_type(params)
if fastlane_platform = (lane_context[SharedValues::PLATFORM_NAME] ||
lane_context[SharedValues::DEFAULT_PLATFORM])
case fastlane_platform
when :ios
if (params[:build_args] || []).include?('--no-codesign') ||
params[:debug]
'ios'
else
'ipa'
end
when :android
params[:debug] ? 'apk' : 'appbundle'
end
else
UI.user_error!('flutter_build action "build" parameter is not ' \
'specified and cannot be inferred from Fastlane context.')
end
end

def self.publish_gym_defaults(build_args)
if build_args.include?('ios') && !build_args.include?('--debug')
UI.deprecated(<<-"MESSAGE")
Building for "ios" without "--debug" will soon no longer populate parameters
used by gym(). Consider using the new "ipa" build type directly and omitting an
extra gym() action:

BEFORE:

flutter_build(build: "ios", build_args: ["--no-codesign"])
gym(silent: true, suppress_xcode_output: true)

AFTER:

flutter_build(build: "ipa")

MESSAGE
end

ENV['GYM_WORKSPACE'] ||= 'ios/Runner.xcworkspace'
ENV['GYM_BUILD_PATH'] ||= 'build/ios'
ENV['GYM_OUTPUT_DIRECTORY'] ||= 'build'
Expand All @@ -98,24 +123,6 @@ def self.publish_gym_defaults(build_args)
end
end

def self.process_deprecated_params(params, build_args)
unless params[:codesign].nil?
UI.deprecated(<<-"MESSAGE")
flutter_build parameter "codesign" is deprecated. Use

flutter_build(
build_args: ["--#{params[:codesign] == false ? 'no-' : ''}codesign"]
)

form instead.
MESSAGE

if params[:codesign] == false
build_args.push('--no-codesign')
end
end
end

def self.process_build_output(output, build_args)
artifacts = output.scan(/Built (.*?)(:? \([^)]*\))?\.$/).
map { |path| File.absolute_path(path[0]) }
Expand Down Expand Up @@ -160,14 +167,6 @@ def self.available_options
type: Boolean,
default_value: false,
),
FastlaneCore::ConfigItem.new(
key: :codesign,
env_name: 'FL_FLUTTER_CODESIGN',
description: 'Set to false to skip iOS app signing. This may be ' \
'useful e.g. on CI or when signed later by Fastlane "sigh"',
optional: true,
type: Boolean,
),
FastlaneCore::ConfigItem.new(
key: :build_number,
env_name: 'FL_FLUTTER_BUILD_NUMBER',
Expand Down
28 changes: 27 additions & 1 deletion spec/flutter_build_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,33 @@
it 'build type from fastlane platform' do
expect(Fastlane::Helper::FlutterHelper).
to receive(:flutter).
with('build', 'ios').
with('build', 'ios', '--debug').
and_yield(*successful_flutter(''))
Fastlane::FastFile.new.parse(<<-FASTLANE).runner.execute(:test)
default_platform(:ios)
lane :test do
flutter_build(debug: true)
end
FASTLANE
end

it 'build type from fastlane platform (no-codesign builds)' do
expect(Fastlane::Helper::FlutterHelper).
to receive(:flutter).
with('build', 'ios', '--no-codesign').
and_yield(*successful_flutter(''))
Fastlane::FastFile.new.parse(<<-FASTLANE).runner.execute(:test)
default_platform(:ios)
lane :test do
flutter_build(build_args: %w(--no-codesign))
end
FASTLANE
end

it 'build type from fastlane platform (release builds)' do
expect(Fastlane::Helper::FlutterHelper).
to receive(:flutter).
with('build', 'ipa').
and_yield(*successful_flutter(''))
Fastlane::FastFile.new.parse(<<-FASTLANE).runner.execute(:test)
default_platform(:ios)
Expand Down