Skip to content

Commit

Permalink
Fix hooks/command
Browse files Browse the repository at this point in the history
  • Loading branch information
ksindi committed Apr 5, 2020
1 parent 830d042 commit 8e390e2
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 64 deletions.
16 changes: 0 additions & 16 deletions Dockerfile

This file was deleted.

15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
help:
@echo "clean - remove artifacts"
@echo "test - run unit test and test buildkite plugin"
@echo "release - package and upload a release"
@echo "dist - package"

clean: clean-build

Expand All @@ -18,15 +20,24 @@ clean-build:
lint: lint-plugin

lint-plugin:
docker-compose run --rm lint
docker-compose run --rm buildkite_plugin_linter

test: test-unit test-plugin

test-unit:
python setup.py test

test-plugin:
docker-compose up --build tests
docker-compose up --build buildkite_plugin_tester

version:
python setup.py --version

release: clean
python setup.py sdist upload
python setup.py bdist_wheel upload

dist: clean
python setup.py sdist
python setup.py bdist_wheel
ls -l dist
47 changes: 31 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Buildpipe
=========

A Buildkite plugin to dynamically generate pipelines. Especially useful
for monorepos.
for monorepos where you want to create dependencies between projects.

Example
-------
Expand All @@ -27,7 +27,7 @@ steps:
- build
path:
- project3/
- project2/somedir/ # project3 steps will also be trigger by changes in this dir
- project2/somedir/ # project3 steps will also be triggered by changes in this dir
```
### dynamic\_pipeline.yml
Expand Down Expand Up @@ -116,24 +116,39 @@ Other useful things to note:
`diff` command
--------------

The default `diff` commands are (run in the order shown):
Depending on your [merge
strategy](https://help.github.com/en/github/administering-a-repository/about-merge-methods-on-github),
you might need to use different diff command.

Buildpipe assumes you are using a merge strategy on the master branch.


Requirements
------------

Python3 and pip3 are currently required, but we have plant to convert it into a binary with Golang.

Just make sure to install them in your agent bootstrap script or Dockerfile.

```bash
# Used to check if on a feature branch and check diff against master
git diff --name-only origin/master...HEAD

# Useful for checking master against master in a merge commit strategy environment
git diff --name-only HEAD HEAD~1
### Cloudformation bootstrap script

```bash
# Install python3
yum -y install python3 python3-pip
pip3 install -U setuptools wheel
```

Both of the above commands are run, in their order listed above to
detect if there is any `diff`.
### Agent Dockerfile

Depending on your [merge
strategy](https://help.github.com/en/github/administering-a-repository/about-merge-methods-on-github),
you might need to use different [diff]{.title-ref} commands.
```
FROM buildkite/agent:3.0

RUN apk add --no-cache \
# Languages
python3 py-setuptools
```
Buildpipe assumes you are using a merge strategy on the master branch.
Troubleshooting
---------------
Expand Down Expand Up @@ -166,8 +181,8 @@ License

MIT

Acknowledgement
---------------
Acknowledgements
----------------

The rewrite to a plugin was inspired by
[git-diff-conditional-buildkite-plugin](https://github.com/Zegocover/git-diff-conditional-buildkite-plugin).
13 changes: 12 additions & 1 deletion buildpipe/__main__.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
"""Dynamically generate Buildkite pipeline artifact based on git changes."""
import argparse
from fnmatch import fnmatch
import io
import logging
Expand All @@ -12,6 +13,8 @@
from ruamel.yaml import YAML
from ruamel.yaml.scanner import ScannerError

from buildpipe import __version__


PLUGIN_PREFIX = "BUILDKITE_PLUGIN_BUILDPIPE_"

Expand Down Expand Up @@ -199,7 +202,15 @@ def get_projects() -> List[dict]:
return projects


if __name__ == "__main__":
def create_parser():
parser = argparse.ArgumentParser()
parser.add_argument("--version", "-V", action="version", version=__version__)
return parser


def main():
parser = create_parser()
parser.parse_args()
projects = get_projects()
affected_projects = get_affected_projects(projects)
if not affected_projects:
Expand Down
10 changes: 4 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
version: '2'
version: '3'
services:
tests:
buildkite_plugin_tester:
build:
context: .
dockerfile: Dockerfile-test
volumes:
- ".:/plugin:ro"
lint:
dockerfile: tests/Dockerfile
buildkite_plugin_linter:
image: buildkite/plugin-linter
command: ['--id', 'jwplayer/buildpipe']
volumes:
Expand Down
10 changes: 7 additions & 3 deletions hooks/command
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/bash
set -euo pipefail

basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
buildpipe_version="${BUILDKITE_PLUGIN_BUILDPIPE_VERSION:-0.7.0}"

docker build $basedir -t buildpipe > /dev/null
if [[ "$BUILDKITE_PLUGIN_BUILDPIPE_RUN_MODE" == "test" ]]; then
python3 setup.py install
else
pip3 install buildpipe==$buildpipe_version
fi

docker run --rm --env-file <(env | grep BUILDKITE) buildpipe
buildpipe
6 changes: 0 additions & 6 deletions hooks/post-command

This file was deleted.

3 changes: 2 additions & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Buildpipe
description: Dynamically generate Buildkite pipelines based on project changes
author: https://github.com/ksindi
requirements:
- docker
- python3
- pip3
configuration:
properties:
diff:
Expand Down
1 change: 0 additions & 1 deletion requirements.txt

This file was deleted.

13 changes: 5 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
with open("README.md") as f_readme:
readme = f_readme.read()

with open("requirements.txt") as f:
install_requires = f.read().splitlines()

setup(
name="buildpipe",
description="Dynamically generate Buildkite pipelines",
Expand All @@ -17,18 +14,18 @@
use_scm_version=True,
author="Kamil Sindi",
author_email="[email protected]",
url="https://github.com/jwplayer/buildpipe",
url="https://github.com/jwplayer/buildpipe-buildkite-plugin",
keywords="pipeline buildkite buildkite-plugin cicd".split(),
license="MIT",
install_requires=install_requires,
setup_requires=["pytest-runner", "setuptools_scm",],
tests_require=["pytest", "pytest-cov", "pytest-flake8",],
install_requires=["ruamel.yaml>=0.16.10", "setuptools_scm"],
setup_requires=["pytest-runner"],
tests_require=["pytest", "pytest-cov", "pytest-flake8"],
include_package_data=True,
zip_safe=False,
entry_points={"console_scripts": ["buildpipe=buildpipe.__main__:main"]},
classifiers=textwrap.dedent(
"""
Development Status :: 5 - Production/Stable
Development Status :: 4 - Beta
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Environment :: Console
Expand Down
3 changes: 1 addition & 2 deletions Dockerfile-test → tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ RUN apk add --update-cache \
&& python3 -m ensurepip \
&& rm -rf /var/cache/apk/*

COPY requirements.txt ./
RUN pip3 install --no-cache-dir -r requirements.txt
COPY . .

CMD ["bats", "tests/"]
4 changes: 3 additions & 1 deletion tests/post-command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ setup() {

teardown() {
unstub git
# TODO: fix not being able to unstub
# unstub buildkite-agent
}

Expand All @@ -22,9 +23,10 @@ teardown() {
export BUILDKITE_PLUGIN_BUILDPIPE_PROJECTS_1_PATH_0="project1"
export BUILDKITE_PLUGIN_BUILDPIPE_PROJECTS_1_PATH_1="project0"
export BUILDKITE_PLUGIN_BUILDPIPE_LOG_LEVEL="DEBUG"
export BUILDKITE_PLUGIN_BUILDPIPE_RUN_MODE="test"
export BUILDKITE_BRANCH="not_master"

run python3 "$PWD/buildpipe"
run hooks/command

assert_success
assert_output --partial "label: test project0"
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = docs,flake8,py36,py37
envlist = docs,flake8,py36,py37,py38
skipsdist=True

[testenv]
Expand Down

0 comments on commit 8e390e2

Please sign in to comment.