├── .github └── workflows │ └── .gitkeep ├── .gitignore ├── .rspec ├── .rubocop.yml ├── .travis.yml ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── example_pubspec.yaml ├── fastlane-plugin-flutter_version_manager.gemspec ├── fastlane ├── Fastfile └── Pluginfile ├── lib └── fastlane │ └── plugin │ ├── flutter_version_manager.rb │ └── flutter_version_manager │ ├── actions │ └── flutter_version_manager_action.rb │ ├── helper │ └── flutter_version_manager_helper.rb │ └── version.rb ├── spec └── spec_helper.rb └── version.yml /.github/workflows/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rubiconba/fastlane-plugin-flutter-version-manager/a33d1362196b7de6ea1ae779d855b444c8c00873/.github/workflows/.gitkeep -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | Gemfile.lock 3 | 4 | ## Documentation cache and generated files: 5 | /.yardoc/ 6 | /_yardoc/ 7 | /doc/ 8 | /rdoc/ 9 | fastlane/README.md 10 | fastlane/report.xml 11 | coverage 12 | test-results 13 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | --color 3 | --format d 4 | --format RspecJunitFormatter 5 | --out test-results/rspec/rspec.xml 6 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | --- 2 | Style/MultipleComparison: 3 | Enabled: false 4 | Style/PercentLiteralDelimiters: 5 | Enabled: false 6 | Style/ClassCheck: 7 | EnforcedStyle: kind_of? 8 | Style/FrozenStringLiteralComment: 9 | Enabled: false 10 | Style/SafeNavigation: 11 | Enabled: false 12 | Performance/RegexpMatch: 13 | Enabled: false 14 | Performance/StringReplacement: 15 | Enabled: false 16 | Style/NumericPredicate: 17 | Enabled: false 18 | Metrics/BlockLength: 19 | Enabled: false 20 | Metrics/ModuleLength: 21 | Enabled: false 22 | Style/VariableNumber: 23 | Enabled: false 24 | Style/MethodMissing: 25 | Enabled: false 26 | MultilineBlockChain: 27 | Enabled: false 28 | Style/NumericLiteralPrefix: 29 | Enabled: false 30 | Style/TernaryParentheses: 31 | Enabled: false 32 | Style/EmptyMethod: 33 | Enabled: false 34 | Style/BracesAroundHashParameters: 35 | Enabled: false 36 | Lint/UselessAssignment: 37 | Exclude: 38 | - "**/spec/**/*" 39 | Require/MissingRequireStatement: 40 | Exclude: 41 | - "**/spec/**/*.rb" 42 | - "**/spec_helper.rb" 43 | - spaceship/lib/spaceship/babosa_fix.rb 44 | - "**/Fastfile" 45 | - "**/*.gemspec" 46 | - rakelib/**/* 47 | - "**/*.rake" 48 | - "**/Rakefile" 49 | - fastlane/**/* 50 | - supply/**/* 51 | Layout/IndentHash: 52 | Enabled: false 53 | Layout/AlignHash: 54 | Enabled: false 55 | Layout/DotPosition: 56 | Enabled: false 57 | Style/DoubleNegation: 58 | Enabled: false 59 | Style/SymbolArray: 60 | Enabled: false 61 | Layout/IndentHeredoc: 62 | Enabled: false 63 | Style/MixinGrouping: 64 | Exclude: 65 | - "**/spec/**/*" 66 | Lint/HandleExceptions: 67 | Enabled: false 68 | Lint/UnusedBlockArgument: 69 | Enabled: false 70 | Lint/AmbiguousBlockAssociation: 71 | Enabled: false 72 | Style/GlobalVars: 73 | Enabled: false 74 | Style/ClassAndModuleChildren: 75 | Enabled: false 76 | Style/SpecialGlobalVars: 77 | Enabled: false 78 | Metrics/AbcSize: 79 | Enabled: false 80 | Metrics/MethodLength: 81 | Enabled: false 82 | Metrics/CyclomaticComplexity: 83 | Enabled: false 84 | Style/WordArray: 85 | MinSize: 19 86 | Style/SignalException: 87 | Enabled: false 88 | Style/RedundantReturn: 89 | Enabled: false 90 | Style/IfUnlessModifier: 91 | Enabled: false 92 | Style/AndOr: 93 | Enabled: true 94 | EnforcedStyle: conditionals 95 | Metrics/ClassLength: 96 | Max: 320 97 | Metrics/LineLength: 98 | Max: 370 99 | Metrics/ParameterLists: 100 | Max: 17 101 | Metrics/PerceivedComplexity: 102 | Max: 18 103 | Style/GuardClause: 104 | Enabled: false 105 | Style/StringLiterals: 106 | Enabled: false 107 | Style/ConditionalAssignment: 108 | Enabled: false 109 | Style/RedundantSelf: 110 | Enabled: false 111 | Lint/UnusedMethodArgument: 112 | Enabled: false 113 | Lint/ParenthesesAsGroupedExpression: 114 | Exclude: 115 | - "**/spec/**/*" 116 | Style/PredicateName: 117 | Enabled: false 118 | Style/PerlBackrefs: 119 | Enabled: false 120 | Layout/SpaceAroundOperators: 121 | Exclude: 122 | - "**/spec/actions_specs/xcodebuild_spec.rb" 123 | AllCops: 124 | TargetRubyVersion: 2.0 125 | Include: 126 | - "*/lib/assets/*Template" 127 | - "*/lib/assets/*TemplateAndroid" 128 | Exclude: 129 | - "**/lib/assets/custom_action_template.rb" 130 | - "./vendor/**/*" 131 | - "**/lib/assets/DefaultFastfileTemplate" 132 | - "**/lib/assets/MatchfileTemplate" 133 | - "**/spec/fixtures/broken_files/broken_file.rb" 134 | Style/FileName: 135 | Exclude: 136 | - "**/Dangerfile" 137 | - "**/Brewfile" 138 | - "**/Gemfile" 139 | - "**/Podfile" 140 | - "**/Rakefile" 141 | - "**/Fastfile" 142 | - "**/Deliverfile" 143 | - "**/Snapfile" 144 | - "**/*.gemspec" 145 | Style/Documentation: 146 | Enabled: false 147 | Style/MutableConstant: 148 | Enabled: false 149 | Style/ZeroLengthPredicate: 150 | Enabled: false 151 | Style/IfInsideElse: 152 | Enabled: false 153 | Style/CollectionMethods: 154 | Enabled: false 155 | CrossPlatform/ForkUsage: 156 | Exclude: 157 | - "**/plugins/template/**/*" 158 | Lint/IsStringUsage: 159 | Include: 160 | - cert/**/* 161 | - gym/**/* 162 | - match/**/* 163 | - screengrab/**/* 164 | - supply/**/* 165 | Style/MethodCallWithArgsParentheses: 166 | Enabled: true 167 | IgnoredMethods: 168 | - require 169 | - require_relative 170 | - fastlane_require 171 | - gem 172 | - program 173 | - command 174 | - raise 175 | - attr_accessor 176 | - attr_reader 177 | - desc 178 | - lane 179 | - private_lane 180 | - platform 181 | - to 182 | - describe 183 | - it 184 | - be 185 | - context 186 | - before 187 | - after 188 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # os: osx # enable this if you need macOS support 2 | language: ruby 3 | rvm: 4 | - 2.2.4 5 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source('https://rubygems.org') 2 | 3 | gemspec 4 | 5 | plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') 6 | 7 | eval_gemfile(plugins_path) if File.exist?(plugins_path) 8 | 9 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 10 | 11 | gem "git" 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Davor Maric and Rubicon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # flutter_version_manager plugin 2 | 3 | [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-flutter_version_manager) 4 | 5 | ## Getting Started 6 | 7 | This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-flutter_version_manager`, add it to your project by running: 8 | 9 | ```bash 10 | fastlane add_plugin flutter_version_manager 11 | ``` 12 | 13 | Inside project root, create new `version.yml` file and add the following: 14 | ``` 15 | --- 16 | major: 0 17 | minor: 0 18 | patch: 1 19 | 20 | ``` 21 | 22 | This plugin heavily resides on having a git repository. You need to configure [ruby-git](https://github.com/ruby-git/ruby-git). Add ```gem 'git'``` to `fastlane/Pluginfile` or follow the instructions from their repository. 23 | 24 | ## About flutter_version_manager 25 | 26 | Manages app versioning of a Flutter project. This plugin heavily resides on having a git repository and at least one commit as version code is applied through timestamp of HEAD commit. As for app version, `version.yml` should be used as a single source of truth. In order to apply changes to pubspec, use `-apply` as an argument of a plugin. 27 | 28 | This plugin accepts 4 arguments: 29 | - `yml` - Path to version.yml file 30 | - `pubspec` - Path to pubspec.yaml file 31 | - `git_repo` - Path to git repository (optional) 32 | - `arguments` - Additional arguments as stated below (optional) 33 | ``` 34 | -h: Access this menu 35 | -version: Reads current version name 36 | -code: Reads current version code 37 | -major: Bumps major version 38 | -minor: Bumps minor version 39 | -patch: Bumps patch version 40 | -apply: Applies version specified from version.yml to pubspec 41 | ``` 42 | 43 | ## Example 44 | 45 | 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`. 46 | 47 | ## Issues and Feedback 48 | 49 | For any other issues and feedback about this plugin, please submit it to this repository. 50 | 51 | ## Troubleshooting 52 | 53 | If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide. 54 | 55 | ## Using _fastlane_ Plugins 56 | 57 | For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/). 58 | 59 | ## About _fastlane_ 60 | 61 | _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). 62 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | 3 | require 'rspec/core/rake_task' 4 | RSpec::Core::RakeTask.new 5 | 6 | require 'rubocop/rake_task' 7 | RuboCop::RakeTask.new(:rubocop) 8 | 9 | task(default: [:spec, :rubocop]) 10 | -------------------------------------------------------------------------------- /example_pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: Flutter Application 2 | description: A new Flutter application. 3 | 4 | # The following line prevents the package from being accidentally published to 5 | # pub.dev using `pub publish`. This is preferred for private packages. 6 | publish_to: 'none' # Remove this line if you wish to publish to pub.dev 7 | 8 | # The following defines the version and build number for your application. 9 | # A version number is three numbers separated by dots, like 1.2.43 10 | # followed by an optional build number separated by a +. 11 | # Both the version and the builder number may be overridden in flutter 12 | # build by specifying --build-name and --build-number, respectively. 13 | # In Android, build-name is used as versionName while build-number used as versionCode. 14 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning 15 | # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. 16 | # Read more about iOS versioning at 17 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html 18 | version: 0.0.1+430 19 | 20 | environment: 21 | sdk: ">=2.7.0 <3.0.0" 22 | 23 | dependencies: 24 | flutter: 25 | sdk: flutter 26 | 27 | # The following adds the Cupertino Icons font to your application. 28 | # Use with the CupertinoIcons class for iOS style icons. 29 | cupertino_icons: ^0.1.3 30 | 31 | dev_dependencies: 32 | flutter_test: 33 | sdk: flutter 34 | 35 | # For information on the generic Dart part of this file, see the 36 | # following page: https://dart.dev/tools/pub/pubspec 37 | 38 | # The following section is specific to Flutter. 39 | flutter: 40 | 41 | # The following line ensures that the Material Icons font is 42 | # included with your application, so that you can use the icons in 43 | # the material Icons class. 44 | uses-material-design: true 45 | 46 | # To add assets to your application, add an assets section, like this: 47 | # assets: 48 | # - images/a_dot_burr.jpeg 49 | # - images/a_dot_ham.jpeg 50 | 51 | # An image asset can refer to one or more resolution-specific "variants", see 52 | # https://flutter.dev/assets-and-images/#resolution-aware. 53 | 54 | # For details regarding adding assets from package dependencies, see 55 | # https://flutter.dev/assets-and-images/#from-packages 56 | 57 | # To add custom fonts to your application, add a fonts section here, 58 | # in this "flutter" section. Each entry in this list should have a 59 | # "family" key with the font family name, and a "fonts" key with a 60 | # list giving the asset and other descriptors for the font. For 61 | # example: 62 | # fonts: 63 | # - family: Schyler 64 | # fonts: 65 | # - asset: fonts/Schyler-Regular.ttf 66 | # - asset: fonts/Schyler-Italic.ttf 67 | # style: italic 68 | # - family: Trajan Pro 69 | # fonts: 70 | # - asset: fonts/TrajanPro.ttf 71 | # - asset: fonts/TrajanPro_Bold.ttf 72 | # weight: 700 73 | # 74 | # For details regarding fonts from package dependencies, 75 | # see https://flutter.dev/custom-fonts/#from-packages 76 | -------------------------------------------------------------------------------- /fastlane-plugin-flutter_version_manager.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | lib = File.expand_path("../lib", __FILE__) 4 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 5 | require 'fastlane/plugin/flutter_version_manager/version' 6 | 7 | Gem::Specification.new do |spec| 8 | spec.name = 'fastlane-plugin-flutter_version_manager' 9 | spec.version = Fastlane::FlutterVersionManager::VERSION 10 | spec.author = 'Davor Maric' 11 | spec.email = 'davormaric@outlook.com' 12 | 13 | spec.summary = 'Manages app versioning of Flutter project' 14 | spec.homepage = "https://github.com/rubiconba/fastlane-plugin-flutter-version-manager" 15 | spec.license = "MIT" 16 | 17 | spec.files = Dir["lib/**/*"] + %w(README.md LICENSE) 18 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 19 | spec.require_paths = ['lib'] 20 | 21 | # Don't add a dependency to fastlane or fastlane_re 22 | # since this would cause a circular dependency 23 | 24 | # spec.add_dependency 'your-dependency', '~> 1.0.0' 25 | 26 | spec.add_development_dependency('pry') 27 | spec.add_development_dependency('bundler') 28 | spec.add_development_dependency('rspec') 29 | spec.add_development_dependency('rspec_junit_formatter') 30 | spec.add_development_dependency('rake') 31 | spec.add_development_dependency('rubocop', '0.49.1') 32 | spec.add_development_dependency('rubocop-require_tools') 33 | spec.add_development_dependency('simplecov') 34 | spec.add_development_dependency('fastlane', '>= 2.149.1') 35 | end 36 | -------------------------------------------------------------------------------- /fastlane/Fastfile: -------------------------------------------------------------------------------- 1 | lane :test do 2 | flutter_version_manager( 3 | arguments: "-major", 4 | yml: "./version.yml", 5 | pubspec: "./example_pubspec.yaml") 6 | end 7 | 8 | lane :bump_major do 9 | flutter_version_manager( 10 | arguments: "-major", 11 | yml: "./version.yml", 12 | pubspec: "./example_pubspec.yaml") 13 | end 14 | 15 | lane :bump_minor do 16 | flutter_version_manager( 17 | arguments: "-minor", 18 | yml: "./version.yml", 19 | pubspec: "./example_pubspec.yaml") 20 | end 21 | 22 | lane :bump_patch do 23 | flutter_version_manager( 24 | arguments: "-patch", 25 | yml: "./version.yml", 26 | pubspec: "./example_pubspec.yaml") 27 | end 28 | 29 | lane :read_version do 30 | flutter_version_manager( 31 | arguments: "-version", 32 | yml: "./version.yml", 33 | pubspec: "./example_pubspec.yaml") 34 | end 35 | 36 | lane :read_code do 37 | flutter_version_manager( 38 | arguments: "-code", 39 | yml: "./version.yml", 40 | pubspec: "./example_pubspec.yaml") 41 | end 42 | 43 | lane :apply_new_version do 44 | flutter_version_manager( 45 | arguments: "-apply", 46 | yml: "./version.yml", 47 | pubspec: "./example_pubspec.yaml") 48 | end 49 | 50 | lane :get_help do 51 | flutter_version_manager( 52 | arguments: "-h", 53 | yml: "./version.yml", 54 | pubspec: "./example_pubspec.yaml") 55 | end -------------------------------------------------------------------------------- /fastlane/Pluginfile: -------------------------------------------------------------------------------- 1 | # Autogenerated by fastlane 2 | -------------------------------------------------------------------------------- /lib/fastlane/plugin/flutter_version_manager.rb: -------------------------------------------------------------------------------- 1 | require 'fastlane/plugin/flutter_version_manager/version' 2 | 3 | module Fastlane 4 | module FlutterVersionManager 5 | # Return all .rb files inside the "actions" and "helper" directory 6 | def self.all_classes 7 | Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))] 8 | end 9 | end 10 | end 11 | 12 | # By default we want to import all available actions and helpers 13 | # A plugin can contain any number of actions and plugins 14 | Fastlane::FlutterVersionManager.all_classes.each do |current| 15 | require current 16 | end 17 | -------------------------------------------------------------------------------- /lib/fastlane/plugin/flutter_version_manager/actions/flutter_version_manager_action.rb: -------------------------------------------------------------------------------- 1 | require 'fastlane/action' 2 | require_relative '../helper/flutter_version_manager_helper' 3 | require 'git' 4 | require 'yaml' 5 | 6 | GIT_OFFSET = 1598622000 # IMPORTANT: Do not change! 7 | 8 | module Fastlane 9 | module Actions 10 | 11 | class ArgumentManager 12 | def evaluateArgument(argument) 13 | case argument 14 | when '-h' 15 | true 16 | when "-version" 17 | true 18 | when "-code" 19 | true 20 | when "-major" 21 | true 22 | when "-minor" 23 | true 24 | when "-patch" 25 | true 26 | when "-apply" 27 | true 28 | else 29 | false 30 | end 31 | end 32 | 33 | def invalid_argument 34 | UI.message("You have to pass at least one argument: Use -h view all commands") 35 | end 36 | 37 | def missing_required_arguments 38 | UI.message("You have to pass paths to version.yml and pubspec.yml: Use -h for more info") 39 | end 40 | 41 | def commands 42 | " 43 | -h: Access this menu 44 | -version: Reads current version name 45 | -code: Reads current version code 46 | -major: Bumps major version 47 | -minor: Bumps minor version 48 | -patch: Bumps patch version 49 | -apply: Applies version specified from version.yml to pubspec 50 | " 51 | end 52 | end 53 | 54 | class GitReader 55 | def initialize(git_path) 56 | @git = Git.open(git_path) 57 | end 58 | 59 | def get_timestamp 60 | head = @git.object('HEAD') 61 | commit = @git.gcommit(head.sha) 62 | commit.date.to_i 63 | end 64 | end 65 | 66 | class YamlReader 67 | def initialize(yaml_path) 68 | @yamlFile = YAML.load_file(yaml_path) 69 | end 70 | 71 | def field(fieldName) 72 | @yamlFile[fieldName] 73 | end 74 | 75 | def all 76 | @yamlFile 77 | end 78 | end 79 | 80 | class YamlWritter 81 | def initialize(yaml_path) 82 | @yaml_path = yaml_path 83 | end 84 | 85 | def write(yaml) 86 | File.open(@yaml_path, "w") { |file| file.write(yaml.to_yaml) } 87 | end 88 | end 89 | 90 | class FileReader 91 | def initialize(yaml_path) 92 | @yaml_path = yaml_path 93 | end 94 | 95 | def read 96 | IO.readlines(@yaml_path) 97 | end 98 | end 99 | 100 | class FileWritter 101 | def initialize(yaml_path) 102 | @yaml_path = yaml_path 103 | end 104 | 105 | def write(content) 106 | File.open(@yaml_path, "w") { |file| 107 | file.puts(content) 108 | file.close 109 | } 110 | end 111 | end 112 | 113 | class VersionManager 114 | def initialize(yaml_path, pubspec_path, git_path) 115 | @version_reader = YamlReader.new(yaml_path) 116 | @version_writter = YamlWritter.new(yaml_path) 117 | @pubspec_yaml_reader = YamlReader.new(pubspec_path) 118 | @pubspec_file_reader = FileReader.new(pubspec_path) 119 | @pubspec_file_writter = FileWritter.new(pubspec_path) 120 | @git_reader = GitReader.new(git_path) 121 | end 122 | 123 | def get_current_version_name 124 | "#{@version_reader.field('major')}.#{@version_reader.field('minor')}.#{@version_reader.field('patch')}" 125 | end 126 | 127 | def get_current_version_code 128 | @git_reader.get_timestamp - GIT_OFFSET 129 | end 130 | 131 | def bump_major 132 | context = @version_reader.all 133 | context['major'] = context['major'] + 1 134 | context['minor'] = 0 135 | context['patch'] = 0 136 | @version_writter.write(context) 137 | update_pubspec 138 | end 139 | 140 | def bump_minor 141 | context = @version_reader.all 142 | context['minor'] = context['minor'] + 1 143 | context['patch'] = 0 144 | @version_writter.write(context) 145 | update_pubspec 146 | end 147 | 148 | def bump_patch 149 | context = @version_reader.all 150 | context['patch'] = context['patch'] + 1 151 | @version_writter.write(context) 152 | update_pubspec 153 | end 154 | 155 | def update_pubspec 156 | previousVersion = @pubspec_yaml_reader.field('version') 157 | newVersion = "#{get_current_version_name}+#{get_current_version_code}" 158 | newContent = @pubspec_file_reader.read.map { |s| s.gsub(previousVersion, newVersion) } 159 | @pubspec_file_writter.write(newContent) 160 | UI.message("Previous app version: #{previousVersion}") 161 | UI.message("New app version: #{newVersion}") 162 | end 163 | end 164 | 165 | ARGUMENT_MANAGER = ArgumentManager.new() 166 | 167 | class FlutterVersionManagerAction < Action 168 | def self.run(params) 169 | version_path = params[:yml] 170 | pubspec_path = params[:pubspec] 171 | git_path = params[:git_repo] || './' 172 | args = (params[:arguments] || "").split(" ") 173 | 174 | # Paths valid, continue 175 | versionManager = VersionManager.new(version_path, pubspec_path, git_path) 176 | 177 | # Check if the user has passed additional arguments 178 | if(args.include?("-h") || args.include?("-version") || args.include?("-code") || args.include?("-major") || args.include?("-minor") || args.include?("-patch") || args.include?("-apply")) 179 | args.each { |a| 180 | case a 181 | when '-h' 182 | UI.message(ARGUMENT_MANAGER.commands) 183 | when "-version" 184 | UI.message(versionManager.get_current_version_name) 185 | when "-code" 186 | UI.message(versionManager.get_current_version_code) 187 | when "-major" 188 | versionManager.bump_major 189 | when "-minor" 190 | versionManager.bump_minor 191 | when "-patch" 192 | versionManager.bump_patch 193 | when "-apply" 194 | versionManager.update_pubspec 195 | end 196 | } 197 | else 198 | ARGUMENT_MANAGER.invalid_argument 199 | end 200 | end 201 | 202 | def self.description 203 | "Manages app versioning of a Flutter project." 204 | end 205 | 206 | def self.authors 207 | ["Davor Maric", "rubicon-world.com"] 208 | end 209 | 210 | def self.return_value 211 | # If your method provides a return value, you can describe here what it does 212 | end 213 | 214 | def self.details 215 | "App versioning tool for Flutter projects that can be plugged into pipeline via CI/CD" 216 | end 217 | 218 | def self.available_options 219 | [ 220 | FastlaneCore::ConfigItem.new( 221 | key: :arguments, 222 | description: "Additional arguments", 223 | optional: true, 224 | type: String), 225 | FastlaneCore::ConfigItem.new( 226 | key: :yml, 227 | description: "Path to version.yml", 228 | optional: false, 229 | type: String), 230 | FastlaneCore::ConfigItem.new( 231 | key: :pubspec, 232 | description: "Path to pubspec.yaml", 233 | optional: false, 234 | type: String), 235 | FastlaneCore::ConfigItem.new( 236 | key: :git_repo, 237 | description: "Path to root folder of git repository", 238 | optional: true, 239 | type: String) 240 | ] 241 | end 242 | 243 | def self.is_supported?(platform) 244 | true 245 | end 246 | end 247 | end 248 | end 249 | -------------------------------------------------------------------------------- /lib/fastlane/plugin/flutter_version_manager/helper/flutter_version_manager_helper.rb: -------------------------------------------------------------------------------- 1 | require 'fastlane_core/ui/ui' 2 | 3 | module Fastlane 4 | UI = FastlaneCore::UI unless Fastlane.const_defined?("UI") 5 | 6 | module Helper 7 | class FlutterVersionManagerHelper 8 | # class methods that you define here become available in your action 9 | # as `Helper::FlutterVersionManagerHelper.your_method` 10 | # 11 | def self.show_message 12 | # Hi! :) 13 | end 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/fastlane/plugin/flutter_version_manager/version.rb: -------------------------------------------------------------------------------- 1 | module Fastlane 2 | module FlutterVersionManager 3 | VERSION = "1.0.0" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__)) 2 | 3 | require 'simplecov' 4 | 5 | # SimpleCov.minimum_coverage 95 6 | SimpleCov.start 7 | 8 | # This module is only used to check the environment is currently a testing env 9 | module SpecHelper 10 | end 11 | 12 | require 'fastlane' # to import the Action super class 13 | require 'fastlane/plugin/flutter_version_manager' # import the actual plugin 14 | 15 | Fastlane.load_actions # load other actions (in case your plugin calls other actions or shared values) 16 | -------------------------------------------------------------------------------- /version.yml: -------------------------------------------------------------------------------- 1 | --- 2 | major: 0 3 | minor: 0 4 | patch: 1 5 | --------------------------------------------------------------------------------