Skip to content

Commit

Permalink
Avoid passing the entire agent into the annotate container
Browse files Browse the repository at this point in the history
  • Loading branch information
zzak committed Dec 1, 2023
1 parent d3d29aa commit a8538b9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 37 deletions.
6 changes: 2 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ require "minitest/test_task"
Minitest::TestTask.create
task default: [:test]

task :diff => [:buildkite_config, :rails] do
task :diff do
diff = Buildkite::Config::Diff.compare
puts diff.to_s(:color)

annotate = Buildkite::Config::Annotate.new(diff)
annotate.perform
puts annotate.plan
end

task :buildkite_config do
Expand Down
33 changes: 22 additions & 11 deletions buildkite-config-initial-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,35 @@ steps:
git config --global --add safe.directory /workdir
bundle install
bundle exec rake test
label: ":test_tube: buildkite-config: rake test"
key: self-test
plugins:
- docker#v5.8.0:
image: "ruby:latest"
propagate-environment: true
- command: |
git config --global --add safe.directory /workdir
bundle install
bundle exec rake diff
git clone --depth=1 https://github.com/rails/buildkite-config tmp/buildkite-config
git clone --depth=1 https://github.com/rails/rails tmp/rails
sh -c "$$ANNOTATE_COMMAND" > tmp/annotate.diff
if [[ -z $(grep '[^[:space:]]' tmp/annotate.diff) ]]; then
echo "annotate.diff is empty"
else
echo "annotate.diff is not empty"
cat tmp/annotate.diff
printf '%b\n' "$(cat tmp/annotate.diff)" | buildkite-agent annotate --style warning
fi
label: ":writing_hand: buildkite-config: annotate diff"
env:
BUNDLE_FROZEN: true
ANNOTATE_COMMAND: >-
docker run --rm
-v "$$PWD":/app:ro -w /app
-v "$$PWD/tmp":/app/tmp:rw
-e BUNDLE_FROZEN
ruby:latest
./pipeline-annotate
key: diff
depends_on: self-test
plugins:
- docker#v5.8.0:
image: "ruby:latest"
mount-buildkite-agent: true
propagate-environment: true
environment:
- "GITHUB_TOKEN"
- trigger: "rails-ci"
label: ":pipeline: Build Rails main with new config"
depends_on: diff
Expand Down
33 changes: 11 additions & 22 deletions lib/buildkite_config/annotate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,21 @@ def initialize(diff)
@diff = diff
end

def perform
def plan
return if @diff.to_s.empty?

io = IO.popen("buildkite-agent annotate --style warning '#{plan}'")
output = io.read
io.close
<<~PLAN
### :writing_hand: buildkite-config/plan
raise output unless $?.success?
<details>
<summary>Show Output</summary>
output
end

private
def plan
<<~PLAN
### :writing_hand: buildkite-config/plan
<details>
<summary>Show Output</summary>
```term
#{@diff.to_s(:color)}
```
```term
#{@diff.to_s(:color)}
```
</details>
PLAN
end
</details>
PLAN
end
end
end
18 changes: 18 additions & 0 deletions pipeline-annotate
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

def run(cmd, value=false)
io = IO.popen(cmd)
output = io.read
io.close

raise output unless $?.success?

return output if value
end

run "bundle install"

annotation = run "bundle exec rake diff", true

puts annotation

0 comments on commit a8538b9

Please sign in to comment.