Skip to content

Commit

Permalink
Switch back to use metedata.exists? (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
tubaxenor authored Jun 27, 2023
1 parent 15a6a5f commit 5892b58
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 4.2.3
* Simplify pipeline upload duplication check

### 4.2.2
* Use step id to distinguish different piplelines, fix re-uploading pipeline on same step issue.

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.2.2
4.2.3
2 changes: 1 addition & 1 deletion lib/buildkite/builder/commands/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def run
# variables to be set. It also uploads the pipeline to Buildkite.
log.info "+++ 🧰 #{'Buildkite Builder'.color(:springgreen)} v#{Buildkite::Builder.version}#{relative_pipeline_path.to_s.yellow}"

if Buildkite::Pipelines::Command.meta_data(:get, Builder.meta_data.fetch(:job)) == Buildkite.env.step_id
if Buildkite::Pipelines::Command.meta_data(:exists, Builder.meta_data.fetch(:job))
log.info "Pipeline already uploaded in #{Buildkite.env.step_id} step".color(:dimgray)
else
Pipeline.new(pipeline_path, logger: log).upload
Expand Down
27 changes: 8 additions & 19 deletions spec/buildkite/builder/commands/run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
before do
stub_const('ARGV', argv)
setup_project(fixture_project)
stub_buildkite_env(step_id: 'step-id')
end

describe '.execute' do
context 'when step key matches' do
context 'when step key exists' do
let(:exists) { true }

before do
stub_buildkite_env(step_id: 'step-id')
allow(Buildkite::Pipelines::Command).to receive(:meta_data).with(:get, Buildkite::Builder.meta_data.fetch(:job)).and_return('step-id')
allow(Buildkite::Pipelines::Command).to receive(:meta_data).with(:exists, Buildkite::Builder.meta_data.fetch(:job)).and_return(exists)
end

it 'does not upload the pipeline' do
Expand All @@ -23,24 +25,11 @@
described_class.execute
end

context 'when uploaded to different job' do
before do
stub_buildkite_env(step_id: 'another-step-id')
allow(Buildkite::Pipelines::Command).to receive(:meta_data).with(:get, Buildkite::Builder.meta_data.fetch(:job)).and_return('step-id')
end

it 'uploads the context' do
expect(Buildkite::Builder::Pipeline).to receive(:new).and_return(pipeline)
expect(pipeline).to receive(:upload)

described_class.execute
end
end
context 'when step key does not exists' do
let(:exists) { false }

context 'when not uploaded' do
before do
stub_buildkite_env(step_id: 'another-step-id')
allow(Buildkite::Pipelines::Command).to receive(:meta_data).with(:get, Buildkite::Builder.meta_data.fetch(:job)).and_return('')
allow(Buildkite::Pipelines::Command).to receive(:meta_data).with(:exists, Buildkite::Builder.meta_data.fetch(:job)).and_return(exists)
end

it 'uploads the context' do
Expand Down

0 comments on commit 5892b58

Please sign in to comment.