buildkite-builder 2.1.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1796ef4fc73c74c399a7eb271092baee5b0101e3c06598c8d837d1fd031876e2
4
- data.tar.gz: c384d20a194cf13a8dff4e1057a1b07b777201fd717f1d75496d88ec04d7fbff
3
+ metadata.gz: b6e19458f7245c430927899fcb8a0a9d109abb85980dc9dd64ca679efec89617
4
+ data.tar.gz: 85593b91b77405e8e9fadbf4c485e86a4ce0c62747dacd3422c8e08e5c228666
5
5
  SHA512:
6
- metadata.gz: cc19aa8d8c3af6f4fbbd0bd892d56f41243649b8b384e38f7391d8e198950704bc515530c022c231eb7d4368a7bed0f74fa0f4bab3c020813bf045b67a4d1062
7
- data.tar.gz: e414869940fbb417e06192a7fdd48049d38564c00f1283a8110c2521462ce736ec890c7275c03c386b619ae718b654a4ac2cbbf460cb1f1dfd86cefb4e871b2c
6
+ metadata.gz: 878daff8f7270bc83de7dfd9d89938c7204bda1a014ed09e5e7c8d1378d1520abb94b102f052fb4312170b1c65a583f218c1b7e7c222b2ae5daed3a67728bcdb
7
+ data.tar.gz: 7365820be85d5d7b5c0123c86d5dd2c0015b15a7ee430c92b47750157f7bec1e3215a9161f212f7aa26e9da3c265352d2ec5fcb757fe761d714bab28d337cfa8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## 2.4.1
2
+ * Fix pipeline upload as artifact logic.
3
+
4
+ ## 2.4.0
5
+ * Upload custom pipeline artifacts in a single command.
6
+ * Only upload the pipeline as an artifact when the pipeline upload fails.
7
+
8
+ ## 2.3.0
9
+ * Improve BKB step idempotency.
10
+
11
+ ## 2.2.0
12
+ * Add `.buildkite/lib` directory to $LOAD_PATH if it exists.
13
+
1
14
  ## 2.1.0
2
15
  * Fix a bug introduced in 2.0.0 where artifacts were being uploaded before extensions had a chance to do work.
3
16
  * Remove `SortedSet` dependency.
data/README.md CHANGED
@@ -1,11 +1,12 @@
1
1
  # Buildkite Builder [![Build status](https://badge.buildkite.com/a26bf804e9a93fb118d29824d5695a601a248ceec51591be23.svg?branch=main)](https://buildkite.com/gusto-open-source/buildkite-builder/builds?branch=main)
2
2
 
3
3
  ## Introduction
4
+
4
5
  Buildkite Builder (BKB) is a Buildkite pipeline builder written in Ruby. It allows you to build your pipeline with a Ruby DSL for dynamically generated pipeline steps.
5
6
 
6
7
  ## Gem Installation (optional)
7
8
 
8
- There are 2 components to this toolkit. The `buildkite-builder` Rubygem and the `buildkite-builder` Docker image. You technically only need the image to use Buildkite Builder, but installing the gem in your repo helps you preview your pipeline during development.
9
+ There are 2 components to this toolkit. The `buildkite-builder` RubyGem and the `buildkite-builder` Docker image. You technically only need the image to use Buildkite Builder, but installing the gem in your repo helps you preview your pipeline during development.
9
10
 
10
11
  To install the gem, add this line to your application's Gemfile:
11
12
 
@@ -16,7 +17,7 @@ gem 'buildkite-builder'
16
17
  The gem provides a command line tool that lets you perform various operations on your pipelines:
17
18
 
18
19
  ```shell
19
- $ buildkite-builder help
20
+ buildkite-builder help
20
21
  ```
21
22
 
22
23
  ## Pipeline Installation
@@ -33,23 +34,26 @@ steps:
33
34
  ```
34
35
 
35
36
  Some things to note:
36
- - The `label` can be whatever you like.
37
- - You'll want to update the `docker` plugin version from time to time.
38
- - You can update the `buildkite-builder` version by bumping the Docker image tag.
37
+
38
+ - The `label` can be whatever you like.
39
+ - You'll want to update the `docker` plugin version from time to time.
40
+ - You can update the `buildkite-builder` version by bumping the Docker image tag.
39
41
 
40
42
  ## Usage
41
43
 
42
44
  💡 We have a [Showcase pipeline](https://buildkite.com/gusto-open-source/showcase/builds/latest?branch=main) (defined in [`.buildkite/pipelines/showcase/pipeline.rb`](https://github.com/Gusto/buildkite-builder/blob/main/.buildkite/pipelines/showcase/pipeline.rb)) that, well, showcases some of the features and possibilities with Buildkite Builder. Sometimes the best way to learning something is seeing how it's used.
43
45
 
44
46
  At its core, BKB is really just a YAML builder. This tool allows you to scale your needs when it comes to building a Buildkite pipeline. Your pipeline can be as straight forward as you'd like, or as complex as you need. Since you have Ruby at your disposal, you can do some cool things like:
45
- - Perform pre-build code/diff analysis to determine whether or not to to add a step to the pipeline.
46
- - Reorder pipeline steps dynamically.
47
- - Augment your pipeline steps with BKB processors.
47
+
48
+ - Perform pre-build code/diff analysis to determine whether or not to to add a step to the pipeline.
49
+ - Reorder pipeline steps dynamically.
50
+ - Augment your pipeline steps with BKB processors.
48
51
 
49
52
  ### Pipeline Files
53
+
50
54
  Your repo can contain as many pipeline definitions as you'd like. By convention, pipeline file structure are as such:
51
55
 
52
- ```
56
+ ```console
53
57
  .buildkite/
54
58
  pipelines/
55
59
  <your-pipeline1-slug>/
@@ -95,7 +99,7 @@ If the step type or attribute exists in Buildkite docs, then it should exist in
95
99
 
96
100
  If your pipeline has a lot of steps, you should consider using Step Templates. Templates allow you to break out your build steps into reusable template files.
97
101
 
98
- ```
102
+ ```console
99
103
  .buildkite/
100
104
  pipelines/
101
105
  foobar-widget/
@@ -108,6 +112,7 @@ If your pipeline has a lot of steps, you should consider using Step Templates. T
108
112
  A template is basically a step that was extracted from the pipeline:
109
113
 
110
114
  `.buildkite/pipelines/foobar-widget/templates/rspec.rb`
115
+
111
116
  ```ruby
112
117
  Buildkite::Builder.template do
113
118
  label "Rspec", emoji: :rspec
@@ -118,6 +123,7 @@ end
118
123
  You can then include the template into the the pipeline once or as many time as you need. The template name will be the name of the file (without the extension).
119
124
 
120
125
  `.buildkite/pipelines/foobar-widget/pipeline.rb`
126
+
121
127
  ```ruby
122
128
  Buildkite::Builder.pipeline do
123
129
  command(:rspec)
@@ -137,7 +143,7 @@ To install this gem onto your local machine, run `bundle exec rake install`.
137
143
 
138
144
  ## Contributing
139
145
 
140
- Bug reports and pull requests are welcome on GitHub at https://github.com/gusto/buildkite-builder. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/gusto/buildkite-builder/blob/main/CODE_OF_CONDUCT.md).
146
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/gusto/buildkite-builder>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/gusto/buildkite-builder/blob/main/CODE_OF_CONDUCT.md).
141
147
 
142
148
  ## License
143
149
 
@@ -145,4 +151,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
145
151
 
146
152
  ## Code of Conduct
147
153
 
148
- Everyone interacting in the Buildkite::Builder project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/gusto/buildkite-builder/blob/main/CODE_OF_CONDUCT.md).
154
+ Everyone interacting in the `Buildkite::Builder` project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/gusto/buildkite-builder/blob/main/CODE_OF_CONDUCT.md).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.0
1
+ 2.4.1
@@ -15,8 +15,13 @@ module Buildkite
15
15
 
16
16
  # This entrypoint is for running on CI. It expects certain environment
17
17
  # variables to be set. It also uploads the pipeline to Buildkite.
18
- log.info "#{'+++ ' if Buildkite.env}🧰 " + 'Buildkite Builder'.color(:springgreen) + " ─ #{relative_pipeline_path.to_s.yellow}"
19
- Pipeline.new(pipeline_path, logger: log).upload
18
+ log.info "+++ 🧰 #{'Buildkite Builder'.color(:springgreen)} ─ #{relative_pipeline_path.to_s.yellow}"
19
+
20
+ if Buildkite::Pipelines::Command.meta_data(:exists, Builder::META_DATA.fetch(:job))
21
+ log.info 'Pipeline already uploaded'.color(:dimgray)
22
+ else
23
+ Pipeline.new(pipeline_path, logger: log).upload
24
+ end
20
25
  end
21
26
 
22
27
  private
@@ -0,0 +1,15 @@
1
+ module Buildkite
2
+ module Builder
3
+ module Extensions
4
+ class Lib < Extension
5
+ def prepare
6
+ lib_dir = Buildkite::Builder.root.join(Buildkite::Builder::BUILDKITE_DIRECTORY_NAME, 'lib')
7
+
8
+ if lib_dir.directory? && !$LOAD_PATH.include?(lib_dir)
9
+ $LOAD_PATH.unshift(lib_dir)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -4,6 +4,7 @@ module Buildkite
4
4
  module Builder
5
5
  module Extensions
6
6
  autoload :Env, File.expand_path('extensions/env', __dir__)
7
+ autoload :Lib, File.expand_path('extensions/lib', __dir__)
7
8
  autoload :Notify, File.expand_path('extensions/notify', __dir__)
8
9
  autoload :Steps, File.expand_path('extensions/steps', __dir__)
9
10
  autoload :Use, File.expand_path('extensions/use', __dir__)
@@ -33,6 +33,7 @@ module Buildkite
33
33
  @data = Data.new
34
34
 
35
35
  use(Extensions::Use)
36
+ use(Extensions::Lib)
36
37
  use(Extensions::Env)
37
38
  use(Extensions::Notify)
38
39
  use(Extensions::Steps)
@@ -40,19 +41,25 @@ module Buildkite
40
41
  end
41
42
 
42
43
  def upload
44
+ # Generate the pipeline YAML first.
45
+ contents = to_yaml
46
+
47
+ upload_artifacts
48
+
43
49
  # Upload the pipeline.
44
50
  Tempfile.create(['pipeline', '.yml']) do |file|
45
51
  file.sync = true
46
- file.write(to_yaml)
52
+ file.write(contents)
47
53
 
48
- logger.info '+++ :paperclip: Uploading pipeline.yml as artifact'
49
- Buildkite::Pipelines::Command.artifact!(:upload, file.path)
50
- logger.info '+++ :pipeline: Uploading pipeline'
51
- Buildkite::Pipelines::Command.pipeline!(:upload, file.path)
54
+ logger.info "+++ :pipeline: Uploading pipeline"
55
+ unless Buildkite::Pipelines::Command.pipeline(:upload, file.path)
56
+ logger.info "Pipeline upload failed, saving as artifact…"
57
+ Buildkite::Pipelines::Command.artifact!(:upload, file.path)
58
+ abort
59
+ end
60
+ logger.info "+++ :toolbox: Setting job meta-data to #{Buildkite.env.job_id.color(:yellow)}"
61
+ Buildkite::Pipelines::Command.meta_data!(:set, Builder::META_DATA.fetch(:job), Buildkite.env.job_id)
52
62
  end
53
-
54
- logger.info '+++ :paperclip: Uploading artifacts'
55
- upload_artifacts
56
63
  end
57
64
 
58
65
  def to_h
@@ -84,11 +91,8 @@ module Buildkite
84
91
  def upload_artifacts
85
92
  return if artifacts.empty?
86
93
 
87
- artifacts.each do |path|
88
- if File.exist?(path)
89
- Buildkite::Pipelines::Command.artifact!(:upload, path)
90
- end
91
- end
94
+ logger.info "+++ :paperclip: Uploading artifacts"
95
+ Buildkite::Pipelines::Command.artifact!(:upload, artifacts.join(";"))
92
96
  end
93
97
 
94
98
  def pipeline_definition
@@ -27,6 +27,9 @@ module Buildkite
27
27
  autoload :PluginManager, File.expand_path('builder/plugin_manager', __dir__)
28
28
 
29
29
  BUILDKITE_DIRECTORY_NAME = Pathname.new('.buildkite').freeze
30
+ META_DATA = {
31
+ job: 'buildkite-builder:job'
32
+ }.freeze
30
33
 
31
34
  class << self
32
35
  def root(start_path: Dir.pwd, reset: false)
@@ -46,7 +49,7 @@ module Buildkite
46
49
 
47
50
  def find_buildkite_directory(start_path)
48
51
  path = Pathname.new(start_path)
49
- until path.join(BUILDKITE_DIRECTORY_NAME).exist? && path.join(BUILDKITE_DIRECTORY_NAME).directory?
52
+ until path.join(BUILDKITE_DIRECTORY_NAME).directory?
50
53
  raise "Unable to find #{BUILDKITE_DIRECTORY_NAME} from #{start_path}" if path == path.parent
51
54
 
52
55
  path = path.parent
@@ -4,29 +4,35 @@ module Buildkite
4
4
  module Pipelines
5
5
  class Command
6
6
  BIN_PATH = 'buildkite-agent'
7
+ COMMANDS = %w(
8
+ pipeline
9
+ artifact
10
+ annotate
11
+ meta_data
12
+ )
7
13
 
8
- def self.pipeline!(*args)
9
- abort unless pipeline(*args)
10
- end
11
-
12
- def self.pipeline(subcommand, *args)
13
- new(:pipeline, subcommand, *args).run
14
- end
14
+ class << self
15
+ def pipeline(subcommand, *args)
16
+ new(:pipeline, subcommand, *args).run
17
+ end
15
18
 
16
- def self.artifact!(*args)
17
- abort unless artifact(*args)
18
- end
19
+ def artifact(subcommand, *args)
20
+ new(:artifact, subcommand, *args).run
21
+ end
19
22
 
20
- def self.artifact(subcommand, *args)
21
- new(:artifact, subcommand, *args).run
22
- end
23
+ def annotate(body, *args)
24
+ new(:annotate, body, *args).run
25
+ end
23
26
 
24
- def self.annotate(body, *args)
25
- new(:annotate, body, *args).run
27
+ def meta_data(subcommand, *args)
28
+ new(:'meta-data', subcommand, *args).run
29
+ end
26
30
  end
27
31
 
28
- def self.annotate!(*args)
29
- abort unless annotate(*args)
32
+ COMMANDS.each do |command|
33
+ define_singleton_method("#{command}!") do |*args|
34
+ abort unless public_send(command, *args)
35
+ end
30
36
  end
31
37
 
32
38
  def initialize(command, subcommand, *args)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buildkite-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ngan Pham
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-08-27 00:00:00.000000000 Z
12
+ date: 2022-01-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rainbow
@@ -126,6 +126,7 @@ files:
126
126
  - lib/buildkite/builder/extension_manager.rb
127
127
  - lib/buildkite/builder/extensions.rb
128
128
  - lib/buildkite/builder/extensions/env.rb
129
+ - lib/buildkite/builder/extensions/lib.rb
129
130
  - lib/buildkite/builder/extensions/notify.rb
130
131
  - lib/buildkite/builder/extensions/steps.rb
131
132
  - lib/buildkite/builder/extensions/use.rb
@@ -195,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
196
  - !ruby/object:Gem::Version
196
197
  version: '0'
197
198
  requirements: []
198
- rubygems_version: 3.2.2
199
+ rubygems_version: 3.2.32
199
200
  signing_key:
200
201
  specification_version: 4
201
202
  summary: A gem for programmatically creating Buildkite pipelines.