diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..6cf17b4 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,32 @@ +name: Test + +on: + push: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/cache@v1 + with: + path: fastlane-plugin-dotenv_vault/vendor/bundle + key: ${{ runner.os }}-gem-fastlane-${{ hashFiles('fastlane-plugin-dotenv_vault/Gemfile') }} + restore-keys: | + ${{ runner.os }}-gem-fastlane + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.0 + working-directory: 'fastlane-plugin-dotenv_vault/' + - name: Install dependencies + run: bundle check || bundle install --jobs=4 --retry=3 --path vendor/bundle + working-directory: 'fastlane-plugin-dotenv_vault/' + - name: Run tests + run: bundle exec rake + working-directory: 'fastlane-plugin-dotenv_vault/' + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: fastlane-test-results + path: 'fastlane-plugin-dotenv_vault/test-results' diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..f592a66 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,190 @@ +--- +require: +- rubocop/require_tools +- rubocop-performance +AllCops: + TargetRubyVersion: 2.6 + NewCops: enable + Include: + - "**/*.rb" + - "**/*file" + - "**/*.gemspec" + - "*/lib/assets/*Template" + - "*/lib/assets/*TemplateAndroid" + Exclude: + - "**/lib/assets/custom_action_template.rb" + - "**/vendor/**/*" + - "vendor/bundle/**/*" + - "**/lib/assets/DefaultFastfileTemplate" + - "**/lib/assets/MatchfileTemplate" + - "**/spec/fixtures/broken_files/broken_file.rb" + - "**/*.provisionprofile" + - "**/fastlane-plugin-dotenv_vault/fastlane/*" +Lint/ErbNewArguments: + Enabled: false +Style/SlicingWithRange: + Enabled: false +Style/MultipleComparison: + Enabled: false +Style/PercentLiteralDelimiters: + Enabled: false +Style/ClassCheck: + EnforcedStyle: kind_of? +Style/FrozenStringLiteralComment: + Enabled: false +Style/SafeNavigation: + Enabled: false +Performance/RegexpMatch: + Enabled: false +Performance/StringReplacement: + Enabled: false +Style/NumericPredicate: + Enabled: false +Metrics/BlockLength: + Enabled: false +Metrics/ModuleLength: + Enabled: false +Naming/VariableNumber: + Enabled: false +Style/MissingRespondToMissing: + Enabled: false +Style/MultilineBlockChain: + Enabled: false +Style/NumericLiteralPrefix: + Enabled: false +Style/TernaryParentheses: + Enabled: false +Style/EmptyMethod: + Enabled: false +Lint/UselessAssignment: + Exclude: + - "**/spec/**/*" +Require/MissingRequireStatement: + Exclude: + - "**/spec/**/*.rb" + - "**/spec_helper.rb" + - spaceship/lib/spaceship/babosa_fix.rb + - fastlane_core/lib/fastlane_core/ui/disable_colors.rb + - "**/Fastfile" + - "**/*.gemspec" + - rakelib/**/* + - "**/*.rake" + - "**/Rakefile" + - fastlane/**/* + - supply/**/* +Layout/FirstHashElementIndentation: + Enabled: false +Layout/HashAlignment: + Enabled: false +Layout/DotPosition: + Enabled: false +Style/DoubleNegation: + Enabled: false +Style/SymbolArray: + Enabled: false +Layout/HeredocIndentation: + Enabled: false +Style/MixinGrouping: + Exclude: + - "**/spec/**/*" +Lint/SuppressedException: + Enabled: false +Lint/UnusedBlockArgument: + Enabled: false +Lint/AmbiguousBlockAssociation: + Enabled: false +Style/GlobalVars: + Enabled: false +Style/ClassAndModuleChildren: + Enabled: false +Style/SpecialGlobalVars: + Enabled: false +Metrics/AbcSize: + Enabled: false +Metrics/MethodLength: + Enabled: false +Metrics/CyclomaticComplexity: + Enabled: false +Style/WordArray: + MinSize: 19 +Style/SignalException: + Enabled: false +Style/RedundantReturn: + Enabled: false +Style/IfUnlessModifier: + Enabled: false +Style/AndOr: + Enabled: true + EnforcedStyle: conditionals +Metrics/ClassLength: + Max: 320 +Layout/LineLength: + Max: 370 +Metrics/ParameterLists: + Max: 17 +Style/GuardClause: + Enabled: false +Style/StringLiterals: + Enabled: false +Style/ConditionalAssignment: + Enabled: false +Style/RedundantSelf: + Enabled: false +Lint/UnusedMethodArgument: + Enabled: false +Lint/ParenthesesAsGroupedExpression: + Exclude: + - "**/spec/**/*" +Naming/PredicateName: + Enabled: false +Style/PerlBackrefs: + Enabled: false +Layout/SpaceAroundOperators: + Exclude: + - "**/spec/actions_specs/xcodebuild_spec.rb" +Naming/FileName: + Exclude: + - "**/Dangerfile" + - "**/Brewfile" + - "**/Gemfile" + - "**/Podfile" + - "**/Rakefile" + - "**/Fastfile" + - "**/Deliverfile" + - "**/Snapfile" + - "**/Pluginfile" + - "**/*.gemspec" +Style/Documentation: + Enabled: false +Style/MutableConstant: + Enabled: false +Style/ZeroLengthPredicate: + Enabled: false +Style/IfInsideElse: + Enabled: false +Style/CollectionMethods: + Enabled: false +Style/MethodCallWithArgsParentheses: + Enabled: true + IgnoredMethods: + - require + - require_relative + - fastlane_require + - gem + - program + - command + - raise + - attr_accessor + - attr_reader + - desc + - lane + - private_lane + - platform + - to + - not_to + - describe + - it + - be + - context + - before + - after diff --git a/Gemfile.lock b/Gemfile.lock index e37b3af..c12f466 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,8 +29,10 @@ GEM i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) + ast (2.4.2) builder (3.2.4) byebug (11.1.3) + coderay (1.1.3) concurrent-ruby (1.1.10) crass (1.0.6) diff-lcs (1.5.0) @@ -41,6 +43,7 @@ GEM erubi (1.11.0) i18n (1.12.0) concurrent-ruby (~> 1.0) + json (2.6.3) lockbox (1.1.0) loofah (2.19.0) crass (~> 1.0.2) @@ -51,6 +54,12 @@ GEM nokogiri (1.13.9) mini_portile2 (~> 2.8.0) racc (~> 1.4) + parallel (1.22.1) + parser (3.2.1.0) + ast (~> 2.4.1) + pry (0.14.2) + coderay (~> 1.1) + method_source (~> 1.0) racc (1.6.0) rack (2.2.4) rack-test (2.0.2) @@ -67,7 +76,10 @@ GEM rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) + rainbow (3.1.1) rake (12.3.3) + regexp_parser (2.7.0) + rexml (3.2.5) rspec (3.11.0) rspec-core (~> 3.11.0) rspec-expectations (~> 3.11.0) @@ -81,10 +93,31 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.11.0) rspec-support (3.11.0) + rubocop (1.45.1) + json (~> 2.3) + parallel (~> 1.10) + parser (>= 3.2.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.24.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.26.0) + parser (>= 3.2.1.0) + rubocop-capybara (2.17.1) + rubocop (~> 1.41) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (2.18.1) + rubocop (~> 1.33) + rubocop-capybara (~> 2.17) + ruby-progressbar (1.11.0) spring (4.0.0) thor (1.2.1) tzinfo (2.0.5) concurrent-ruby (~> 1.0) + unicode-display_width (2.4.2) zeitwerk (2.6.1) PLATFORMS @@ -94,9 +127,13 @@ DEPENDENCIES byebug dotenv-vault! dotenv-vault-rails! + pry rake (~> 12.0) rspec (~> 3.0) + rubocop + rubocop-rake + rubocop-rspec spring BUNDLED WITH - 2.1.4 + 2.3.19 diff --git a/dotenv-vault-rails.gemspec b/dotenv-vault-rails.gemspec index 8ad0c76..72f378b 100644 --- a/dotenv-vault-rails.gemspec +++ b/dotenv-vault-rails.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new "dotenv-vault-rails" do |spec| # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do - `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|fastlane-plugin-dotenv_vault)/}) } end spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } diff --git a/dotenv-vault.gemspec b/dotenv-vault.gemspec index be13e23..df5097e 100644 --- a/dotenv-vault.gemspec +++ b/dotenv-vault.gemspec @@ -31,4 +31,8 @@ Gem::Specification.new "dotenv-vault" do |spec| spec.add_development_dependency "rake" spec.add_development_dependency "rspec" spec.add_development_dependency "byebug" + spec.add_development_dependency "pry" + spec.add_development_dependency "rubocop" + spec.add_development_dependency "rubocop-rake" + spec.add_development_dependency "rubocop-rspec" end diff --git a/fastlane-plugin-dotenv_vault/.gitignore b/fastlane-plugin-dotenv_vault/.gitignore new file mode 100644 index 0000000..74ebf77 --- /dev/null +++ b/fastlane-plugin-dotenv_vault/.gitignore @@ -0,0 +1,14 @@ +*.gem +Gemfile.lock + +## Documentation cache and generated files: +/.yardoc/ +/_yardoc/ +/doc/ +/rdoc/ +fastlane/README.md +fastlane/report.xml +coverage +test-results + +vendor/bundle \ No newline at end of file diff --git a/fastlane-plugin-dotenv_vault/.rspec b/fastlane-plugin-dotenv_vault/.rspec new file mode 100644 index 0000000..e1f89b5 --- /dev/null +++ b/fastlane-plugin-dotenv_vault/.rspec @@ -0,0 +1,5 @@ +--require spec_helper +--color +--format d +--format RspecJunitFormatter +--out test-results/rspec/rspec.xml diff --git a/fastlane-plugin-dotenv_vault/.travis.yml b/fastlane-plugin-dotenv_vault/.travis.yml new file mode 100644 index 0000000..9530465 --- /dev/null +++ b/fastlane-plugin-dotenv_vault/.travis.yml @@ -0,0 +1,4 @@ +# os: osx # enable this if you need macOS support +language: ruby +rvm: + - 3.0 diff --git a/fastlane-plugin-dotenv_vault/Gemfile b/fastlane-plugin-dotenv_vault/Gemfile new file mode 100644 index 0000000..2e1b1ce --- /dev/null +++ b/fastlane-plugin-dotenv_vault/Gemfile @@ -0,0 +1,6 @@ +source('https://rubygems.org') + +gemspec name: 'fastlane-plugin-dotenv_vault' + +plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') +eval_gemfile(plugins_path) if File.exist?(plugins_path) diff --git a/fastlane-plugin-dotenv_vault/LICENSE b/fastlane-plugin-dotenv_vault/LICENSE new file mode 100644 index 0000000..6b99904 --- /dev/null +++ b/fastlane-plugin-dotenv_vault/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2023 Miles Zimmerman + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/fastlane-plugin-dotenv_vault/README.md b/fastlane-plugin-dotenv_vault/README.md new file mode 100644 index 0000000..7b7618f --- /dev/null +++ b/fastlane-plugin-dotenv_vault/README.md @@ -0,0 +1,80 @@ +# dotenv_vault plugin + +[![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-dotenv_vault) + +## Getting Started + +This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-dotenv_vault`, add it to your project by running: + +```bash +fastlane add_plugin dotenv_vault +``` + +then at the top of your `Fastfile`: + +```ruby +# Fastfile +dotenv_vault + +# or if you want to configure non-standard path to .env.vault file +dotenv_vault( + # vault_path: ".env.vault", +) +``` + +You can also set the `VAULT_PATH` environment variable to configure the path to the `.env.vault` file: + +```bash +$ DOTENV_VAULT_PATH="../.env.vault" \ +fastlane some_lane +``` + +## About dotenv_vault + +Decrypt .env.vault file. + +## Actions + +### dotenv_vault + +Decrypt .env.vault file. + +#### Parameters + +| Parameter | Environment Variable | Default | +| ------------- | -------------------- | ------------ | +| `:vault_path` | `DOTENV_VAULT_PATH` | `.env.vault` | + +## 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`. + +## Run tests for this plugin + +To run both the tests, and code style validation, run + +```bash +rake +``` + +To automatically fix many of the styling issues, use + +```bash +rubocop -a +``` + +## Issues and Feedback + +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. + +## 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/). + +## 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). diff --git a/fastlane-plugin-dotenv_vault/Rakefile b/fastlane-plugin-dotenv_vault/Rakefile new file mode 100644 index 0000000..70a2f74 --- /dev/null +++ b/fastlane-plugin-dotenv_vault/Rakefile @@ -0,0 +1,11 @@ +require 'bundler/gem_tasks' + +require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new + +require 'rubocop/rake_task' +RuboCop::RakeTask.new(:rubocop) do |task| + task.options = ['-c', '../.rubocop.yml'] +end + +task(default: [:spec, :rubocop]) diff --git a/fastlane-plugin-dotenv_vault/fastlane-plugin-dotenv_vault.gemspec b/fastlane-plugin-dotenv_vault/fastlane-plugin-dotenv_vault.gemspec new file mode 100644 index 0000000..eb8cd87 --- /dev/null +++ b/fastlane-plugin-dotenv_vault/fastlane-plugin-dotenv_vault.gemspec @@ -0,0 +1,43 @@ +lib = File.expand_path("lib", __dir__) +$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +require 'fastlane/plugin/dotenv_vault/version' + +Gem::Specification.new do |spec| + spec.name = 'fastlane-plugin-dotenv_vault' + spec.version = Fastlane::DotenvVault::VERSION + spec.authors = ['mileszim', 'motdotla'] + spec.email = ['miles@zim.dev', 'mot@mot.la'] + + spec.summary = 'Decrypt .env.vault file.' + spec.homepage = "https://github.com/dotenv-org/dotenv-vault-ruby" + spec.license = "MIT" + + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = "https://github.com/dotenv-org/dotenv-vault-ruby" + spec.metadata["changelog_uri"] = "https://github.com/dotenv-org/dotenv-vault-ruby" + + spec.metadata["rubygems_mfa_required"] = 'true' + + spec.files = Dir["lib/**/*"] + %w(README.md LICENSE) + spec.require_paths = ['lib'] + + spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0") + + # Don't add a dependency to fastlane or fastlane_re + # since this would cause a circular dependency + + spec.add_dependency('dotenv-vault', '~> 0.10.0') + + spec.add_development_dependency('bundler') + spec.add_development_dependency('fastlane', '>= 2.211.0') + spec.add_development_dependency('pry') + spec.add_development_dependency('rake') + spec.add_development_dependency('rspec') + spec.add_development_dependency('rspec_junit_formatter') + spec.add_development_dependency('rubocop', '1.12.1') + spec.add_development_dependency('rubocop-performance') + spec.add_development_dependency('rubocop-rake') + spec.add_development_dependency('rubocop-require_tools') + spec.add_development_dependency('rubocop-rspec') + spec.add_development_dependency('simplecov') +end diff --git a/fastlane-plugin-dotenv_vault/fastlane/.env b/fastlane-plugin-dotenv_vault/fastlane/.env new file mode 100644 index 0000000..e931ed1 --- /dev/null +++ b/fastlane-plugin-dotenv_vault/fastlane/.env @@ -0,0 +1 @@ +DOTENV_KEY="dotenv://:key_1234567890@dotenv.org/vault/.env.vault?environment=development" diff --git a/fastlane-plugin-dotenv_vault/fastlane/.env.vault b/fastlane-plugin-dotenv_vault/fastlane/.env.vault new file mode 100644 index 0000000..aefabc1 --- /dev/null +++ b/fastlane-plugin-dotenv_vault/fastlane/.env.vault @@ -0,0 +1,13 @@ +#/-------------------.env.vault---------------------/ +#/ cloud-agnostic vaulting standard / +#/ [how it works](https://dotenv.org/env-vault) / +#/--------------------------------------------------/ +DOTENV_VAULT=vlt_1234567890abcdef + +# development +DOTENV_VAULT_DEVELOPMENT="some encrypted data..." +DOTENV_VAULT_DEVELOPMENT_VERSION=19 + +# production +DOTENV_VAULT_PRODUCTION="some encrypted data.." +DOTENV_VAULT_PRODUCTION_VERSION=27 diff --git a/fastlane-plugin-dotenv_vault/fastlane/Fastfile b/fastlane-plugin-dotenv_vault/fastlane/Fastfile new file mode 100644 index 0000000..de8ab84 --- /dev/null +++ b/fastlane-plugin-dotenv_vault/fastlane/Fastfile @@ -0,0 +1,21 @@ +# you want this at the top of your Fastfile +dotenv_vault + +# you can set the :vault_path option explicitly +# if your project has a nested `fastlane/` dir, for example +# +# dotenv_vault(vault_path: '../.env.vault') + +# you can also set the :vault_path option via an ENV var +# this is useful if you want to use the same Fastfile for multiple projects +# +# ENV['DOTENV_VAULT_PATH'] #=> '../.env.vault' + +# be sure to set the DOTENV_KEY env var in the command +# or in the .env when you run this lane +# +# DOTENV_KEY=123 fastlane build_or_something +lane :build_or_something do + puts "DOTENV_KEY: #{ENV.fetch('DOTENV_KEY')}" + puts "EXAMPLE_ENV_VAR: #{ENV.fetch('EXAMPLE_ENV_VAR')}" +end diff --git a/fastlane-plugin-dotenv_vault/fastlane/Pluginfile b/fastlane-plugin-dotenv_vault/fastlane/Pluginfile new file mode 100644 index 0000000..e0576b0 --- /dev/null +++ b/fastlane-plugin-dotenv_vault/fastlane/Pluginfile @@ -0,0 +1 @@ +# Autogenerated by fastlane diff --git a/fastlane-plugin-dotenv_vault/lib/fastlane/plugin/dotenv_vault.rb b/fastlane-plugin-dotenv_vault/lib/fastlane/plugin/dotenv_vault.rb new file mode 100644 index 0000000..1cd0862 --- /dev/null +++ b/fastlane-plugin-dotenv_vault/lib/fastlane/plugin/dotenv_vault.rb @@ -0,0 +1,26 @@ +require 'fastlane/plugin/dotenv_vault/version' +require 'fastlane/plugin/dotenv_vault/logger' + +module Fastlane + module DotenvVault + # Return all .rb files inside the "actions" and "helper" directory + def self.all_classes + Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))] + end + end +end + +# By default we want to import all available actions and helpers +# A plugin can contain any number of actions and plugins +Fastlane::DotenvVault.all_classes.each do |current| + require current +end + +# Monkeypatch DotenvVault.logger +module DotenvVault + class << self + def logger + @logger ||= Fastlane::DotenvVault::Logger.new + end + end +end diff --git a/fastlane-plugin-dotenv_vault/lib/fastlane/plugin/dotenv_vault/actions/dotenv_vault_action.rb b/fastlane-plugin-dotenv_vault/lib/fastlane/plugin/dotenv_vault/actions/dotenv_vault_action.rb new file mode 100644 index 0000000..33318fb --- /dev/null +++ b/fastlane-plugin-dotenv_vault/lib/fastlane/plugin/dotenv_vault/actions/dotenv_vault_action.rb @@ -0,0 +1,53 @@ +require 'fastlane/action' +require 'fastlane_core/configuration/config_item' +require 'dotenv-vault' +require_relative '../helper/dotenv_vault_helper' + +module Fastlane + module Actions + class DotenvVaultAction < Action + def self.run(params) + params.values + + if defined?(::DotenvVault) + ::DotenvVault.load(params[:vault_path]) + end + end + + def self.description + "Decrypt .env.vault file." + end + + def self.authors + ["mileszim", "motdotla"] + end + + def self.return_value + # If your method provides a return value, you can describe here what it does + end + + def self.details + # Optional: + "Extends the proven & trusted foundation of dotenv, with a .env.vault file." + end + + def self.available_options + [ + FastlaneCore::ConfigItem.new(key: :vault_path, + env_name: "DOTENV_VAULT_PATH", + description: "Path to .env.vault file (default is ./.env.vault)", + default_value: ".env.vault", + type: String) + ] + end + + def self.is_supported?(platform) + # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example) + # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform + # + # [:ios, :mac, :android].include?(platform) + true + end + end + end +end diff --git a/fastlane-plugin-dotenv_vault/lib/fastlane/plugin/dotenv_vault/helper/dotenv_vault_helper.rb b/fastlane-plugin-dotenv_vault/lib/fastlane/plugin/dotenv_vault/helper/dotenv_vault_helper.rb new file mode 100644 index 0000000..0029e52 --- /dev/null +++ b/fastlane-plugin-dotenv_vault/lib/fastlane/plugin/dotenv_vault/helper/dotenv_vault_helper.rb @@ -0,0 +1,31 @@ +require 'dotenv-vault' + +module Fastlane + module Helper + class DotenvVaultHelper + def self.load(*filenames) + ::DotenvVault.load(*filenames) + end + + # same as `load`, but raises Errno::ENOENT if any files don't exist + def self.load!(*filenames) + ::DotenvVault.load!(*filenames) + end + + # same as `load`, but will override existing values in `ENV` + def self.overload(*filenames) + ::DotenvVault.overload(*filenames) + end + + # same as `overload`, but raises Errno:ENOENT if any files don't exist + def self.overload!(*filenames) + ::DotenvVault.overload!(*filenames) + end + + # returns a hash of parsed key/value pairs but does not modify ENV + def self.parse(*filenames) + ::DotenvVault.parse(*filenames) + end + end + end +end diff --git a/fastlane-plugin-dotenv_vault/lib/fastlane/plugin/dotenv_vault/logger.rb b/fastlane-plugin-dotenv_vault/lib/fastlane/plugin/dotenv_vault/logger.rb new file mode 100644 index 0000000..aaa8795 --- /dev/null +++ b/fastlane-plugin-dotenv_vault/lib/fastlane/plugin/dotenv_vault/logger.rb @@ -0,0 +1,62 @@ +require 'fastlane_core/ui/ui' + +# Monkeypatch DotenvVault to use fastlane_core ui +module Fastlane + UI = FastlaneCore::UI unless Fastlane.const_defined?(:UI) + + module DotenvVault + class Logger + def debug(message) + UI.verbose(message) + end + + def info(message) + UI.message(message) + end + + def warn(message) + UI.important(message) + end + + def error(message) + UI.error(message) + end + + def fatal(message) + UI.error(message) + end + + def unknown(message) + UI.message(message) + end + + def log(_level, message) + UI.message(message) + end + + def <<(message) + UI.message(message) + end + + def close + # noop + end + + def reopen + # noop + end + + def flush + # noop + end + + def level + # noop + end + + def level=(level) + # noop + end + end + end +end diff --git a/fastlane-plugin-dotenv_vault/lib/fastlane/plugin/dotenv_vault/version.rb b/fastlane-plugin-dotenv_vault/lib/fastlane/plugin/dotenv_vault/version.rb new file mode 100644 index 0000000..c4cd38d --- /dev/null +++ b/fastlane-plugin-dotenv_vault/lib/fastlane/plugin/dotenv_vault/version.rb @@ -0,0 +1,5 @@ +module Fastlane + module DotenvVault + VERSION = "0.10.0" + end +end diff --git a/fastlane-plugin-dotenv_vault/spec/dotenv_vault/actions/dotenv_vault_action_spec.rb b/fastlane-plugin-dotenv_vault/spec/dotenv_vault/actions/dotenv_vault_action_spec.rb new file mode 100644 index 0000000..8251d15 --- /dev/null +++ b/fastlane-plugin-dotenv_vault/spec/dotenv_vault/actions/dotenv_vault_action_spec.rb @@ -0,0 +1,28 @@ +require 'fastlane/plugin/dotenv_vault/actions/dotenv_vault_action' + +describe Fastlane::Actions::DotenvVaultAction do + let(:action) { Fastlane::Actions::DotenvVaultAction } + + describe '#run' do + it 'calls DotenvVault.load' do + expect(DotenvVault).to receive(:load) + params = FastlaneCore::Configuration.create(action.available_options, {}) + action.run(params) + end + + it 'calls DotenvVault.load with DOTENV_VAULT_PATH' do + stub_const('ENV', 'DOTENV_VAULT_PATH' => 'test') + expect(DotenvVault).to receive(:load).with('test') + params = FastlaneCore::Configuration.create(action.available_options, {}) + action.run(params) + end + + it 'calls DotenvVault.load with :vault_path param' do + expect(DotenvVault).to receive(:load).with('test') + params = FastlaneCore::Configuration.create(action.available_options, { + vault_path: 'test' + }) + action.run(params) + end + end +end diff --git a/fastlane-plugin-dotenv_vault/spec/dotenv_vault/helper/dotenv_vault_helper_spec.rb b/fastlane-plugin-dotenv_vault/spec/dotenv_vault/helper/dotenv_vault_helper_spec.rb new file mode 100644 index 0000000..3fbb723 --- /dev/null +++ b/fastlane-plugin-dotenv_vault/spec/dotenv_vault/helper/dotenv_vault_helper_spec.rb @@ -0,0 +1,47 @@ +require 'fastlane/plugin/dotenv_vault/helper/dotenv_vault_helper' + +describe Fastlane::Helper::DotenvVaultHelper do + before do + @filenames = %w[.env .env.test] + end + + describe '.load' do + it 'calls DotenvVault.load' do + expect(DotenvVault).to receive(:load).with(*@filenames) + + described_class.load(*@filenames) + end + end + + describe '.load!' do + it 'calls DotenvVault.load!' do + expect(DotenvVault).to receive(:load!).with(*@filenames) + + described_class.load!(*@filenames) + end + end + + describe '.overload' do + it 'calls DotenvVault.overload' do + expect(DotenvVault).to receive(:overload).with(*@filenames) + + described_class.overload(*@filenames) + end + end + + describe '.overload!' do + it 'calls DotenvVault.overload!' do + expect(DotenvVault).to receive(:overload!).with(*@filenames) + + described_class.overload!(*@filenames) + end + end + + describe '.parse' do + it 'calls DotenvVault.parse' do + expect(DotenvVault).to receive(:parse).with(*@filenames) + + described_class.parse(*@filenames) + end + end +end diff --git a/fastlane-plugin-dotenv_vault/spec/dotenv_vault/logger_spec.rb b/fastlane-plugin-dotenv_vault/spec/dotenv_vault/logger_spec.rb new file mode 100644 index 0000000..09f3607 --- /dev/null +++ b/fastlane-plugin-dotenv_vault/spec/dotenv_vault/logger_spec.rb @@ -0,0 +1,95 @@ +require 'fastlane/plugin/dotenv_vault/logger' + +describe Fastlane::DotenvVault::Logger do + describe '.debug' do + it 'should call UI.verbose' do + expect(Fastlane::UI).to receive(:verbose) + subject.debug('test') + end + end + + describe '.info' do + it 'should call UI.message' do + expect(Fastlane::UI).to receive(:message) + subject.info('test') + end + end + + describe '.warn' do + it 'should call UI.important' do + expect(Fastlane::UI).to receive(:important) + subject.warn('test') + end + end + + describe '.error' do + it 'should call UI.error' do + expect(Fastlane::UI).to receive(:error) + subject.error('test') + end + end + + describe '.fatal' do + it 'should call UI.error' do + expect(Fastlane::UI).to receive(:error) + subject.fatal('test') + end + end + + describe '.unknown' do + it 'should call UI.message' do + expect(Fastlane::UI).to receive(:message) + subject.unknown('test') + end + end + + describe '.log' do + it 'should call UI.message' do + expect(Fastlane::UI).to receive(:message) + subject.log('test', 'test') + end + end + + describe '.<<' do + it 'should call UI.message' do + expect(Fastlane::UI).to receive(:message) + subject << 'test' + end + end + + describe '.close' do + it 'should do nothing' do + expect(subject.close).to be_nil + end + end + + describe '.reopen' do + it 'should do nothing' do + expect(subject.reopen).to be_nil + end + end + + describe '.flush' do + it 'should do nothing' do + expect(subject.flush).to be_nil + end + end + + describe '.level' do + it 'should do nothing' do + expect(subject.level).to be_nil + end + end + + describe '.level=' do + it 'should do nothing' do + expect(subject.level = 'test').to eq('test') + end + end + + describe '.new' do + it 'should return a new Fastlane::DotenvVault::Logger' do + expect(subject).to be_a(Fastlane::DotenvVault::Logger) + end + end +end diff --git a/fastlane-plugin-dotenv_vault/spec/spec_helper.rb b/fastlane-plugin-dotenv_vault/spec/spec_helper.rb new file mode 100644 index 0000000..7be41b4 --- /dev/null +++ b/fastlane-plugin-dotenv_vault/spec/spec_helper.rb @@ -0,0 +1,16 @@ +$LOAD_PATH.unshift(File.expand_path('../lib', __dir__)) + +require 'simplecov' + +# SimpleCov.minimum_coverage 95 +SimpleCov.start + +# This module is only used to check the environment is currently a testing env +module SpecHelper +end + +require 'fastlane' # to import the Action super class +require 'fastlane/plugin/dotenv_vault' # import the actual plugin +require 'pry' + +Fastlane.load_actions # load other actions (in case your plugin calls other actions or shared values) diff --git a/lib/dotenv-vault.rb b/lib/dotenv-vault.rb index 57289e5..9708580 100644 --- a/lib/dotenv-vault.rb +++ b/lib/dotenv-vault.rb @@ -1,8 +1,9 @@ require "uri" require "dotenv" +require "stringio" require "lockbox" -require "dotenv-vault/version" require "logger" +require_relative "./dotenv-vault/version" module DotenvVault class NotFoundDotenvKey < ArgumentError; end