towel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +7 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +6 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +43 -0
  9. data/Rakefile +19 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/extensions/towel-minitest/.gitignore +8 -0
  13. data/extensions/towel-minitest/Gemfile +6 -0
  14. data/extensions/towel-minitest/README.md +43 -0
  15. data/extensions/towel-minitest/Rakefile +10 -0
  16. data/extensions/towel-minitest/bin/console +14 -0
  17. data/extensions/towel-minitest/bin/setup +8 -0
  18. data/extensions/towel-minitest/examples/.towel.toml +37 -0
  19. data/extensions/towel-minitest/examples/parallel_test.rb +29 -0
  20. data/extensions/towel-minitest/examples/simple_spec.rb +25 -0
  21. data/extensions/towel-minitest/examples/simple_test.rb +35 -0
  22. data/extensions/towel-minitest/lib/minitest/towel_plugin.rb +12 -0
  23. data/extensions/towel-minitest/lib/towel/minitest/reporter.rb +102 -0
  24. data/extensions/towel-minitest/lib/towel/minitest/version.rb +5 -0
  25. data/extensions/towel-minitest/lib/towel/minitest.rb +13 -0
  26. data/extensions/towel-minitest/test/test_helper.rb +4 -0
  27. data/extensions/towel-minitest/test/towel/minitest_test.rb +11 -0
  28. data/extensions/towel-minitest/towel-minitest.gemspec +41 -0
  29. data/extensions/towel-rspec/.gitignore +9 -0
  30. data/extensions/towel-rspec/.rspec +1 -0
  31. data/extensions/towel-rspec/Gemfile +6 -0
  32. data/extensions/towel-rspec/README.md +43 -0
  33. data/extensions/towel-rspec/Rakefile +10 -0
  34. data/extensions/towel-rspec/bin/console +14 -0
  35. data/extensions/towel-rspec/bin/setup +8 -0
  36. data/extensions/towel-rspec/examples/.rspec +2 -0
  37. data/extensions/towel-rspec/examples/simple_spec.rb +22 -0
  38. data/extensions/towel-rspec/lib/towel/rspec/formatter.rb +63 -0
  39. data/extensions/towel-rspec/lib/towel/rspec/version.rb +5 -0
  40. data/extensions/towel-rspec/lib/towel/rspec.rb +13 -0
  41. data/extensions/towel-rspec/spec/spec_helper.rb +100 -0
  42. data/extensions/towel-rspec/towel-rspec.gemspec +41 -0
  43. data/generated/.gitignore +1 -0
  44. data/generated/towel/v1alpha/collector_pb.rb +61 -0
  45. data/generated/towel/v1alpha/collector_services_pb.rb +41 -0
  46. data/generated/towel/v1alpha/towel_pb.rb +88 -0
  47. data/lib/towel/configuration.rb +82 -0
  48. data/lib/towel/environment.rb +64 -0
  49. data/lib/towel/log.rb +100 -0
  50. data/lib/towel/log_io.rb +71 -0
  51. data/lib/towel/session.rb +199 -0
  52. data/lib/towel/version.rb +3 -0
  53. data/lib/towel.rb +30 -0
  54. data/towel.gemspec +45 -0
  55. metadata +214 -0
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in towel-rspec.gemspec
6
+ gemspec
@@ -0,0 +1,43 @@
1
+ # Towel::Rspec
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/towel/rspec`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'towel-rspec'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install towel-rspec
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/towel-rspec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Towel::Rspec project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/towel-rspec/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "towel/rspec"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,2 @@
1
+ --require towel/rspec
2
+ --format Towel::RSpec::Formatter
@@ -0,0 +1,22 @@
1
+ Foo = Class.new
2
+
3
+ RSpec.describe Foo do
4
+ describe "#foo" do
5
+ it "acts normally" do
6
+ puts "OK"
7
+ end
8
+
9
+ it "stays cool"
10
+ it "never gives up"
11
+ end
12
+
13
+ describe "#bar" do
14
+ it "is a little unsure of itself" do
15
+ raise ArgumentError, "Not sure of myself"
16
+ end
17
+
18
+ it "needs affirmation" do
19
+ expect(false).to eq(true)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,63 @@
1
+ require "rspec/core/formatters/base_formatter"
2
+
3
+ module Towel
4
+ module RSpec
5
+ # Takes RSpec events and turns them into a streaming upload to Towel.
6
+ class Formatter < ::RSpec::Core::Formatters::BaseFormatter
7
+ ::RSpec::Core::Formatters.register self, :start,
8
+ :example_started,
9
+ :example_finished,
10
+ :close
11
+
12
+ def initialize(io)
13
+ super(io)
14
+ @session = Towel::Session.new
15
+ end
16
+
17
+ def start(_notification)
18
+ super
19
+ url = @session.create_invocation
20
+ puts "View test results at #{url}"
21
+ end
22
+
23
+ def example_started(notification)
24
+ example_group = notification.example.example_group
25
+ example = notification.example
26
+ group = example_group.described_class.to_s + example_group.description
27
+
28
+ puts "CALLING create_result(#{group.inspect}, #{example.id.inspect})"
29
+ context = @session.create_result(
30
+ group,
31
+ example.id,
32
+ display_name: example.description
33
+ )
34
+ end
35
+
36
+ def example_finished(notification)
37
+ example_group = notification.example.example_group
38
+ example = notification.example
39
+ group = example_group.described_class.to_s + example_group.description
40
+
41
+ state = case example.execution_result.status
42
+ when :passed then Towel::ResultState::PASSED
43
+ when :failed then Towel::ResultState::FAILURE
44
+ when :pending then Towel::ResultState::SKIPPED
45
+ else
46
+ status = example.execution_result.status
47
+ raise RuntimeError, "Unknown RSpec result state '#{status}'"
48
+ end
49
+
50
+ @session.update_result(
51
+ group,
52
+ example.id,
53
+ state: state
54
+ )
55
+ end
56
+
57
+ def close(_notification)
58
+ super
59
+ @session.finish_invocation
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,5 @@
1
+ module Towel
2
+ module RSpec
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ # Gems
2
+ require "rspec/core"
3
+ require "towel"
4
+
5
+ require "towel/rspec/formatter"
6
+ require "towel/rspec/version"
7
+
8
+ module Towel
9
+ module RSpec
10
+ class Error < StandardError; end
11
+ # Your code goes here...
12
+ end
13
+ end
@@ -0,0 +1,100 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ # rspec-expectations config goes here. You can use an alternate
18
+ # assertion/expectation library such as wrong or the stdlib/minitest
19
+ # assertions if you prefer.
20
+ config.expect_with :rspec do |expectations|
21
+ # This option will default to `true` in RSpec 4. It makes the `description`
22
+ # and `failure_message` of custom matchers include text for helper methods
23
+ # defined using `chain`, e.g.:
24
+ # be_bigger_than(2).and_smaller_than(4).description
25
+ # # => "be bigger than 2 and smaller than 4"
26
+ # ...rather than:
27
+ # # => "be bigger than 2"
28
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
29
+ end
30
+
31
+ # rspec-mocks config goes here. You can use an alternate test double
32
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
33
+ config.mock_with :rspec do |mocks|
34
+ # Prevents you from mocking or stubbing a method that does not exist on
35
+ # a real object. This is generally recommended, and will default to
36
+ # `true` in RSpec 4.
37
+ mocks.verify_partial_doubles = true
38
+ end
39
+
40
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
41
+ # have no way to turn it off -- the option exists only for backwards
42
+ # compatibility in RSpec 3). It causes shared context metadata to be
43
+ # inherited by the metadata hash of host groups and examples, rather than
44
+ # triggering implicit auto-inclusion in groups with matching metadata.
45
+ config.shared_context_metadata_behavior = :apply_to_host_groups
46
+
47
+ # The settings below are suggested to provide a good initial experience
48
+ # with RSpec, but feel free to customize to your heart's content.
49
+ =begin
50
+ # This allows you to limit a spec run to individual examples or groups
51
+ # you care about by tagging them with `:focus` metadata. When nothing
52
+ # is tagged with `:focus`, all examples get run. RSpec also provides
53
+ # aliases for `it`, `describe`, and `context` that include `:focus`
54
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
55
+ config.filter_run_when_matching :focus
56
+
57
+ # Allows RSpec to persist some state between runs in order to support
58
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
59
+ # you configure your source control system to ignore this file.
60
+ config.example_status_persistence_file_path = "spec/examples.txt"
61
+
62
+ # Limits the available syntax to the non-monkey patched syntax that is
63
+ # recommended. For more details, see:
64
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
65
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
67
+ config.disable_monkey_patching!
68
+
69
+ # This setting enables warnings. It's recommended, but in some cases may
70
+ # be too noisy due to issues in dependencies.
71
+ config.warnings = true
72
+
73
+ # Many RSpec users commonly either run the entire suite or an individual
74
+ # file, and it's useful to allow more verbose output when running an
75
+ # individual spec file.
76
+ if config.files_to_run.one?
77
+ # Use the documentation formatter for detailed output,
78
+ # unless a formatter has already been configured
79
+ # (e.g. via a command-line flag).
80
+ config.default_formatter = "doc"
81
+ end
82
+
83
+ # Print the 10 slowest examples and example groups at the
84
+ # end of the spec run, to help surface which specs are running
85
+ # particularly slow.
86
+ config.profile_examples = 10
87
+
88
+ # Run specs in random order to surface order dependencies. If you find an
89
+ # order dependency and want to debug it, you can fix the order by providing
90
+ # the seed, which is printed after each run.
91
+ # --seed 1234
92
+ config.order = :random
93
+
94
+ # Seed global randomization in this process using the `--seed` CLI option.
95
+ # Setting this allows you to use `--seed` to deterministically reproduce
96
+ # test failures related to randomization by passing the same `--seed` value
97
+ # as the one that triggered the failure.
98
+ Kernel.srand config.seed
99
+ =end
100
+ end
@@ -0,0 +1,41 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "towel/rspec/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "towel-rspec"
8
+ spec.version = Towel::RSpec::VERSION
9
+ spec.authors = ["Andrew Smith"]
10
+ spec.email = ["andrew@velvet.software"]
11
+
12
+ spec.summary = "Towel integration for collecting results from RSpec"
13
+ spec.description = <<END
14
+ Towel collects test results as they run, reporting them to towel.dev for easier
15
+ inspection, debugging, and sharing.
16
+ END
17
+ spec.homepage = "https://towel.dev"
18
+ spec.license = "MIT"
19
+
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://bitbucket.org/VelvetSoftware/towel-ruby"
23
+ spec.metadata["changelog_uri"] = "https://bitbucket.org/VelvetSoftware/towel-ruby/src/master/extensions/towel-rspec/CHANGELOG.md"
24
+ end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_dependency "rspec-core", "~> 3"
36
+ spec.add_dependency "towel", "~> 0.1"
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.17"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3"
41
+ end
@@ -0,0 +1 @@
1
+ *
@@ -0,0 +1,61 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: towel/v1alpha/collector.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require 'google/protobuf/field_mask_pb'
7
+ require 'google/protobuf/timestamp_pb'
8
+ require 'towel/v1alpha/towel_pb'
9
+ Google::Protobuf::DescriptorPool.generated_pool.build do
10
+ add_file("towel/v1alpha/collector.proto", :syntax => :proto3) do
11
+ add_message "towel.v1alpha.CreateInvocationRequest" do
12
+ optional :invocation, :message, 1, "towel.v1alpha.Invocation"
13
+ end
14
+ add_message "towel.v1alpha.CreateGroupRequest" do
15
+ optional :group, :message, 1, "towel.v1alpha.Group"
16
+ end
17
+ add_message "towel.v1alpha.CreateResultRequest" do
18
+ optional :result, :message, 1, "towel.v1alpha.Result"
19
+ end
20
+ add_message "towel.v1alpha.UpdateResultRequest" do
21
+ optional :result, :message, 1, "towel.v1alpha.Result"
22
+ optional :update_mask, :message, 2, "google.protobuf.FieldMask"
23
+ end
24
+ add_message "towel.v1alpha.CreateLogRequest" do
25
+ optional :log, :message, 1, "towel.v1alpha.Log"
26
+ end
27
+ add_message "towel.v1alpha.AppendLogRequest" do
28
+ optional :name, :string, 1
29
+ repeated :entries, :message, 2, "towel.v1alpha.LogEntry"
30
+ end
31
+ add_message "towel.v1alpha.AppendLogResponse" do
32
+ end
33
+ add_message "towel.v1alpha.FinishInvocationRequest" do
34
+ optional :name, :string, 1
35
+ optional :end_time, :message, 2, "google.protobuf.Timestamp"
36
+ end
37
+ add_message "towel.v1alpha.FinishInvocationResponse" do
38
+ end
39
+ add_message "towel.v1alpha.CancelInvocationRequest" do
40
+ optional :name, :string, 1
41
+ end
42
+ add_message "towel.v1alpha.CancelInvocationResponse" do
43
+ end
44
+ end
45
+ end
46
+
47
+ module Towel
48
+ module V1alpha
49
+ CreateInvocationRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.CreateInvocationRequest").msgclass
50
+ CreateGroupRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.CreateGroupRequest").msgclass
51
+ CreateResultRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.CreateResultRequest").msgclass
52
+ UpdateResultRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.UpdateResultRequest").msgclass
53
+ CreateLogRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.CreateLogRequest").msgclass
54
+ AppendLogRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.AppendLogRequest").msgclass
55
+ AppendLogResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.AppendLogResponse").msgclass
56
+ FinishInvocationRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.FinishInvocationRequest").msgclass
57
+ FinishInvocationResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.FinishInvocationResponse").msgclass
58
+ CancelInvocationRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.CancelInvocationRequest").msgclass
59
+ CancelInvocationResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.CancelInvocationResponse").msgclass
60
+ end
61
+ end
@@ -0,0 +1,41 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: towel/v1alpha/collector.proto for package 'towel.v1alpha'
3
+
4
+ require 'grpc'
5
+ require 'towel/v1alpha/collector_pb'
6
+
7
+ module Towel
8
+ module V1alpha
9
+ module Collector
10
+ # Collector is the low-level interface to stream test/build/cron results to
11
+ # Towel.
12
+ class Service
13
+
14
+ include GRPC::GenericService
15
+
16
+ self.marshal_class_method = :encode
17
+ self.unmarshal_class_method = :decode
18
+ self.service_name = 'towel.v1alpha.Collector'
19
+
20
+ # Start recording a new invocation.
21
+ rpc :CreateInvocation, CreateInvocationRequest, Invocation
22
+ # Add a new group under which results or other groups can be placed.
23
+ rpc :CreateGroup, CreateGroupRequest, Group
24
+ # Add a new result.
25
+ rpc :CreateResult, CreateResultRequest, Result
26
+ # Update the progress of a result.
27
+ rpc :UpdateResult, UpdateResultRequest, Result
28
+ # Start recording a new log file.
29
+ rpc :CreateLog, CreateLogRequest, Log
30
+ # Append entries to a log.
31
+ rpc :AppendLog, AppendLogRequest, AppendLogResponse
32
+ # Finalize an invocation that was previously started.
33
+ rpc :FinishInvocation, FinishInvocationRequest, FinishInvocationResponse
34
+ # Declare an in-progress invocation as cancelled.
35
+ rpc :CancelInvocation, CancelInvocationRequest, CancelInvocationResponse
36
+ end
37
+
38
+ Stub = Service.rpc_stub_class
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,88 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: towel/v1alpha/towel.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require 'google/protobuf/duration_pb'
7
+ require 'google/protobuf/timestamp_pb'
8
+ Google::Protobuf::DescriptorPool.generated_pool.build do
9
+ add_file("towel/v1alpha/towel.proto", :syntax => :proto3) do
10
+ add_message "towel.v1alpha.Invocation" do
11
+ optional :name, :string, 1
12
+ optional :url, :string, 8
13
+ optional :project, :string, 2
14
+ map :labels, :string, :string, 3
15
+ optional :platform, :message, 9, "towel.v1alpha.Platform"
16
+ optional :hostname, :string, 10
17
+ optional :user, :string, 11
18
+ optional :working_dir, :string, 12
19
+ repeated :argv, :string, 13
20
+ map :env_vars, :string, :string, 14
21
+ optional :revision, :string, 15
22
+ optional :create_time, :message, 4, "google.protobuf.Timestamp"
23
+ optional :update_time, :message, 5, "google.protobuf.Timestamp"
24
+ optional :start_time, :message, 6, "google.protobuf.Timestamp"
25
+ optional :end_time, :message, 7, "google.protobuf.Timestamp"
26
+ end
27
+ add_message "towel.v1alpha.Platform" do
28
+ optional :os, :string, 1
29
+ optional :os_version, :string, 2
30
+ optional :arch, :string, 3
31
+ end
32
+ add_message "towel.v1alpha.Group" do
33
+ optional :name, :string, 1
34
+ optional :parent_group, :string, 2
35
+ optional :display_name, :string, 3
36
+ end
37
+ add_message "towel.v1alpha.Result" do
38
+ optional :name, :string, 1
39
+ optional :display_name, :string, 2
40
+ optional :state, :enum, 3, "towel.v1alpha.ResultState"
41
+ optional :attempt, :int32, 4
42
+ optional :description, :string, 5
43
+ optional :start_time, :message, 6, "google.protobuf.Timestamp"
44
+ optional :duration, :message, 7, "google.protobuf.Duration"
45
+ repeated :timespans, :message, 8, "towel.v1alpha.Timespan"
46
+ end
47
+ add_message "towel.v1alpha.Timespan" do
48
+ optional :display_name, :string, 1
49
+ optional :start_time, :message, 2, "google.protobuf.Timestamp"
50
+ optional :duration, :message, 3, "google.protobuf.Duration"
51
+ end
52
+ add_message "towel.v1alpha.Log" do
53
+ optional :name, :string, 1
54
+ optional :size, :int64, 2
55
+ optional :create_time, :message, 3, "google.protobuf.Timestamp"
56
+ optional :update_time, :message, 4, "google.protobuf.Timestamp"
57
+ end
58
+ add_message "towel.v1alpha.LogEntry" do
59
+ optional :entry_id, :int64, 1
60
+ optional :parent, :string, 2
61
+ optional :log_time, :message, 3, "google.protobuf.Timestamp"
62
+ optional :contents, :string, 4
63
+ end
64
+ add_enum "towel.v1alpha.ResultState" do
65
+ value :QUEUED, 0
66
+ value :RUNNING, 1
67
+ value :SUCCESS, 2
68
+ value :FAILURE, 3
69
+ value :ERROR, 4
70
+ value :ENVIRONMENT_ERROR, 5
71
+ value :CANCELLED, 6
72
+ value :SKIPPED, 7
73
+ end
74
+ end
75
+ end
76
+
77
+ module Towel
78
+ module V1alpha
79
+ Invocation = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.Invocation").msgclass
80
+ Platform = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.Platform").msgclass
81
+ Group = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.Group").msgclass
82
+ Result = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.Result").msgclass
83
+ Timespan = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.Timespan").msgclass
84
+ Log = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.Log").msgclass
85
+ LogEntry = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.LogEntry").msgclass
86
+ ResultState = Google::Protobuf::DescriptorPool.generated_pool.lookup("towel.v1alpha.ResultState").enummodule
87
+ end
88
+ end
@@ -0,0 +1,82 @@
1
+ module Towel
2
+ # Loads and merges configuration settings for Towel.
3
+ class Configuration
4
+ # Acceptable filenames in which to define Towel settings. These will be
5
+ # read in the defined order.
6
+ FILENAMES = %w[Towel.toml towel.toml .Towel.toml .towel.toml].freeze
7
+
8
+ # Read the configuration from files and environment variables.
9
+ def self.read
10
+ # Load configuration from files, starting in the current working directory
11
+ # and working upwards in the filesystem hierarchy until no configuration
12
+ # files are found.
13
+ files = []
14
+
15
+ directory = Dir.pwd
16
+ while true
17
+ FILENAMES.each do |filename|
18
+ possible_file = File.join(directory, filename)
19
+ files << possible_file if File.exist?(possible_file)
20
+ end
21
+
22
+ parent = File.expand_path("..", directory)
23
+ if directory == parent
24
+ break
25
+ else
26
+ directory = parent
27
+ end
28
+ end
29
+
30
+ # Combine all discovered files into one configuration.
31
+ config = files
32
+ .reverse
33
+ .map { |file| TOML.load_file(file) }
34
+ .inject({}) do |acc, toml|
35
+ acc.merge(toml) do |key, old, new|
36
+ case old
37
+ when Hash then old.merge(new)
38
+ else
39
+ new
40
+ end
41
+ end
42
+ end
43
+
44
+ # Override with environment variables where appropriate.
45
+ override = ->(env, section, key) do
46
+ if ENV.key?(env)
47
+ section_values = config[section] || {}
48
+ section_values[key] = ENV[env]
49
+ config[section] = section_values
50
+ end
51
+ end
52
+ override.call("TOWEL_API_KEY", "auth", "api_key")
53
+ override.call("TOWEL_ACCOUNT", "auth", "account")
54
+ override.call("TOWEL_ADDRESS", "collector", "address")
55
+
56
+ new(config)
57
+ end
58
+
59
+ # Creates a new configuration from a Hash.
60
+ def initialize(hash = {})
61
+ @config = {
62
+ "auth" => {
63
+ "account" => nil,
64
+ "api_key" => nil
65
+ },
66
+ "collector" => {
67
+ "address" => "towel.dev",
68
+ "organization" => nil,
69
+ "project" => nil
70
+ },
71
+ "labels" => {}
72
+ }
73
+ @config.merge!(hash)
74
+ @config.freeze
75
+ end
76
+
77
+ # Retrieves a configuration section ("auth", "collector", "labels", etc).
78
+ def [](key)
79
+ @config[key]
80
+ end
81
+ end
82
+ end