Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the gem multijob #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**Description**

Replace this text with a description of the changes in this PR.

-----------------
63 changes: 63 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: CI

on:
push:
branches:
- main

pull_request:

jobs:
test:
name: Test failing spec detector
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7.2
bundler-cache: true
- name: Lint files
run: bundle exec rake rubocop
- name: Run tests
run: bundle exec rake spec
- name: Upload Failures
uses: actions/upload-artifact@v3
with:
name: Failures
path: failures_log_*.yml
- name: Upload Exceptions
uses: actions/upload-artifact@v3
with:
name: Exceptions
path: exceptions_log_*.yml

print_log:
name: Test combine log task
needs: test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7.2
bundler-cache: true
- name: Download Failures
uses: actions/download-artifact@v3
with:
name: Failures
- name: Download Exceptions
uses: actions/download-artifact@v3
with:
name: Exceptions
- name: Run combine_log task
run: bundle exec rake failing_specs_detector:combine_log
- name: Upload log file
uses: actions/upload-artifact@v3
with:
name: failing_specs_log
path: "failing_specs_detector_log.txt"
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@

# rspec failure tracking
.rspec_status

# log files
exceptions_log_*.yml
failures_log_*.yml
failing_specs_detector_log.txt
27 changes: 27 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
inherit_from: .rubocop_todo.yml

AllCops:
NewCops: enable
SuggestExtensions: false

Naming/FileName:
Exclude:
- lib/rubocop-solidus.rb

Metrics/BlockLength:
Exclude:
- 'Rakefile'
- '**/*.rake'
- 'spec/**/*.rb'
- '*.gemspec'

Metrics/MethodLength:
Exclude:
- 'Rakefile'
- '**/*.rake'
- 'spec/**/*.rb'
- '*.gemspec'

Metrics/ClassLength:
Exclude:
- 'tasks/**/*.rb'
56 changes: 56 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-12-27 14:39:52 UTC using RuboCop version 1.57.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
# SupportedStyles: Gemfile, gems.rb, gemspec
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
Gemspec/DevelopmentDependencies:
Exclude:
- 'failing_spec_detector.gemspec'

# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 19

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 12

# Offense count: 1
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'lib/failing_spec_detector/failing_spec_formatter.rb'

# Offense count: 8
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Exclude:
- 'Gemfile'
- 'Rakefile'
- 'bin/console'
- 'failing_spec_detector.gemspec'
- 'lib/failing_spec_detector.rb'
- 'lib/failing_spec_detector/version.rb'
- 'spec/failing_spec_detector_spec.rb'
- 'spec/spec_helper.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: literals, strict
Style/MutableConstant:
Exclude:
- 'lib/failing_spec_detector/version.rb'
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
source "https://rubygems.org"

source 'https://rubygems.org'

# Specify your gem's dependencies in failing_spec_detector.gemspec
gemspec

gem 'pry'
gem 'psych', '~> 4.0.6'
gem 'rspec', '~>3.12'
gem 'rubocop'
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ GEM
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
psych (4.0.6)
stringio
racc (1.7.3)
rainbow (3.1.1)
rake (10.5.0)
Expand Down Expand Up @@ -51,15 +53,18 @@ GEM
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
stringio (3.1.0)
unicode-display_width (2.5.0)

PLATFORMS
arm64-darwin-21
x86_64-linux

DEPENDENCIES
bundler
failing_spec_detector!
pry
psych (~> 4.0.6)
rake (~> 10.0)
rspec (~> 3.12)
rubocop
Expand Down
14 changes: 11 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
import './lib/tasks/failing_spec_detector/combine_log.rake'

task default: %i[
spec
rubocop
]

RuboCop::RakeTask.new
6 changes: 3 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "failing_spec_detector"
require 'bundler/setup'
require 'failing_spec_detector'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand All @@ -10,5 +10,5 @@ require "failing_spec_detector"
# require "pry"
# Pry.start

require "irb"
require 'irb'
IRB.start(__FILE__)
37 changes: 19 additions & 18 deletions failing_spec_detector.gemspec
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@

lib = File.expand_path("../lib", __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "failing_spec_detector/version"
require 'failing_spec_detector/version'

Gem::Specification.new do |spec|
spec.name = "failing_spec_detector"
spec.name = 'failing_spec_detector'
spec.version = FailingSpecDetector::VERSION
spec.authors = ["safa"]
spec.email = ["[email protected]"]
spec.authors = ['safa']
spec.email = ['[email protected]']

spec.summary = 'A tool to detect failing specs and group them by error message'
spec.description = <<~DESCRIPTION
Automatic Failing spec detector.
Introduces a custom rspec formatter to detect failing specs and group them by exception.
DESCRIPTION
spec.homepage = "https://github.com/nebulab/failing_spec_detector"
spec.license = "MIT"
spec.homepage = 'https://github.com/nebulab/failing_spec_detector'
spec.license = 'MIT'
spec.required_ruby_version = '>= 2.7.0'

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
if spec.respond_to?(:metadata)

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/nebulab/failing_spec_detector"
spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = 'https://github.com/nebulab/failing_spec_detector'
# spec.metadata["changelog_uri"] = "https://github.com/nebulab/failing_spec_detector"
else
raise "RubyGems 2.0 or newer is required to protect against " \
"public gem pushes."
raise 'RubyGems 2.0 or newer is required to protect against ' \
'public gem pushes.'
end

# 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
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = "exe"
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.require_paths = ['lib']

spec.add_development_dependency "bundler"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.metadata['rubygems_mfa_required'] = 'true'
end
2 changes: 1 addition & 1 deletion lib/failing_spec_detector.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "failing_spec_detector/version"
require 'failing_spec_detector/version'

module FailingSpecDetector
class Error < StandardError; end
Expand Down
29 changes: 29 additions & 0 deletions lib/failing_spec_detector/combiner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

module FailingSpecDetector
# Combiner class to combine and group the failures by exception
class Combiner
def initialize(exceptions, failures)
@exceptions = exceptions
@failures = failures
@filename = 'failing_specs_detector_log.txt'
end

def combine
File.write(@filename, "Failing spec detector:\n\n\n")
return if @exceptions.empty?

@exceptions.uniq.each do |exception|
File.write(@filename, "#{exception}:\n\n", mode: 'a')
related_examples = @failures.select { |failure| failure.exception == exception }
next if related_examples.empty?

related_examples.each do |failure|
File.write(@filename, "#{failure.backtrace}:\n", mode: 'a')
end
File.write(@filename, "\n\n\n", mode: 'a')
end
File.write(@filename, '----------------------------------------------------------------', mode: 'a')
end
end
end
23 changes: 8 additions & 15 deletions lib/failing_spec_detector/failing_spec_formatter.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require 'rspec/core/formatters/base_text_formatter'
require_relative 'failure'
require 'yaml'

module FailingSpecDetector
class FailingSpecFormatter < RSpec::Core::Formatters::BaseTextFormatter
Expand All @@ -10,32 +12,23 @@ def initialize(output)
super(output)
@failures = []
@exceptions = []
@filename = 'log.txt'
@failures_filename = "failures_log_#{ENV.fetch('TEST_ENV_NUMBER', nil)}.yml"
@exceptions_filename = "exceptions_log_#{ENV.fetch('TEST_ENV_NUMBER', nil)}.yml"
end

def example_failed(failure)
exception = failure.exception.to_s.gsub(/\e\[(\d+)m/, '')

@exceptions << exception unless @exceptions.include?(exception)

failure = Failure.new(exception, failure.formatted_backtrace.join("\n"))

@failures << failure
end

def stop(_notification)
File.open(@filename, 'w') { |f| f.write "Failing spec detector:\n" }
return if @exceptions.empty?

@exceptions.each do |exception|
File.write(@filename, "#{exception}:\n\n", mode: 'a')
related_examples = @failures.select { |failure| failure.exception.to_s.gsub(/\e\[(\d+)m/, '') == exception }
next if related_examples.empty?

related_examples.each do |failure|
File.write(@filename, "#{failure.formatted_backtrace.join("\n")}:\n", mode: 'a')
end
File.write(@filename, "\n\n\n", mode: 'a')
end
File.write(@filename, '----------------------------------------------------------------', mode: 'a')
File.write(@exceptions_filename, YAML.dump(@exceptions), mode: 'w')
File.write(@failures_filename, YAML.dump(@failures), mode: 'w')
end
end
end
Loading
Loading