Skip to content

Commit

Permalink
Drop support for ruby versions 2.4 and 2.5 (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
jylitalo authored Nov 26, 2021
1 parent 1490efa commit 192f34b
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: true
matrix:
ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0' ]
ruby: [ '2.6', '2.7', '3.0' ]
name: Test on Ruby ${{ matrix.ruby }}
steps:
- uses: actions/checkout@v2
Expand Down
94 changes: 93 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
AllCops:
TargetRubyVersion: 2.4
NewCops: enable
TargetRubyVersion: 2.6

Gemspec/DateAssignment:
Enabled: true

Gemspec/RequiredRubyVersion:
Severity: warning
Expand All @@ -12,6 +16,58 @@ Layout/LineLength:
Max: 100
Severity: warning

Layout/SpaceBeforeBrackets: # (new in 1.7)
Enabled: true

Lint/AmbiguousAssignment:
Enabled: true

Lint/DeprecatedConstants:
Enabled: true

Lint/DuplicateBranch:
Enabled: true

Lint/DuplicateRegexpCharacterClassElement:
Enabled: true

Lint/EmptyBlock:
Enabled: true
AllowEmptyLambdas: true

Lint/EmptyClass:
Enabled: true

Lint/LambdaWithoutLiteralBlock:
Enabled: true

Lint/NoReturnInBeginEndBlocks:
Enabled: true

Lint/NumberedParameterAssignment:
Enabled: true

Lint/OrAssignmentToConstant:
Enabled: true

Lint/RedundantDirGlobSort:
Enabled: true

Lint/SymbolConversion:
Enabled: true

Lint/ToEnumArguments:
Enabled: true

Lint/TripleQuotes:
Enabled: true

Lint/UnexpectedBlockArity:
Enabled: true

Lint/UnmodifiedReduceAccumulator:
Enabled: true

Metrics/AbcSize:
Max: 16

Expand All @@ -28,15 +84,51 @@ Metrics/MethodLength:
Max: 13
Severity: warning

Style/ArgumentsForwarding:
Enabled: true

Style/CollectionCompact:
Enabled: true

Style/Documentation:
Enabled: false

Style/DocumentDynamicEvalDefinition:
Enabled: true

Style/EndlessMethod:
Enabled: true

Style/GuardClause:
MinBodyLength: 3

Style/HashConversion:
Enabled: true

Style/HashExcept:
Enabled: true

Style/IfWithBooleanLiteralBranches:
Enabled: true

Style/NegatedIf:
Enabled: false

Style/NegatedIfElseCondition:
Enabled: true

Style/NilLambda:
Enabled: true

Style/RedundantArgument:
Enabled: true

Style/StringChars:
Enabled: true

Style/SwapValues:
Enabled: true

Style/TrailingCommaInArrayLiteral:
Enabled: false

Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Compatibility:

- Handle TF_LOG=TRACE in similar fashion as DEBUG ([GH-41](https://github.com/Yleisradio/yle_tf/pull/41/))
- Add Terrafrom 1.0 to tested versions. ([GH-43](https://github.com/Yleisradio/yle_tf/pull/43))
-
- Changed CI environment from Travis-CI to GitHub Actions ([GH-44](https://github.com/Yleisradio/yle_tf/pull/45))
- Dropped support for Ruby versions 2.4 and 2.5 and Terraform versions 0.9 and 0.10. ([GH-45](https://github.com/Yleisradio/yle_tf/pull/46))

Bugfixes:

- Interpret terraform hooks output as UTF-8. ([GH-42](https://github.com/Yleisradio/yle_tf/pull/42) & [GH-44](https://github.com/Yleisradio/yle_tf/pull/44))
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Offers a command-line helper tool, `tf`

YleTf requires Terraform which can be installed according to their [instructions](https://www.terraform.io/intro/getting-started/install.html). On MacOS (and OSX) you can use [Homebrew](https://brew.sh/). You can also easily install and manage multiple versions of Terraform with [homebrew-terraforms](https://github.com/Yleisradio/homebrew-terraforms).

YleTf supports Terraform versions from 0.9 on. Tested versions range from 0.11 to 1.0.
YleTf supports Terraform versions from 0.11 on. Tested versions range from 0.11 to 1.0.

YleTf requires Ruby 2.3 or newer. Tested versions range from 2.4 to 3.0.
YleTf requires Ruby 2.6 or newer. Tested versions range from 2.6 to 3.0.

## Installation

Expand Down
3 changes: 1 addition & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ namespace :test do
"Terraform versions can be passed by a comma/space separated argument or \n" \
'TERRAFORM_VERSIONS environment variable.'
task :acceptance, [:terraform_versions] do |t, args|
# Find all acceptance test tasks
tasks = namespace(t.name) {}.tasks
tasks = namespace(t.name) {}.tasks # Find all acceptance test tasks

TestSupport::Rake.terraform_versions(args, default: 'latest').each do |v|
rake_output_message "#########################################################\n" \
Expand Down
2 changes: 1 addition & 1 deletion lib/yle_tf/action/verify_terraform_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def call(env)
end

def terraform_version
v = YleTf::System.read_cmd('terraform', 'version', error_handler: proc {})
v = YleTf::System.read_cmd('terraform', 'version', error_handler: proc {}) # ignore errors
m = /^Terraform v(?<version>[^\s]+)/.match(v)
m && m[:version]
end
Expand Down
5 changes: 3 additions & 2 deletions lib/yle_tf/config/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class YleTf
class Config
module Defaults
sops_options = '--input-type binary --output-type binary --output "{{TO}}" "{{FROM}}"'
DEFAULT_CONFIG = {
'hooks' => {
'pre' => [],
Expand All @@ -15,8 +16,8 @@ module Defaults
'file' => {
'path' => '<%= @module %>_<%= @env %>.tfstate',
'encrypt' => false,
'encrypt_command' => 'sops --encrypt --input-type binary --output-type binary --output "{{TO}}" "{{FROM}}"',
'decrypt_command' => 'sops --decrypt --input-type binary --output-type binary --output "{{TO}}" "{{FROM}}"'
'encrypt_command' => "sops --encrypt #{sops_options}",
'decrypt_command' => "sops --decrypt #{sops_options}"
},
's3' => {
'key' => '<%= @module %>_<%= @env %>.tfstate'
Expand Down
2 changes: 2 additions & 0 deletions lib/yle_tf/config/erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ def initialize(vars)
vars.each { |key, value| instance_variable_set(:"@#{key}", value) }
end

# rubocop:disable Lint/UselessMethodDefinition
def binding
super
end
# rubocop:enable Lint/UselessMethodDefinition
end

def self.evaluate(string, vars = {})
Expand Down
2 changes: 1 addition & 1 deletion lib/yle_tf/config/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def evaluate_configuration_strings(config)
def eval_config(config)
case config
when Hash
config.each_with_object({}) { |(key, value), h| h[key] = eval_config(value) }
config.transform_values { |value| eval_config(value) }
when Array
config.map { |item| eval_config(item) }
when String
Expand Down
2 changes: 2 additions & 0 deletions lib/yle_tf/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class YleTf
# Prints to STDERR, so it does not mess with e.g. `terraform output`.
module Logger
LEVELS = %i[debug info warn error fatal].freeze
# rubocop:disable Style/GlobalStdStream
DEVICE = STDERR
# rubocop:enable Style/GlobalStdStream

# Default to colorful error messages on a TTY
@color = DEVICE.respond_to?(:tty?) && DEVICE.tty?
Expand Down
16 changes: 8 additions & 8 deletions lib/yle_tf/system/io_handlers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class System
class IOHandlers
BLOCK_SIZE = 1024

# rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
# rubocop:disable Metrics/MethodLength
def self.input_handler(handler)
case handler
when :close
Expand Down Expand Up @@ -49,13 +49,14 @@ def self.output_handler(handler)
handler
end
end
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength
# rubocop:enable Metrics/MethodLength

# Returns a lambda that just closes the IO
def self.close
->(io, *) { io.close }
end

# rubocop:disable Style/GlobalStdStream
# Returns a lambda that pipes STDIN to the IO
def self.console_input
io_input(STDIN)
Expand All @@ -65,6 +66,7 @@ def self.console_input
def self.console_output
io_output(STDOUT)
end
# rubocop:enable Style/GlobalStdStream

# Returns a lambda that does nothing
def self.dev_null_input
Expand All @@ -75,11 +77,9 @@ def self.dev_null_input
def self.dev_null_output
lambda do |io, *|
Thread.new do
begin
while io.read; end
rescue IOError => e
YleTf::Logger.debug e.full_message
end
while io.read; end
rescue IOError => e
YleTf::Logger.debug e.full_message
end
end
end
Expand Down Expand Up @@ -108,7 +108,7 @@ def self.copy_data(source, target, **opts)
while (data = source.readpartial(BLOCK_SIZE))
target.write(data)
end
rescue EOFError # rubocop:disable Lint/SuppressedException
rescue EOFError
# All read
rescue IOError => e
YleTf::Logger.debug e.full_message
Expand Down
8 changes: 3 additions & 5 deletions lib/yle_tf/system/output_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ def initialize(level)

def call(io, progname)
Thread.new do
begin
io.each { |line| log(progname, line.chomp) }
rescue IOError => e
YleTf::Logger.debug e.full_message
end
io.each { |line| log(progname, line.chomp) }
rescue IOError => e
YleTf::Logger.debug e.full_message
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/yle_tf/system/tf_hook_output_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TfHookOutputLogger < OutputLogger
def log(progname, line)
# Remove `[<progname>] ` prefix from the output line.
# This is mostly for backwards compatibility in Yle.
level = "INFO".downcase.to_sym
level = 'INFO'.downcase.to_sym
begin
newline = line.force_encoding(Encoding::UTF_8).sub(/^\[#{progname}\] /, '')
level, line = line_level(newline)
Expand Down
2 changes: 1 addition & 1 deletion lib/yle_tf/tf_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def run(tf_vars)
end

def parse_source_config
m = %r{^(?<uri>.+)//(?<path>[^?]+)(\?ref=(?<ref>.*))?$}.match(source)
m = %r{^(?<uri>.+)//(?<path>[^?]+)(?<query_string>\?ref=(?<ref>.*))?$}.match(source)
raise Error, "Invalid or missing `source` for hook '#{description}'" if !m

{
Expand Down
2 changes: 1 addition & 1 deletion lib/yle_tf_plugins/commands/help/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def error?(env)
end

def device(env)
error?(env) ? STDERR : STDOUT
error?(env) ? $stderr : $stdout
end

def tf_command_help
Expand Down
2 changes: 1 addition & 1 deletion test/unit/yle_tf/tf_hook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
end
let(:description) { 'Hook description' }
let(:source) { 'git@git.example.com:organization/repo.git//hook/path' }
let(:vars) {}
let(:vars) {} # defined for readability
let(:env) { 'spec' }

describe '#description' do
Expand Down
2 changes: 1 addition & 1 deletion yle_tf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
spec.executables = ['tf']
spec.require_paths = ['lib']

spec.required_ruby_version = '>= 2.3'
spec.required_ruby_version = '>= 2.6'

spec.add_runtime_dependency 'thwait', '~> 0.2.0'

Expand Down

0 comments on commit 192f34b

Please sign in to comment.