Coder Social home page Coder Social logo

journera / monorepo-diff-buildkite-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adikari/monorepo-diff-buildkite-plugin

0.0 1.0 0.0 237 KB

Run separate pipelines for each folder in your monorepo

License: MIT License

Shell 18.43% Makefile 3.31% Go 77.32% Dockerfile 0.94%

monorepo-diff-buildkite-plugin's Introduction

e2e status codecov Publish All Contributors

monorepo-diff-buildkite-plugin

This plugin will assist you in triggering pipelines by watching folders in your monorepo.

Check out this post to learn How to set up Continuous Integration for monorepo using Buildkite.

Using the plugin

If the version number is not provided then the most recent version of the plugin will be used. Do not use version number as master or any branch names.

Simple

steps:
  - label: "Triggering pipelines"
    plugins:
      - chronotc/monorepo-diff#v2.1.1:
          diff: "git diff --name-only HEAD~1"
          watch:
            - path: "bar-service/"
              config:
                command: "echo deploy-bar"
            - path: "foo-service/"
              config:
                trigger: "deploy-foo-service"

Detailed

steps:
  - label: "Triggering pipelines"
    plugins:
      - chronotc/monorepo-diff#v2.1.1:
          diff: "git diff --name-only $(head -n 1 last_successful_build)"
          interpolation: false
          env:
            - env1=env-1 # this will be appended to all env configuration
          hooks:
            - command: "echo $(git rev-parse HEAD) > last_successful_build"
          watch:
            - path:
                - "ops/terraform/"
                - "ops/templates/terraform/"
              config:
                command: "buildkite-agent pipeline upload ops/.buildkite/pipeline.yml"
                label: "Upload pipeline"
                retry:
                  automatic:
                  - limit: 2
                    exit_status: -1
                agents:
                  queue: performance
                artifacts:
                  - "logs/*"
                env:
                  - FOO=bar
            - path: "foo-service/"
              config:
                trigger: "deploy-foo-service"
                label: "Triggered deploy"
                build:
                  message: "Deploying foo service"
                  env:
                    - HELLO=123
                    - AWS_REGION

          wait: true

Configuration

diff (optional)

This will run the script provided to determine the folder changes. Depending on your use case, you may want to determine the point where the branch occurs https://stackoverflow.com/questions/1527234/finding-a-branch-point-with-git and perform a diff against the branch point.

Sample output:

README.md
lib/trigger.bash
tests/trigger.bats

Default: git diff --name-only HEAD~1

Examples:

diff: ./diff-against-last-successful-build.sh

#!/bin/bash

set -ueo pipefail

LAST_SUCCESSFUL_BUILD_COMMIT="$(aws s3 cp "${S3_LAST_SUCCESSFUL_BUILD_COMMIT_PATH}" - | head -n 1)"
git diff --name-only "$LAST_SUCCESSFUL_BUILD_COMMIT"

diff: ./diff-against-last-built-tag.sh

#!/bin/bash

set -ueo pipefail

LATEST_BUILT_TAG=$(git describe --tags --match foo-service-* --abbrev=0)
git diff --name-only "$LATEST_TAG"

interpolation (optional)

This controls the pipeline interpolation on upload, and defaults to true. If set to false it adds --no-interpolation to the buildkite pipeline upload, to avoid trying to interpolate the commit message, which can cause failures.

env (optional)

The object values provided in this configuration will be appended to env property of all steps or commands.

log_level (optional)

Add log_level property to set the log level. Supported log levels are debug and info. Defaults to info.

steps:
  - label: "Triggering pipelines"
    plugins:
      - chronotc/monorepo-diff#v2.1.1:
          diff: "git diff --name-only HEAD~1"
          log_level: "debug" # defaults to "info"
          watch:
            - path: "foo-service/"
              config:
                trigger: "deploy-foo-service"

watch

Declare a list of

- path: app/cms/
  config: # Required [trigger step configuration]
    trigger: cms-deploy # Required [trigger pipeline slug]
- path:
    - services/email
    - assets/images/email
  config:
    trigger: email-deploy

path

If the path specified here in the appears in the diff output, a trigger step will be added to the dynamically generated pipeline.yaml

A list of paths can be provided to trigger the desired pipeline. Changes in any of the paths will initiate the pipeline provided in trigger.

A path can also be a glob pattern. For example specify path: "**/*.md" to match all markdown files.

config

Configuration supports 2 different step types.

Trigger

The configuration for the trigger step https://buildkite.com/docs/pipelines/trigger-step

By default, it will pass the following values to the build attributes unless an alternative values are provided

- path: app/cms/
  config:
    trigger: cms-deploy
    build:
      commit: $BUILDKITE_COMMIT
      branch: $BUILDKITE_BRANCH

wait (optional)

Default: true

By setting wait to true, the build will wait until the triggered pipeline builds are successful before proceeding

hooks (optional)

Currently supports a list of commands you wish to execute after the watched pipelines have been triggered

hooks:
  - command: upload unit tests reports
  - command: echo success

Command

steps:
  - label: "Triggering pipelines"
    plugins:
      - chronotc/monorepo-diff#v2.1.1:
          diff: "git diff --name-only HEAD~1"
          watch:
            - path: app/cms/
              config:
                command: "netlify --production deploy"
                label: ":netlify: Deploy to production"
                agents:
                  queue: "deploy"
                env:
                  - FOO=bar

There is currently limited support for command configuration. Only the command property can be provided at this point in time.

Using commands, it is also possible to use this to upload other pipeline definitions

- path: frontend/
  config:
    command: "buildkite-agent pipeline upload ./frontend/.buildkite/pipeline.yaml"
- path: infrastructure/
  config:
    command: "buildkite-agent pipeline upload ./infrastructure/.buildkite/pipeline.yaml"
- path: backend/
  config:
    command: "buildkite-agent pipeline upload ./backend/.buildkite/pipeline.yaml"

How to Contribute

Please read contributing guide.

Contributors


subash adhikari

πŸ’» πŸ’‘ πŸ“– 🚧 πŸ‘€ ⚠️ πŸš‡

Silla Tan

πŸ’» πŸ’‘ πŸ“– 🚧 πŸ‘€ ⚠️ πŸš‡

Elliott Davis

πŸ’» ⚠️ πŸ€”

Julliano Gonçalves

πŸ’» ⚠️

Lukas Bischofberger

πŸ’» ⚠️ πŸ“– πŸ’‘

Martin Englund

πŸ’» ⚠️

Jacek Szubert

πŸ’»

Ronald Carvalho

πŸ›

Harriet Lawrence

πŸ“– πŸ’‘

Trung LΓͺ

πŸ’» πŸ’‘βš οΈ

Jared Quick

πŸ› πŸ’» ⚠️

monorepo-diff-buildkite-plugin's People

Contributors

adikari avatar allcontributors[bot] avatar chronotc avatar elliott-davis avatar harrietgrace avatar jquick avatar jullianoacqio avatar lstoll avatar pmenglund avatar sleepdeprecation avatar worxli avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.