From bfe31b17ee48499ba15ea0d2eab89bd3070c0d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Hal=C3=A1sz?= Date: Thu, 29 Jun 2023 07:16:24 +0200 Subject: [PATCH] feat(CI): RHICOMPL-2852 set up continuous integration --- .github/workflows/ci.yml | 37 +++++++++++++ .github/workflows/deploy.yml | 25 +++++++++ .rubocop.yml | 101 +++++++++++++++++++++++++++++++++++ openscap_parser.gemspec | 3 ++ test/test_helper.rb | 6 +++ 5 files changed, 172 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/deploy.yml create mode 100644 .rubocop.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6992e0e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + branches: + - master + types: [opened, reopened, synchronize] +jobs: + static-analysis: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Setup Ruby and install gems + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + - name: Rubocop + run: bundle exec rubocop --parallel + unit-tests: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Setup Ruby and install gems + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + - name: Run unit tests + run: bin/rake test + - name: Upload code coverage + uses: codecov/codecov-action@v2 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..59e41c8 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,25 @@ +name: Release +on: + push: + branches: + - "master" +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 2 + - name: Install dependencies + run: | + sudo apt-get install -y ruby-bundler + bundle install + - name: Configure git + run: | + git config user.name 'Update-a-Bot' + git config user.email 'insights@redhat.com' + - name: Publish gem + run: git diff --name-only HEAD~1 HEAD | grep lib/openscap_parser/version.rb && bundle exec rake release || echo "There is nothing to release" + env: + GEM_HOST_API_KEY: "${{secrets.GEM_HOST_API_KEY}}" diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..4f795fe --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,101 @@ +AllCops: + NewCops: enable + TargetRubyVersion: 3.1 + Exclude: + - 'db/**/*' + - 'bin/**/*' + - 'bundle/**/*' + - 'config/**/*' + - 'test/fixtures/**/*' + - 'Rakefile' + - 'Gemfile' + - 'vendor/**/*' + +Metrics/ClassLength: + Exclude: + - 'test/**/*' + - 'spec/**/*' + +Metrics/BlockLength: + AllowedMethods: ['included', 'class_methods', 'GraphQL::ObjectType.define'] + Exclude: + - 'test/**/*' + - 'spec/**/*' + +Layout/LineEndStringConcatenationIndentation: + Enabled: false + +Layout/MultilineMethodCallIndentation: + EnforcedStyle: aligned + +Layout/EmptyLinesAroundAttributeAccessor: + Enabled: false + +Layout/EmptyLineBetweenDefs: + EmptyLineBetweenClassDefs: false + +Lint/AmbiguousOperatorPrecedence: + Enabled: false + +Lint/EmptyBlock: + Enabled: false + +Lint/SymbolConversion: + Enabled: false + +Lint/ConstantDefinitionInBlock: + Enabled: false + +Lint/RedundantCopDisableDirective: + Enabled: false + +Lint/MissingSuper: + Enabled: false + +Lint/EmptyFile: + Enabled: false + +Naming/VariableNumber: + Enabled: false + +Security/IoMethods: + Enabled: false + +Style/FileWrite: + Enabled: false + +Style/MapToHash: + Enabled: false + +Style/OpenStructUse: + Enabled: false + +Style/SingleArgumentDig: + Enabled: false + +Style/IfUnlessModifier: + Enabled: false + +Style/OptionalBooleanParameter: + Enabled: false + +Style/RedundantFileExtensionInRequire: + Enabled: false + +Style/GlobalStdStream: + Enabled: false + +Style/SlicingWithRange: + Enabled: false + +Style/RedundantBegin: + Enabled: false + +Style/StringConcatenation: + Mode: conservative + +Style/RedundantAssignment: + Enabled: false + +Style/RedundantRegexpEscape: + Enabled: false diff --git a/openscap_parser.gemspec b/openscap_parser.gemspec index 132609c..6cdd247 100644 --- a/openscap_parser.gemspec +++ b/openscap_parser.gemspec @@ -44,4 +44,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency "shoulda-context" spec.add_development_dependency "pry" spec.add_development_dependency "pry-byebug" + spec.add_development_dependency "rubocop", "~> 1.53.1" + spec.add_development_dependency "simplecov" + spec.add_development_dependency "simplecov-cobertura" end diff --git a/test/test_helper.rb b/test/test_helper.rb index bfcc8ab..f06d7b1 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -6,6 +6,12 @@ require 'shoulda-context' require 'mocha/minitest' +require "simplecov" +SimpleCov.start + +require 'simplecov-cobertura' +SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter + def test(name, &block) test_name = "test_#{name.gsub(/\s+/, '_')}".to_sym defined = method_defined? test_name