Skip to content

Commit 94fb8f2

Browse files
authored
Merge pull request #267 from buildkite/toote_orb_jobs
Orb jobs
2 parents 582ef69 + 565d9d4 commit 94fb8f2

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

app/examples/circleci/orb-jobs.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: '2.1'
2+
setup: true
3+
orbs:
4+
path-filtering: circleci/path-filtering@0.1.7
5+
workflows:
6+
generate-config:
7+
jobs:
8+
- path-filtering/filter:
9+
base-revision: main
10+
config-path: .circleci/continue_config.yml
11+
mapping: |
12+
src/.* build-code true
13+
doc/.* build-docs true
14+
src/tests/.* string-parameter "value"

app/lib/bk/compat/parsers/circleci.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ def load_orb(key, _config)
3535
def self.matches?(text)
3636
# sorting is important
3737
config = YAML.safe_load(text, aliases: true)
38-
mandatory_keys = %w[jobs version workflows].freeze
38+
mandatory_keys = %w[version workflows].freeze
39+
has_mandatory = (mandatory_keys & config.keys == mandatory_keys)
40+
at_least_one_of = %w[jobs orbs].any? { |k| config.include?(k) }
3941

4042
return false if config.is_a?(String)
41-
return true if mandatory_keys & config.keys == mandatory_keys
43+
return true if has_mandatory && at_least_one_of
4244

4345
# legacy format support
4446
config.fetch('version', 2.1) == 2 && config['jobs'].include?('build')

app/lib/bk/compat/parsers/circleci/orbs.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require_relative 'orbs/docker'
4+
require_relative '../../models/steps/circleci'
45

56
module BK
67
module Compat
@@ -15,10 +16,13 @@ def matcher?(orb, _conf)
1516
orb.start_with?("#{@prefix}/")
1617
end
1718

18-
def translator(action, _config)
19-
[
20-
"# #{action} is part of orb #{@prefix} which is not supported and should be translated by hand"
21-
]
19+
def translator(action, config)
20+
BK::Compat::CircleCIStep.new(
21+
key: config['name'] || action,
22+
commands: [
23+
"# #{action} is part of orb #{@prefix} which is not supported and should be translated by hand"
24+
]
25+
)
2226
end
2327
end
2428
end

app/lib/bk/compat/parsers/circleci/workflows.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ def process_workflow_job(job)
3131
BK::Compat::BlockStep.new(key: key, depends_on: config.fetch('requires', []))
3232
elsif @commands_by_key.include?(key)
3333
process_job(key, config)
34+
elsif key.include?('/') # orb jobs will not be defined in commands_by_key
35+
@translator.translate_step(key, config)
3436
else
35-
raise BK::Compat::Error::ConfigurationError,
36-
"Job '#{key}' is not defined"
37+
raise BK::Compat::Error::ConfigurationError, "Job '#{key}' is not defined"
3738
end
3839
end
3940

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
steps:
3+
- commands:
4+
- "# path-filtering/filter is part of orb path-filtering which is not supported
5+
and should be translated by hand"
6+
key: path-filtering/filter

0 commit comments

Comments
 (0)