Skip to main content

Generate Buildkite YAML with composable type-checked models

Project description

lint and tests codecov

Kitefly

The Kitefly python library can be used to generate Buildkite pipeline YAML using type-checked composable classes. Additionally, a filter mechanism is available which can be used to reduce the number of jobs in pull requests for mono-repos, or other similar applications.

Installation

pip install kitefly

Usage

Create a pipeline file in your repository (e.g. generate_pipeline.py). Here's a simple example:

#!/usr/bin/env python
# File: generate_pipeline.py

from kitefly import *

# 1. Define your Source Targets (Optional)

lib = Target.src('src/lib', 'src/lib-v2')
app = Target.src('src/app').prio(10)
app >> lib
py_files = Target('**/*.py')


# 2. Define the Pipeline
# You can inherit from Command to apply env vars and agents targeting to
# all steps with that class. Those class properties will be merged in reverse-MRO.

class Linux(Command):
  env = {
    "PYTHON_PATH": "/usr/bin/python3"
  }
  agents = {
    "os": "linux"
  }

class LinuxHighCpu(Linux):
  agents = {
    "instance": "large"
  }

# If you want to declare dependencies, you can create variables for certain
# steps to be used below.
coverage = Command('Collect and publish code coverage', 'script/coverage-collector.sh')

app_tests = LinuxHighCpu('Run app tests', 'script/test-app.sh', targets=[app])
lib_tests = Linux('Run library tests', 'script/test-lib.sh', targets=[lib])
e2e_tests = Command('Run E2E Tests', 'script/e2e.sh', targets=[app])
lint = Command('Run pylint', './script/pylint.sh', targets=py_files, env={PYENV_VERSION: "project-3.6.3"})

lint_phase = Group([lint], label='Lint') 
test_phase = Group([app_tests, lib_tests, e2e_tests], label='Test')
test_phase >> lint_phase

pipeline = Pipeline([
  lint_phase,
  test_phase,
  Wait(),
  Command('Publish test artifacts ', './script/publish-test-artifacts.sh')
])

# 3. Filter your pipeline against targets matching changes from base (optional):
#    By default, `GitFilter` uses the BUILDKITE_PULL_REQUEST_BASE_BRANCH environmental variable.
filtered = pipeline.filter(GitFilter())

# 4. Print out the Pipeline YAML. Alternatively, you could write it to a file
#    and then upload it using `buildkite-agent pipeline upload [file]`
#
print(filtered.asyaml())

The pipeline can now be generated as the main executor step in Buildkite:

pip install kitefly
generate_pipeline.py | buildkite-agent pipeline upload

About Filtering

Kitefly provides a model to associate build steps with source "targets", enabling filtering to run fewer builds. This is particularly useful for monorepos.

For example, if the command git ls-files <buildkite-branch>..<base-branch> outputs:

src/lib/util.ts

Then the target_lib target will match, since its filepath spec includes src/lib, and target_app will also be included in the list of targets since target_app has a target dependency on target_lib.

If, on the other hand, the list of files reported by git is:

src/infra/tool.py

Then only the py_files target will match, and so only steps targeting py_files will be included in the pipeline, along with steps that do not specify any target.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kitefly-0.1.0.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kitefly-0.1.0-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file kitefly-0.1.0.tar.gz.

File metadata

  • Download URL: kitefly-0.1.0.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.1

File hashes

Hashes for kitefly-0.1.0.tar.gz
Algorithm Hash digest
SHA256 11499afa348ba201fb94fe472a6dc8f8e2b0578c3abd9d752cec42c16ea001f9
MD5 d781e8a994e1b3700727eb0031a6acb1
BLAKE2b-256 64290f114a606b00d0044b36e411d9b65d9fe0ad3a0c65e16076569335fa8617

See more details on using hashes here.

File details

Details for the file kitefly-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: kitefly-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.1

File hashes

Hashes for kitefly-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9f0c9a484e53fdeac5e5df925609cf57e8f942ae38a307a2dd72e2d3fb574338
MD5 b1fd48f204720fc1b420ffca5949f20d
BLAKE2b-256 df8b421d79699f60f1a02a08e646e192956da107a267f9b058a3c467915ea366

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page