buildkite_watcher 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +16 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +43 -0
- data/.rubocop_todo.yml +52 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +92 -0
- data/README.md +25 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/buildkite_watcher.gemspec +33 -0
- data/exe/bw +8 -0
- data/lib/buildkite_watcher.rb +289 -0
- data/lib/buildkite_watcher/version.rb +5 -0
- metadata +80 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ce94c9f805c452c1c2d347d496c6035f2c46978c4380ece167df5d4fc8e185bf
|
|
4
|
+
data.tar.gz: 37134a0e829761200e9c864416f023325ef3d716cadc929f7c5c1c9817786f8c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 84da1398fdb493ff787030ce14e9499a58dda0b8b5c6c6e55310b76a389204c7345cd02febd7824bab80f730cf46e5bfa2561db94580f58c450353e40f648d55
|
|
7
|
+
data.tar.gz: fe35e7b28d99cf4bb0e44667cf4f35b96381b5aa499dc6aabd8e7c9725ddb8a963f931006c4742f8e30be5e94b2163094c13ec30c138727a2e172ad93cf82d3c
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: Ruby
|
|
2
|
+
|
|
3
|
+
on: [push,pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
steps:
|
|
9
|
+
- uses: actions/checkout@v2
|
|
10
|
+
- name: Set up Ruby
|
|
11
|
+
uses: ruby/setup-ruby@v1
|
|
12
|
+
with:
|
|
13
|
+
ruby-version: 3.0
|
|
14
|
+
bundler-cache: true
|
|
15
|
+
- name: Run the default task
|
|
16
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
|
2
|
+
|
|
3
|
+
AllCops:
|
|
4
|
+
TargetRubyVersion: 3.0
|
|
5
|
+
NewCops: enable
|
|
6
|
+
|
|
7
|
+
Style/StringLiterals:
|
|
8
|
+
Enabled: true
|
|
9
|
+
EnforcedStyle: double_quotes
|
|
10
|
+
|
|
11
|
+
Style/StringLiteralsInInterpolation:
|
|
12
|
+
Enabled: true
|
|
13
|
+
EnforcedStyle: double_quotes
|
|
14
|
+
|
|
15
|
+
Style/Documentation:
|
|
16
|
+
Enabled: false
|
|
17
|
+
|
|
18
|
+
Style/TrailingCommaInArguments:
|
|
19
|
+
EnforcedStyleForMultiline: comma
|
|
20
|
+
|
|
21
|
+
Style/TrailingCommaInArrayLiteral:
|
|
22
|
+
EnforcedStyleForMultiline: comma
|
|
23
|
+
|
|
24
|
+
Style/TrailingCommaInHashLiteral:
|
|
25
|
+
EnforcedStyleForMultiline: comma
|
|
26
|
+
|
|
27
|
+
Layout/LineLength:
|
|
28
|
+
Max: 120
|
|
29
|
+
|
|
30
|
+
Layout/MultilineMethodCallIndentation:
|
|
31
|
+
EnforcedStyle: indented
|
|
32
|
+
|
|
33
|
+
Metrics/BlockLength:
|
|
34
|
+
Exclude:
|
|
35
|
+
- '**/*_spec.rb'
|
|
36
|
+
|
|
37
|
+
Metrics/ModuleLength:
|
|
38
|
+
Exclude:
|
|
39
|
+
- '**/*_spec.rb'
|
|
40
|
+
|
|
41
|
+
Lint/AmbiguousBlockAssociation:
|
|
42
|
+
Exclude:
|
|
43
|
+
- "**/*_spec.rb"
|
data/.rubocop_todo.yml
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# This configuration was generated by
|
|
2
|
+
# `rubocop --auto-gen-config`
|
|
3
|
+
# on 2021-06-04 19:01:24 UTC using RuboCop version 1.16.0.
|
|
4
|
+
# The point is for the user to remove these configuration records
|
|
5
|
+
# one by one as the offenses are removed from the code base.
|
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
|
8
|
+
|
|
9
|
+
# Offense count: 1
|
|
10
|
+
# Configuration parameters: Include.
|
|
11
|
+
# Include: **/*.gemspec
|
|
12
|
+
Gemspec/RequiredRubyVersion:
|
|
13
|
+
Exclude:
|
|
14
|
+
- 'buildkite_watcher.gemspec'
|
|
15
|
+
|
|
16
|
+
# Offense count: 1
|
|
17
|
+
# Configuration parameters: CheckForMethodsWithNoSideEffects.
|
|
18
|
+
Lint/Void:
|
|
19
|
+
Exclude:
|
|
20
|
+
- 'lib/buildkite_watcher.rb'
|
|
21
|
+
|
|
22
|
+
# Offense count: 4
|
|
23
|
+
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
|
|
24
|
+
Metrics/AbcSize:
|
|
25
|
+
Max: 100
|
|
26
|
+
|
|
27
|
+
# Offense count: 2
|
|
28
|
+
# Configuration parameters: IgnoredMethods.
|
|
29
|
+
Metrics/CyclomaticComplexity:
|
|
30
|
+
Max: 11
|
|
31
|
+
|
|
32
|
+
# Offense count: 3
|
|
33
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
|
34
|
+
Metrics/MethodLength:
|
|
35
|
+
Max: 50
|
|
36
|
+
|
|
37
|
+
# Offense count: 1
|
|
38
|
+
# Configuration parameters: CountComments, CountAsOne.
|
|
39
|
+
Metrics/ModuleLength:
|
|
40
|
+
Max: 300
|
|
41
|
+
|
|
42
|
+
# Offense count: 2
|
|
43
|
+
# Configuration parameters: IgnoredMethods.
|
|
44
|
+
Metrics/PerceivedComplexity:
|
|
45
|
+
Max: 13
|
|
46
|
+
|
|
47
|
+
# Offense count: 1
|
|
48
|
+
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
|
|
49
|
+
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
|
|
50
|
+
Naming/MemoizedInstanceVariableName:
|
|
51
|
+
Exclude:
|
|
52
|
+
- 'lib/buildkite_watcher.rb'
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source "https://rubygems.org"
|
|
4
|
+
|
|
5
|
+
# Specify your gem's dependencies in buildkite_watcher.gemspec
|
|
6
|
+
gemspec
|
|
7
|
+
|
|
8
|
+
gem "rake", "~> 13.0"
|
|
9
|
+
|
|
10
|
+
gem "rspec", "~> 3.0"
|
|
11
|
+
|
|
12
|
+
gem "rubocop", "~> 1.7"
|
|
13
|
+
gem "rubocop-rake", "~> 0.5.1"
|
|
14
|
+
gem "rubocop-rspec", "~> 2.3.0"
|
|
15
|
+
|
|
16
|
+
gem "pry-byebug"
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
buildkite_watcher (0.1.0)
|
|
5
|
+
rest-client (~> 2.1.0)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
ast (2.4.2)
|
|
11
|
+
byebug (11.1.3)
|
|
12
|
+
coderay (1.1.3)
|
|
13
|
+
diff-lcs (1.4.4)
|
|
14
|
+
domain_name (0.5.20190701)
|
|
15
|
+
unf (>= 0.0.5, < 1.0.0)
|
|
16
|
+
http-accept (1.7.0)
|
|
17
|
+
http-cookie (1.0.3)
|
|
18
|
+
domain_name (~> 0.5)
|
|
19
|
+
method_source (1.0.0)
|
|
20
|
+
mime-types (3.3.1)
|
|
21
|
+
mime-types-data (~> 3.2015)
|
|
22
|
+
mime-types-data (3.2021.0225)
|
|
23
|
+
netrc (0.11.0)
|
|
24
|
+
parallel (1.20.1)
|
|
25
|
+
parser (3.0.1.1)
|
|
26
|
+
ast (~> 2.4.1)
|
|
27
|
+
pry (0.13.1)
|
|
28
|
+
coderay (~> 1.1)
|
|
29
|
+
method_source (~> 1.0)
|
|
30
|
+
pry-byebug (3.9.0)
|
|
31
|
+
byebug (~> 11.0)
|
|
32
|
+
pry (~> 0.13.0)
|
|
33
|
+
rainbow (3.0.0)
|
|
34
|
+
rake (13.0.3)
|
|
35
|
+
regexp_parser (2.1.1)
|
|
36
|
+
rest-client (2.1.0)
|
|
37
|
+
http-accept (>= 1.7.0, < 2.0)
|
|
38
|
+
http-cookie (>= 1.0.2, < 2.0)
|
|
39
|
+
mime-types (>= 1.16, < 4.0)
|
|
40
|
+
netrc (~> 0.8)
|
|
41
|
+
rexml (3.2.5)
|
|
42
|
+
rspec (3.10.0)
|
|
43
|
+
rspec-core (~> 3.10.0)
|
|
44
|
+
rspec-expectations (~> 3.10.0)
|
|
45
|
+
rspec-mocks (~> 3.10.0)
|
|
46
|
+
rspec-core (3.10.1)
|
|
47
|
+
rspec-support (~> 3.10.0)
|
|
48
|
+
rspec-expectations (3.10.1)
|
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
50
|
+
rspec-support (~> 3.10.0)
|
|
51
|
+
rspec-mocks (3.10.2)
|
|
52
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
53
|
+
rspec-support (~> 3.10.0)
|
|
54
|
+
rspec-support (3.10.2)
|
|
55
|
+
rubocop (1.16.0)
|
|
56
|
+
parallel (~> 1.10)
|
|
57
|
+
parser (>= 3.0.0.0)
|
|
58
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
59
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
60
|
+
rexml
|
|
61
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
|
62
|
+
ruby-progressbar (~> 1.7)
|
|
63
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
64
|
+
rubocop-ast (1.7.0)
|
|
65
|
+
parser (>= 3.0.1.1)
|
|
66
|
+
rubocop-rake (0.5.1)
|
|
67
|
+
rubocop
|
|
68
|
+
rubocop-rspec (2.3.0)
|
|
69
|
+
rubocop (~> 1.0)
|
|
70
|
+
rubocop-ast (>= 1.1.0)
|
|
71
|
+
ruby-progressbar (1.11.0)
|
|
72
|
+
unf (0.1.4)
|
|
73
|
+
unf_ext
|
|
74
|
+
unf_ext (0.0.7.7)
|
|
75
|
+
unicode-display_width (2.0.0)
|
|
76
|
+
|
|
77
|
+
PLATFORMS
|
|
78
|
+
x86_64-darwin-19
|
|
79
|
+
x86_64-darwin-20
|
|
80
|
+
x86_64-linux
|
|
81
|
+
|
|
82
|
+
DEPENDENCIES
|
|
83
|
+
buildkite_watcher!
|
|
84
|
+
pry-byebug
|
|
85
|
+
rake (~> 13.0)
|
|
86
|
+
rspec (~> 3.0)
|
|
87
|
+
rubocop (~> 1.7)
|
|
88
|
+
rubocop-rake (~> 0.5.1)
|
|
89
|
+
rubocop-rspec (~> 2.3.0)
|
|
90
|
+
|
|
91
|
+
BUNDLED WITH
|
|
92
|
+
2.2.17
|
data/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Buildkite Watcher
|
|
2
|
+
|
|
3
|
+
Command line utility that continuously watches for the buildkite job running current git HEAD and notifies on build status changes.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Run this command:
|
|
8
|
+
|
|
9
|
+
$ gem install buildkite_watcher
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
From a directory in your project, run.
|
|
14
|
+
|
|
15
|
+
`$ bw `
|
|
16
|
+
|
|
17
|
+
## Development
|
|
18
|
+
|
|
19
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
20
|
+
|
|
21
|
+
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
22
|
+
|
|
23
|
+
## Contributing
|
|
24
|
+
|
|
25
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nulogy/buildkite_watcher.
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "buildkite_watcher"
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
+
# require "pry"
|
|
12
|
+
# Pry.start
|
|
13
|
+
|
|
14
|
+
require "irb"
|
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/buildkite_watcher/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "buildkite_watcher"
|
|
7
|
+
spec.version = BuildkiteWatcher::VERSION
|
|
8
|
+
spec.authors = ["Arturo Pie"]
|
|
9
|
+
spec.email = ["arturop@nulogy.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "CLI utility that watches buildkite and notify on build status changes"
|
|
12
|
+
spec.description = <<~MSG
|
|
13
|
+
Command line utility that continuously watches for the buildkite job running current git HEAD and
|
|
14
|
+
notifies on build status changes.
|
|
15
|
+
MSG
|
|
16
|
+
|
|
17
|
+
spec.required_ruby_version = ">= 2.7", "< 3.1"
|
|
18
|
+
|
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/nulogy/buildkite_watcher"
|
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/nulogy/buildkite_watcher/blob/main/CHANGELOG.md"
|
|
21
|
+
|
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
24
|
+
spec.files =
|
|
25
|
+
Dir.chdir(File.expand_path(__dir__)) do
|
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
|
27
|
+
end
|
|
28
|
+
spec.bindir = "exe"
|
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
30
|
+
spec.require_paths = ["lib"]
|
|
31
|
+
|
|
32
|
+
spec.add_dependency "rest-client", "~> 2.1.0"
|
|
33
|
+
end
|
data/exe/bw
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rainbow"
|
|
4
|
+
require "rest-client"
|
|
5
|
+
require "buildkite_watcher/version"
|
|
6
|
+
|
|
7
|
+
# Command line utility that continuously watches for the buildkite job running current git HEAD and
|
|
8
|
+
# notifies on build status changes.
|
|
9
|
+
module BuildkiteWatcher
|
|
10
|
+
class << self
|
|
11
|
+
GRAPHQL_QUERY = <<~GRAPHQL
|
|
12
|
+
query ($pipelineSlug: ID!, $commitHash: [String!], $branch: [String!]) {
|
|
13
|
+
pipeline(slug: $pipelineSlug) {
|
|
14
|
+
commit_hash_builds: builds(commit: $commitHash, state: [PASSED, RUNNING, FAILED, BLOCKED], first: 1) {
|
|
15
|
+
edges {
|
|
16
|
+
node {
|
|
17
|
+
commit
|
|
18
|
+
message
|
|
19
|
+
state
|
|
20
|
+
jobs(first: 1, step: { key: "aggregate_results" }) {
|
|
21
|
+
edges {
|
|
22
|
+
node {
|
|
23
|
+
... on JobTypeCommand {
|
|
24
|
+
label
|
|
25
|
+
artifacts {
|
|
26
|
+
edges {
|
|
27
|
+
node {
|
|
28
|
+
downloadURL
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
branch_builds: builds(branch: $branch, state: [PASSED, RUNNING, FAILED, BLOCKED], first: 2) {
|
|
40
|
+
edges {
|
|
41
|
+
node {
|
|
42
|
+
commit
|
|
43
|
+
message
|
|
44
|
+
state
|
|
45
|
+
jobs(first: 1, step: { key: "aggregate_results" }) {
|
|
46
|
+
edges {
|
|
47
|
+
node {
|
|
48
|
+
... on JobTypeCommand {
|
|
49
|
+
label
|
|
50
|
+
artifacts {
|
|
51
|
+
edges {
|
|
52
|
+
node {
|
|
53
|
+
downloadURL
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
GRAPHQL
|
|
67
|
+
BUILD_PASSED = "PASSED"
|
|
68
|
+
BUILD_BLOCKED = "BLOCKED"
|
|
69
|
+
BUILD_RUNNING = "RUNNING"
|
|
70
|
+
BUILD_FAILED = "FAILED"
|
|
71
|
+
BUILD_UNKNOWN_STATUS = "UNKNOWN"
|
|
72
|
+
|
|
73
|
+
def result_watch
|
|
74
|
+
Signal.trap("SIGINT") do
|
|
75
|
+
puts
|
|
76
|
+
puts Rainbow("Program interrupt received. Exiting.").red
|
|
77
|
+
exit 1
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
previous_result = BUILD_UNKNOWN_STATUS
|
|
81
|
+
loop do
|
|
82
|
+
system("clear")
|
|
83
|
+
new_result = result
|
|
84
|
+
|
|
85
|
+
maybe_notify(previous_result, new_result)
|
|
86
|
+
previous_result = new_result
|
|
87
|
+
|
|
88
|
+
sleep 30
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Scenarios:
|
|
93
|
+
# - current commit doesn't have a build, no prior failed build
|
|
94
|
+
# - current commit doesn't have a build, there is a prior failed build
|
|
95
|
+
# - current commit has a build, is running, no prior failed build
|
|
96
|
+
# - current commit has a build, is running, there is a prior failed build
|
|
97
|
+
# - current commit has a build, has passed
|
|
98
|
+
# - current commit has a build, has failed
|
|
99
|
+
|
|
100
|
+
def result
|
|
101
|
+
puts Rainbow("Branch: ").bright + Rainbow(branch_name)
|
|
102
|
+
puts Rainbow("HEAD ➜ ").bright + Rainbow(commit_hash)
|
|
103
|
+
puts
|
|
104
|
+
|
|
105
|
+
buildkite_query = {
|
|
106
|
+
query: GRAPHQL_QUERY,
|
|
107
|
+
variables: {
|
|
108
|
+
pipelineSlug: pipeline_slug,
|
|
109
|
+
commitHash: commit_hash,
|
|
110
|
+
branch: branch_name,
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
builds = fetch_build_data(buildkite_query)
|
|
115
|
+
commit_hash_builds = simplify_builds_response_data(builds.commit_hash_builds)
|
|
116
|
+
branch_builds = simplify_builds_response_data(builds.branch_builds)
|
|
117
|
+
|
|
118
|
+
if commit_hash_builds.any?
|
|
119
|
+
build = commit_hash_builds.first
|
|
120
|
+
print_state(build.state)
|
|
121
|
+
return build.state if build_passed?(build.state) || branch_builds.empty?
|
|
122
|
+
|
|
123
|
+
if build.state == BUILD_RUNNING && prior_build_failed?(branch_builds)
|
|
124
|
+
puts
|
|
125
|
+
puts Rainbow("Prior failure summary:").bright
|
|
126
|
+
print_failures(prior_failed_build(branch_builds))
|
|
127
|
+
elsif build.state == BUILD_FAILED
|
|
128
|
+
print_failures(build)
|
|
129
|
+
end
|
|
130
|
+
else
|
|
131
|
+
print_no_current_build
|
|
132
|
+
|
|
133
|
+
return build.state if branch_builds.empty?
|
|
134
|
+
|
|
135
|
+
puts
|
|
136
|
+
puts Rainbow("Prior finished build summary:").bright
|
|
137
|
+
puts
|
|
138
|
+
|
|
139
|
+
build = branch_builds.first
|
|
140
|
+
print_state(build.state)
|
|
141
|
+
return build.state if build_passed?(build.state)
|
|
142
|
+
|
|
143
|
+
if last_build_failed?(branch_builds)
|
|
144
|
+
puts
|
|
145
|
+
puts Rainbow("Failure summary:").bright
|
|
146
|
+
|
|
147
|
+
build = branch_builds.first
|
|
148
|
+
print_failures(build)
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
build.state
|
|
152
|
+
rescue StandardError => e
|
|
153
|
+
puts
|
|
154
|
+
puts Rainbow("ERROR: #{e.message}\n#{e.backtrace}").red
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
private
|
|
158
|
+
|
|
159
|
+
def maybe_notify(previous_result, new_result)
|
|
160
|
+
return if new_result == previous_result || previous_result == BUILD_UNKNOWN_STATUS
|
|
161
|
+
|
|
162
|
+
case new_result
|
|
163
|
+
when build_passed?(new_result)
|
|
164
|
+
system('osascript -e \'display notification "CI PASSED" with title "CI Result Watch" sound name "Glass"\'')
|
|
165
|
+
when BUILD_FAILED
|
|
166
|
+
system('osascript -e \'display notification "CI FAILED" with title "CI Result Watch" sound name "Basso"\'')
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def build_passed?(state)
|
|
171
|
+
[BUILD_PASSED, BUILD_BLOCKED].include?(state)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def fetch_build_data(buildkite_query)
|
|
175
|
+
response =
|
|
176
|
+
JSON.parse(
|
|
177
|
+
RestClient.post(
|
|
178
|
+
"https://graphql.buildkite.com/v1",
|
|
179
|
+
buildkite_query.to_json,
|
|
180
|
+
{ Authorization: "Bearer #{buildkite_token}", content_type: :json },
|
|
181
|
+
),
|
|
182
|
+
object_class: OpenStruct,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
response.data.pipeline
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def simplify_builds_response_data(builds)
|
|
189
|
+
simplified_builds = builds.edges.map(&:node)
|
|
190
|
+
simplified_builds.map do |build|
|
|
191
|
+
OpenStruct.new(
|
|
192
|
+
commit: build.commit,
|
|
193
|
+
message: build.message,
|
|
194
|
+
state: build.state,
|
|
195
|
+
aggregate_results_job: simplify_jobs_response_data(build.jobs),
|
|
196
|
+
)
|
|
197
|
+
end
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def simplify_jobs_response_data(jobs)
|
|
201
|
+
simplified_jobs = jobs.edges.map(&:node)
|
|
202
|
+
simplified_jobs.map do |job|
|
|
203
|
+
OpenStruct.new(label: job.label, artifacts: simplify_artifacts_response_data(job.artifacts))
|
|
204
|
+
end.first
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def simplify_artifacts_response_data(artifacts)
|
|
208
|
+
artifacts.edges.map(&:node)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def print_state(state)
|
|
212
|
+
case state
|
|
213
|
+
when build_passed?(state)
|
|
214
|
+
puts Rainbow("CI Status: ").bright + Rainbow(state).green
|
|
215
|
+
when BUILD_RUNNING
|
|
216
|
+
puts Rainbow("CI Status: ").bright + Rainbow(state).yellow
|
|
217
|
+
when BUILD_FAILED
|
|
218
|
+
puts Rainbow("CI Status: ").bright + Rainbow(state).red
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def print_no_current_build
|
|
223
|
+
no_builds_for_head_message =
|
|
224
|
+
"Your HEAD pointer is at commit #{commit_hash} but Buildkite has no finished builds for this commit."
|
|
225
|
+
puts Rainbow(no_builds_for_head_message).yellow
|
|
226
|
+
puts Rainbow("Push the current branch to trigger a build.").bright.yellow
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def last_build_failed?(builds)
|
|
230
|
+
builds.first.state == BUILD_FAILED
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def prior_build_failed?(builds)
|
|
234
|
+
builds[1].present? && builds[1].state == BUILD_FAILED
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def prior_failed_build(builds)
|
|
238
|
+
builds[1]
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
def print_failures(build)
|
|
242
|
+
aggregate_result_job = build.aggregate_results_job
|
|
243
|
+
|
|
244
|
+
unless aggregate_result_job&.artifacts&.any?
|
|
245
|
+
puts
|
|
246
|
+
return(
|
|
247
|
+
puts Rainbow("Could not retrieve failures. Please check the Aggregate Results step of the CI pipeline.")
|
|
248
|
+
.yellow
|
|
249
|
+
)
|
|
250
|
+
end
|
|
251
|
+
failures_artifact = aggregate_result_job.artifacts.first
|
|
252
|
+
download_url = failures_artifact.downloadURL
|
|
253
|
+
|
|
254
|
+
failures = fetch_failures(download_url)
|
|
255
|
+
|
|
256
|
+
puts
|
|
257
|
+
puts Rainbow("#{failures.count} failures from these specs:").yellow
|
|
258
|
+
puts
|
|
259
|
+
failures.map(&:name).map { |name| /\[(\w+)\] (.*): .*/.match(name).captures }.group_by(&:first)
|
|
260
|
+
.each do |key, values|
|
|
261
|
+
puts key
|
|
262
|
+
values.map { |e| e[1] }.uniq.each do |failure_file|
|
|
263
|
+
failure_file
|
|
264
|
+
puts Rainbow(failure_file).red
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
def fetch_failures(download_url)
|
|
270
|
+
JSON.parse(RestClient.get(download_url), object_class: OpenStruct)
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
def pipeline_slug
|
|
274
|
+
ENV.fetch("PIPELINE_SLUG")
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def branch_name
|
|
278
|
+
ENV.fetch("BRANCH_NAME", `git symbolic-ref --short HEAD`.strip)
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def commit_hash
|
|
282
|
+
ENV.fetch("COMMIT_HASH", `git rev-parse HEAD`.strip)
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
def buildkite_token
|
|
286
|
+
@_buildkite_token ||= `cat ~/.buildkite_token`
|
|
287
|
+
end
|
|
288
|
+
end
|
|
289
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: buildkite_watcher
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Arturo Pie
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-06-04 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rest-client
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 2.1.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 2.1.0
|
|
27
|
+
description: |
|
|
28
|
+
Command line utility that continuously watches for the buildkite job running current git HEAD and
|
|
29
|
+
notifies on build status changes.
|
|
30
|
+
email:
|
|
31
|
+
- arturop@nulogy.com
|
|
32
|
+
executables:
|
|
33
|
+
- bw
|
|
34
|
+
extensions: []
|
|
35
|
+
extra_rdoc_files: []
|
|
36
|
+
files:
|
|
37
|
+
- ".github/workflows/main.yml"
|
|
38
|
+
- ".gitignore"
|
|
39
|
+
- ".rspec"
|
|
40
|
+
- ".rubocop.yml"
|
|
41
|
+
- ".rubocop_todo.yml"
|
|
42
|
+
- CHANGELOG.md
|
|
43
|
+
- Gemfile
|
|
44
|
+
- Gemfile.lock
|
|
45
|
+
- README.md
|
|
46
|
+
- Rakefile
|
|
47
|
+
- bin/console
|
|
48
|
+
- bin/setup
|
|
49
|
+
- buildkite_watcher.gemspec
|
|
50
|
+
- exe/bw
|
|
51
|
+
- lib/buildkite_watcher.rb
|
|
52
|
+
- lib/buildkite_watcher/version.rb
|
|
53
|
+
homepage:
|
|
54
|
+
licenses: []
|
|
55
|
+
metadata:
|
|
56
|
+
source_code_uri: https://github.com/nulogy/buildkite_watcher
|
|
57
|
+
changelog_uri: https://github.com/nulogy/buildkite_watcher/blob/main/CHANGELOG.md
|
|
58
|
+
post_install_message:
|
|
59
|
+
rdoc_options: []
|
|
60
|
+
require_paths:
|
|
61
|
+
- lib
|
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '2.7'
|
|
67
|
+
- - "<"
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '3.1'
|
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
requirements: []
|
|
76
|
+
rubygems_version: 3.2.16
|
|
77
|
+
signing_key:
|
|
78
|
+
specification_version: 4
|
|
79
|
+
summary: CLI utility that watches buildkite and notify on build status changes
|
|
80
|
+
test_files: []
|