From 9af8710c75ee324054ddc58751a5b3ebac8736b5 Mon Sep 17 00:00:00 2001 From: Brian Durand Date: Sat, 11 Nov 2023 14:08:36 -0800 Subject: [PATCH 1/3] add regression test --- .github/workflows/continuous_integration.yml | 59 ++++++++++++++++++++ .github/workflows/regression_test.yml | 29 ++++++++++ .standard.yml | 7 +-- CHANGELOG.md | 15 +++++ CHANGE_LOG.md | 9 --- Gemfile | 14 ++--- Rakefile | 20 ++++++- lib/secret_keys.rb | 10 ++-- lib/secret_keys/cli.rb | 14 ++--- spec/spec_helper.rb | 2 +- 10 files changed, 141 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/continuous_integration.yml create mode 100644 .github/workflows/regression_test.yml create mode 100644 CHANGELOG.md delete mode 100644 CHANGE_LOG.md diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml new file mode 100644 index 0000000..86e0074 --- /dev/null +++ b/.github/workflows/continuous_integration.yml @@ -0,0 +1,59 @@ +name: Continuous Integration +on: + push: + branches: + - master + - actions-* + tags: + - v* + pull_request: +env: + BUNDLE_CLEAN: "true" + BUNDLE_PATH: vendor/bundle + BUNDLE_JOBS: 3 + BUNDLE_RETRY: 3 +jobs: + specs: + name: ruby-${{ matrix.ruby }} ${{ matrix.appraisal }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - ruby: "ruby" + standardrb: true + - ruby: "3.2" + - ruby: "3.1" + - ruby: "3.0" + - ruby: "2.7" + - ruby: "2.6" + - ruby: "2.5" + - ruby: "2.4" + env: + BUNDLE_GEMFILE: ${{ matrix.gemfile }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Ruby ${{ matrix.ruby }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + - name: Setup bundler + if: matrix.bundler != '' + run: | + gem uninstall bundler --all + gem install bundler --no-document --version ${{ matrix.bundler }} + - name: Set Appraisal bundle + if: matrix.appraisal != '' && matrix.gemfile == '' + run: | + echo "using gemfile gemfiles/${{ matrix.appraisal }}.gemfile" + bundle config set gemfile "gemfiles/${{ matrix.appraisal }}.gemfile" + cat gemfiles/${{ matrix.appraisal }}.gemfile + - name: Install bundle + run: | + bundle update + - name: Run specs + run: bundle exec rake spec + - name: Run standardrb + if: matrix.standardrb == true + run: bundle exec rake standard diff --git a/.github/workflows/regression_test.yml b/.github/workflows/regression_test.yml new file mode 100644 index 0000000..d186fea --- /dev/null +++ b/.github/workflows/regression_test.yml @@ -0,0 +1,29 @@ +name: Regression Test +on: + workflow_dispatch: + schedule: + - cron: "0 15 * * 1" +env: + BUNDLE_CLEAN: "true" + BUNDLE_PATH: vendor/bundle + BUNDLE_JOBS: 3 + BUNDLE_RETRY: 3 +jobs: + specs: + name: Run specs + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Ruby ${{ matrix.ruby }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ruby + - name: Install bundler + run: | + bundle update + - name: Run specs + run: | + bundle exec rake spec diff --git a/.standard.yml b/.standard.yml index ce1d88f..52fe067 100644 --- a/.standard.yml +++ b/.standard.yml @@ -1,10 +1,7 @@ -# I really just have issues with the automatic "semantic blocks" - ruby_version: 2.4 format: progress ignore: - - '**/*': - - Standard/SemanticBlocks - - Style/StderrPuts + - 'spec/**/*': + - Lint/UselessAssignment diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e8a3209 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,15 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## 1.0.1 (June 01, 2020) + +### Fixed +- Fix missing documentation links + +## v1.0.0 (May 31, 2020) + +### Added +- Initial release diff --git a/CHANGE_LOG.md b/CHANGE_LOG.md deleted file mode 100644 index 49937a2..0000000 --- a/CHANGE_LOG.md +++ /dev/null @@ -1,9 +0,0 @@ -# Changelog - -## v1.0.1 (June 01, 2020) - -- Fix missing documentation links - -## v1.0.0 (May 31, 2020) - -Initial release diff --git a/Gemfile b/Gemfile index c12614c..ddfdead 100644 --- a/Gemfile +++ b/Gemfile @@ -1,13 +1,11 @@ source "https://rubygems.org" -gemspec - -gem "rake" -# Lock standard to a particular version, esp. cause it's still 0.x.x according to Semver -gem "standard", "0.4.6" +gemspec -gem "rspec", "~> 3.9" +gem "climate_control" +gem "rspec", "~> 3.10" +gem "appraisal" +gem "standard", "~> 1.0" +gem "simplecov", "~> 0.21", require: false gem "yard" - -gem "climate_control" diff --git a/Rakefile b/Rakefile index d0884e5..1cc04ce 100644 --- a/Rakefile +++ b/Rakefile @@ -1,11 +1,29 @@ +begin + require "bundler/setup" +rescue LoadError + puts "You must `gem install bundler` and `bundle install` to run rake tasks" +end + +require "yard" +YARD::Rake::YardocTask.new(:yard) + require "bundler/gem_tasks" + +task :release do + unless `git rev-parse --abbrev-ref HEAD`.chomp == "main" + warn "Gem can only be released from the main branch" + exit 1 + end +end + require "rspec/core/rake_task" -require "standard/rake" RSpec::Core::RakeTask.new(:spec) task default: :spec +require "standard/rake" + task :console do require File.join(__dir__, "lib/secret_keys") require "irb" diff --git a/lib/secret_keys.rb b/lib/secret_keys.rb index bd3a6e1..9c24f29 100644 --- a/lib/secret_keys.rb +++ b/lib/secret_keys.rb @@ -44,7 +44,7 @@ def initialize(path_or_stream, encryption_key = nil) def to_h @values end - alias to_hash to_h + alias_method :to_hash, :to_h # Mark the key as being encrypted when the JSON is saved. # @@ -94,11 +94,9 @@ def save(path, format: nil) format ||= @format format = format.to_s.downcase - output = (format == "yaml" ? YAML.dump(encrypted) : JSON.pretty_generate(encrypted)) + output = ((format == "yaml") ? YAML.dump(encrypted) : JSON.pretty_generate(encrypted)) output << $/ unless output.end_with?($/) # ensure file ends with system dependent new line - File.open(path, "w") do |file| - file.write(output) - end + File.write(path, output) nil end @@ -272,7 +270,7 @@ def equal_encrypted_values?(value_1, value_2) decrypt_val_1 = decrypt_value(value_1) decrypt_val_2 = decrypt_value(value_2) if decrypt_val_1 == decrypt_val_2 - if value_1 == decrypt_val_1 || value_2 == decrypt_val_2 + if value_1 == decrypt_val_1 || value_2 == decrypt_val_2 # rubocop:disable Style/IfWithBooleanLiteralBranches false else true diff --git a/lib/secret_keys/cli.rb b/lib/secret_keys/cli.rb index 8d7a47d..f599f48 100644 --- a/lib/secret_keys/cli.rb +++ b/lib/secret_keys/cli.rb @@ -3,7 +3,7 @@ require "optparse" require "io/console" -require_relative "../secret_keys.rb" +require_relative "../secret_keys" module SecretKeys::CLI class Base @@ -47,7 +47,7 @@ def format def encrypted_file_contents encrypted = secrets.encrypted_hash - string = (format == :yaml ? YAML.dump(encrypted) : JSON.pretty_generate(encrypted)) + string = ((format == :yaml) ? YAML.dump(encrypted) : JSON.pretty_generate(encrypted)) string << $/ unless string.end_with?($/) # ensure file ends with system dependent new line string end @@ -166,8 +166,8 @@ def run! @secrets = SecretKeys.new({}, secret_key) if input.is_a?(String) if File.exist?(input) - STDERR.puts "Error: Cannot init preexisting file '#{input}'" - STDERR.puts "You may want to try calling `secret_keys encrypt/edit` instead" + warn "Error: Cannot init preexisting file '#{input}'" + warn "You may want to try calling `secret_keys encrypt/edit` instead" exit 1 end @@ -220,9 +220,7 @@ def run! raise ArgumentError, "Cannot perform in place editing on streams" unless @input.is_a?(String) # make sure we read the file **before** writing to it. contents = encrypted_file_contents - File.open(@input, "w") do |file| - file.write(contents) - end + File.write(@input, contents) else $stdout.write(encrypted_file_contents) $stdout.flush @@ -237,7 +235,7 @@ def action_name def run! decrypted = secrets.to_h - string = (format == :yaml ? YAML.dump(decrypted) : JSON.pretty_generate(decrypted)) + string = ((format == :yaml) ? YAML.dump(decrypted) : JSON.pretty_generate(decrypted)) string << $/ unless string.end_with?($/) # ensure file ends with system dependent new line $stdout.write(string) $stdout.flush diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 351e6a7..7913c7f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,4 @@ -require_relative "../lib/secret_keys.rb" +require_relative "../lib/secret_keys" require "tempfile" require "climate_control" From fef1cb304934217f14ec93280cb5cda7ca8eed18 Mon Sep 17 00:00:00 2001 From: Brian Durand Date: Sat, 11 Nov 2023 14:14:25 -0800 Subject: [PATCH 2/3] remove old test file --- .github/workflows/test.yml | 55 -------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 2865fa9..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: Run tests -on: - push: - branches: - - master - tags: - - v* - pull_request: -env: - BUNDLE_CLEAN: "true" - BUNDLE_PATH: vendor/bundle - BUNDLE_JOBS: 3 - BUNDLE_RETRY: 3 -jobs: - specs: - name: ruby-${{ matrix.ruby }} ${{ matrix.appraisal }} - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - include: - - ruby: "ruby" - standardrb: true - - ruby: "3.2" - - ruby: "3.1" - - ruby: "3.0" - - ruby: "2.7" - - ruby: "2.6" - - ruby: "2.5" - - ruby: "2.4" - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Set up Ruby ${{ matrix.ruby }} - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - - name: Setup bundler - if: matrix.bundler != '' - run: | - gem uninstall bundler --all - gem install bundler --no-document --version ${{ matrix.bundler }} - - name: Set Appraisal bundle - if: matrix.appraisal != '' - run: | - echo "using gemfile gemfiles/${{ matrix.appraisal }}.gemfile" - bundle config set gemfile "gemfiles/${{ matrix.appraisal }}.gemfile" - - name: Install bundle - run: | - bundle update - - name: Run specs - run: bundle exec rake spec - - name: Run standardrb - if: matrix.standardrb == true - run: bundle exec standardrb From f2ce264ff084019a98e3b90b5e6347283224b493 Mon Sep 17 00:00:00 2001 From: Brian Durand Date: Sat, 11 Nov 2023 14:15:25 -0800 Subject: [PATCH 3/3] unlock simplecov --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index ddfdead..27c754e 100644 --- a/Gemfile +++ b/Gemfile @@ -7,5 +7,5 @@ gem "climate_control" gem "rspec", "~> 3.10" gem "appraisal" gem "standard", "~> 1.0" -gem "simplecov", "~> 0.21", require: false +gem "simplecov", require: false gem "yard"