Skip to content

Commit f14dc01

Browse files
authored
Merge pull request #62 from zzak/bk-config-differ
Add buildkite-config diff tool
2 parents 579f6d2 + 0a212ec commit f14dc01

File tree

11 files changed

+150
-1
lines changed

11 files changed

+150
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.envrc
2+
/tmp

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
source "https://rubygems.org"
22

33
gem "buildkit"
4+
gem "diffy"
5+
gem "rake"
6+
gem "autotest"

Gemfile.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,24 @@ GEM
33
specs:
44
addressable (2.8.4)
55
public_suffix (>= 2.0.2, < 6.0)
6+
autotest (5.0.0)
7+
minitest-autotest (~> 1.0)
68
buildkit (1.5.0)
79
sawyer (>= 0.6)
10+
diffy (3.4.2)
811
faraday (2.7.7)
912
faraday-net_http (>= 2.0, < 3.1)
1013
ruby2_keywords (>= 0.0.4)
1114
faraday-net_http (3.0.2)
15+
minitest (5.19.0)
16+
minitest-autotest (1.1.1)
17+
minitest-server (~> 1.0)
18+
path_expander (~> 1.0)
19+
minitest-server (1.0.7)
20+
minitest (~> 5.16)
21+
path_expander (1.1.1)
1222
public_suffix (5.0.1)
23+
rake (13.0.6)
1324
ruby2_keywords (0.0.5)
1425
sawyer (0.9.2)
1526
addressable (>= 2.3.5)
@@ -19,7 +30,10 @@ PLATFORMS
1930
arm64-darwin-23
2031

2132
DEPENDENCIES
33+
autotest
2234
buildkit
35+
diffy
36+
rake
2337

2438
BUNDLED WITH
2539
2.4.10

Rakefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "lib/buildkite_config"
4+
5+
require "minitest/test_task"
6+
Minitest::TestTask.create
7+
task default: [:test]
8+
9+
task :diff => [:buildkite_config, :rails] do
10+
diff = Buildkite::Config::Diff.compare
11+
puts diff.to_s(:color)
12+
13+
annotate = Buildkite::Config::Annotate.new(diff)
14+
annotate.perform
15+
end
16+
17+
task :buildkite_config do
18+
if !Dir.exist? "tmp/buildkite-config"
19+
`git clone --depth=1 https://github.com/rails/buildkite-config tmp/buildkite-config`
20+
else
21+
`cd tmp/buildkite-config && git pull origin main`
22+
end
23+
end
24+
25+
task :rails do
26+
if !Dir.exist? "tmp/rails"
27+
`git clone --depth=1 https://github.com/rails/rails tmp/rails`
28+
else
29+
`cd tmp/rails && git pull origin main`
30+
end
31+
end

buildkite-config-initial-pipeline.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,31 @@ steps:
1313
Prefer a second opinion for any nontrivial change, especially outside `pipeline-generate`.
1414
1515
- @matthewd
16+
- command: |
17+
git config --global --add safe.directory /workdir
18+
bundle install
19+
bundle exec rake test
20+
key: self-test
21+
plugins:
22+
- docker#v5.8.0:
23+
image: "ruby:latest"
24+
propagate-environment: true
25+
- command: |
26+
git config --global --add safe.directory /workdir
27+
bundle install
28+
bundle exec rake diff
29+
key: diff
30+
depends_on: self-test
31+
plugins:
32+
- docker#v5.8.0:
33+
image: "ruby:latest"
34+
mount-buildkite-agent: true
35+
propagate-environment: true
36+
environment:
37+
- "GITHUB_TOKEN"
1638
- trigger: "rails-ci"
1739
label: ":pipeline: Build Rails main with new config"
40+
depends_on: diff
1841
build:
1942
message: "[${BUILDKITE_BRANCH}] ${BUILDKITE_MESSAGE}"
2043
branch: "main"
@@ -24,6 +47,7 @@ steps:
2447
BUILDKITE_CONFIG_TRIGGER: true # This variable can be used downstream to avoid things like "if branch==main do Y"
2548
- trigger: "rails-ci"
2649
label: ":pipeline: Build Rails 6-1-stable with new config"
50+
depends_on: diff
2751
build:
2852
message: "[${BUILDKITE_BRANCH} / 6-1-stable] ${BUILDKITE_MESSAGE}"
2953
branch: "6-1-stable"

lib/buildkite_config.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Buildkite
2+
module Config
3+
autoload :Annotate, File.expand_path("buildkite_config/annotate", __dir__)
4+
autoload :Diff, File.expand_path("buildkite_config/diff", __dir__)
5+
end
6+
end

lib/buildkite_config/annotate.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module Buildkite::Config
2+
class Annotate
3+
def initialize(diff)
4+
@diff = diff
5+
end
6+
7+
def perform
8+
return if @diff.to_s.empty?
9+
10+
io = IO.popen("buildkite-agent annotate --style warning '#{plan}'")
11+
output = io.read
12+
io.close
13+
14+
raise output unless $?.success?
15+
16+
output
17+
end
18+
19+
private
20+
def plan
21+
<<~PLAN
22+
### :writing_hand: buildkite-config/plan
23+
24+
<details>
25+
<summary>Show Output</summary>
26+
27+
```term
28+
#{@diff.to_s(:color)}
29+
```
30+
31+
</details>
32+
PLAN
33+
end
34+
end
35+
end

lib/buildkite_config/diff.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require "diffy"
2+
3+
module Buildkite::Config
4+
module Diff
5+
def self.compare
6+
head = generated_pipeline(".")
7+
main = generated_pipeline("tmp/buildkite-config")
8+
Diffy::Diff.new(main, head, context: 4)
9+
end
10+
11+
def self.generated_pipeline(repo)
12+
io = IO.popen "ruby #{repo}/pipeline-generate tmp/rails"
13+
14+
output = io.read
15+
io.close
16+
17+
raise output unless $?.success?
18+
19+
output
20+
end
21+
end
22+
end
23+

pipeline-generate

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ end
236236
activemodel test default
237237
activesupport test default
238238
actionview test default
239-
actiontext test default
240239
activejob test default
241240
activerecord mysql2:test mysqldb
242241
activerecord trilogy:test mysqldb
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
require "buildkite_config"
4+
require "minitest/autorun"
5+
6+
class TestAnnotate < Minitest::Test
7+
def test_the_truth
8+
assert true
9+
end
10+
end

test/test_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# frozen_string_literal: true
2+
3+
require "minitest/autorun"

0 commit comments

Comments
 (0)