flakie 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 75a64b188fc68b39cab7b3aabff3dfbd63300475f2d0d185a0577b251c91160e
4
+ data.tar.gz: 2d1df7b06d7bf31d67b97008cf0439de8bf69ef98735d922973430e4a064126f
5
+ SHA512:
6
+ metadata.gz: 77220c649e9b013180760cee5306b0abd1db9cf047f1c684e92cd85127e06f11dc77f60c52f76b4f6ecd7ea7f54c285e3876b614f2c374e85fe4924d42ca231f
7
+ data.tar.gz: 5e2314d28ae93bfb3123cd0c49491801756178280bb001caef0f4d96691127b2fc1b7c21552a751fd7750030723e670a48eae766b6f7a94f6f8e52179477a25d
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,43 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rake
4
+ - rubocop-rspec
5
+
6
+ inherit_gem:
7
+ syntax_tree: config/rubocop.yml
8
+
9
+ AllCops:
10
+ NewCops: enable
11
+ TargetRubyVersion: 3.0
12
+
13
+ Gemspec/RequireMFA:
14
+ Enabled: false
15
+
16
+ Layout/LineLength:
17
+ Max: 120
18
+
19
+ Lint/StructNewOverride:
20
+ Enabled: false
21
+
22
+ Metrics/AbcSize:
23
+ Enabled: false
24
+
25
+ Metrics/MethodLength:
26
+ Enabled: false
27
+
28
+ Style/Documentation:
29
+ Enabled: false
30
+
31
+ Style/ModuleFunction:
32
+ Enabled: false
33
+
34
+ Style/SpecialGlobalVars:
35
+ Enabled: false
36
+
37
+ Style/StringLiterals:
38
+ Enabled: true
39
+ EnforcedStyle: double_quotes
40
+
41
+ Style/StringLiteralsInInterpolation:
42
+ Enabled: true
43
+ EnforcedStyle: double_quotes
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-3.2.2
data/.streerc ADDED
@@ -0,0 +1,4 @@
1
+ --ignore-files='Gemfile'
2
+ --ignore-files='vendor/bundle/**/*'
3
+ --print-width=120
4
+ --plugins=plugin/trailing_comma
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at ikhurramraza@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Khurram Raza
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # Flakie
2
+
3
+ Runs the provided command to calculate its flakyness.
4
+
5
+ ## 💿 Installation
6
+
7
+ ```bash
8
+ gem install flakie
9
+ ```
10
+
11
+ ## 🚀 Publishing
12
+
13
+ 1. Bump the version in `lib/flakie/version.rb` file in a PR.
14
+
15
+ 2. Create and push tag to GitHub.
16
+
17
+ ```bash
18
+ git tag --sing -a "v[VERSION_TAG]" -m "[VERSION_TAG]"
19
+
20
+ git push origin "v[VERSION_TAG]"
21
+ ```
22
+
23
+ 3. Wait for Release GitHub action to complete.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/exe/flakie ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require "flakie"
6
+
7
+ Flakie::CLI.run(ARGV)
data/lefthook.yml ADDED
@@ -0,0 +1,17 @@
1
+ skip_output:
2
+ - meta
3
+ - summary
4
+ - success
5
+ - execution
6
+
7
+ pre-commit:
8
+ parallel: true
9
+ commands:
10
+ rspec:
11
+ run: bundle exec rspec
12
+ rubocop:
13
+ files: git ls-files **/*.rb
14
+ run: bundle exec rubocop --fail-fast {files}
15
+ stree:
16
+ files: git ls-files **/*.rb
17
+ run: bundle exec stree check {files}
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flakie
4
+ module CLI
5
+ Options =
6
+ Struct.new(:count, :env, :format, :output, :help, :version) do
7
+ def self.default = new(count: 5, env: {}, format: :tictactoe, output: $stdout, help: false, version: false)
8
+ def self.from(args) = default.tap { |options| Parser.parse!(args, into: options) }
9
+
10
+ def []=(key, value)
11
+ if key == :env
12
+ add_env(value)
13
+ else
14
+ super
15
+ end
16
+ end
17
+
18
+ def add_env(raw)
19
+ name, value = raw.split("=")
20
+ CLI.exit_with_error("Bad env variable format: #{raw}") if name.nil? || value.nil?
21
+
22
+ env[name] = value
23
+ end
24
+
25
+ def formatter = Formatters::ALL.fetch(format)
26
+
27
+ def help? = help
28
+ def version? = version
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flakie
4
+ module CLI
5
+ Parser =
6
+ OptionParser.new do |opts|
7
+ opts.banner = "USAGE: #{PROGRAM_NAME} [OPTIONS] COMMAND"
8
+ opts.separator ""
9
+
10
+ opts.version = "#{PROGRAM_NAME} #{VERSION}"
11
+
12
+ opts.separator "OPTIONS:"
13
+ opts.on("-n", "--count COUNT", Integer, "Number of tries (default: #{Options.default.count})")
14
+
15
+ opts.on("-f", "--format FORMATTER", "Output format. See FORMATTERS section below.") do |choice|
16
+ Formatters::ALL.include?(choice.to_sym) ? choice.to_sym : CLI.exit_with_error("Invalid format: #{choice}")
17
+ end
18
+
19
+ opts.on("-o", "--output FILE", "File to output result. Defaults to STDOUT.") { |path| File.open(path, "w") }
20
+
21
+ opts.on("-e", "--env KEY_VALUE", "Additional environment variables to set. Can be called multiple times.")
22
+
23
+ opts.on("-v", "--version", "Show the version")
24
+ opts.on("-h", "--help", "Show this help message")
25
+ opts.separator ""
26
+
27
+ opts.separator "FORMATTERS:"
28
+ opts.separator ' tictactoe - Outputs "o" for success and "x" for failures (default)'
29
+ opts.separator ""
30
+
31
+ opts.separator "EXAMPLES:"
32
+ opts.separator " #{PROGRAM_NAME} rails t test/foo_test.rb"
33
+ opts.separator " #{PROGRAM_NAME} -n10 rails t test/foo_test.rb"
34
+ opts.separator " #{PROGRAM_NAME} -count=10 rails t test/foo_test.rb"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flakie
4
+ module CLI
5
+ class Runner
6
+ def initialize(args)
7
+ @args = args
8
+ @options = Options.from(args)
9
+ end
10
+
11
+ def call
12
+ case options
13
+ in help: true
14
+ Parser.help.display
15
+ in version: true
16
+ Parser.version.display
17
+ else
18
+ Engine.new(
19
+ args.join(" "),
20
+ count: options.count,
21
+ env: options.env,
22
+ reporter: options.formatter.new(options.output),
23
+ ).run
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :options, :args
30
+ end
31
+ end
32
+ end
data/lib/flakie/cli.rb ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flakie
4
+ module CLI
5
+ PROGRAM_NAME = "flakie"
6
+
7
+ def self.run(args)
8
+ Runner.new(args).call
9
+ end
10
+
11
+ def self.exit_with_error(msg)
12
+ warn(msg)
13
+ exit 1
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flakie
4
+ class Engine
5
+ Run =
6
+ Data.define(:status, :duration, :number) do
7
+ def success? = status == true
8
+ def failure? = status == true
9
+ end
10
+
11
+ Report = Data.define(:runs) { def last_run = runs.last }
12
+
13
+ def initialize(command, count:, env:, reporter:)
14
+ @command = command
15
+ @count = count
16
+ @env = env
17
+ @reporter = reporter
18
+ @report = Report.new([])
19
+ end
20
+
21
+ def run
22
+ reporter.open
23
+
24
+ count.times do |index|
25
+ start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
26
+ system(env, command, out: File::NULL, err: File::NULL)
27
+ end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
28
+ duration = (end_time - start_time).round
29
+ report.runs.append Run.new(status: $?.success?, duration: duration, number: index + 1)
30
+ reporter.report(report)
31
+ end
32
+
33
+ reporter.close
34
+ end
35
+
36
+ private
37
+
38
+ attr_reader :command, :count, :env, :reporter, :report
39
+ end
40
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flakie
4
+ module Formatters
5
+ class Base
6
+ def initialize(output)
7
+ @output = output
8
+ end
9
+
10
+ def open
11
+ output.sync ||= true
12
+ end
13
+
14
+ def close
15
+ output.close unless output.tty?
16
+ end
17
+
18
+ def report(_report)
19
+ raise NotImplementedError, "Base formatter class must implement this method"
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :output
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flakie
4
+ module Formatters
5
+ class TicTacToe < Base
6
+ CHARACTER_SUCCESS = "o"
7
+ CHARACTER_FAILURE = "x"
8
+ CHARACTER_SUCCESS_COLORED = "\e[32m#{CHARACTER_SUCCESS}\e[0m".freeze
9
+ CHARACTER_FAILURE_COLORED = "\e[31m#{CHARACTER_FAILURE}\e[0m".freeze
10
+ CHARACTER_NEWLINE = "\n"
11
+
12
+ def open
13
+ end
14
+
15
+ def report(report)
16
+ report.last_run.success? ? report_success : report_failure
17
+ end
18
+
19
+ def close
20
+ output.puts(CHARACTER_NEWLINE)
21
+ super
22
+ end
23
+
24
+ private
25
+
26
+ def report_success
27
+ character = output.tty? ? CHARACTER_SUCCESS_COLORED : CHARACTER_SUCCESS
28
+ output.write(character)
29
+ end
30
+
31
+ def report_failure
32
+ character = output.tty? ? CHARACTER_FAILURE_COLORED : CHARACTER_FAILURE
33
+ output.write(character)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flakie
4
+ module Formatters
5
+ ALL = { tictactoe: TicTacToe }.freeze
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Flakie
4
+ VERSION = "1.0.0"
5
+ end
data/lib/flakie.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ autoload(:Zeitwerk, "zeitwerk")
4
+ autoload(:OptionParser, "optparse")
5
+
6
+ Zeitwerk::Loader.for_gem.tap do |loader|
7
+ loader.inflector.inflect("cli" => "CLI")
8
+ loader.setup
9
+ end
10
+
11
+ module Flakie
12
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flakie
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Khurram Raza
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-11-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: zeitwerk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.6.12
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.6.12
27
+ description: Test flakyness of commands
28
+ email:
29
+ - ikhurramraza@gmail.com
30
+ executables:
31
+ - flakie
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - ".ruby-version"
38
+ - ".streerc"
39
+ - CODE_OF_CONDUCT.md
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - exe/flakie
44
+ - lefthook.yml
45
+ - lib/flakie.rb
46
+ - lib/flakie/cli.rb
47
+ - lib/flakie/cli/options.rb
48
+ - lib/flakie/cli/parser.rb
49
+ - lib/flakie/cli/runner.rb
50
+ - lib/flakie/engine.rb
51
+ - lib/flakie/formatters.rb
52
+ - lib/flakie/formatters/base.rb
53
+ - lib/flakie/formatters/tic_tac_toe.rb
54
+ - lib/flakie/version.rb
55
+ homepage: https://github.com/ikhurramraza/flakie.git
56
+ licenses:
57
+ - MIT
58
+ metadata:
59
+ homepage_uri: https://github.com/ikhurramraza/flakie.git
60
+ source_code_uri: https://github.com/ikhurramraza/flakie.git
61
+ rubygems_mfa_required: 'false'
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '3.0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubygems_version: 3.4.10
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Test flakyness of commands
81
+ test_files: []