From 42dc60b5c30f8997fcc6256c105bb9c553220916 Mon Sep 17 00:00:00 2001 From: Carl Johnson Date: Wed, 24 Jul 2019 15:46:03 -0600 Subject: [PATCH] initial working version --- .buildkite/local-pipeline.yml | 9 +++++++++ .gitignore | 6 ++++++ Makefile | 6 ++++++ hooks/environment | 2 ++ hooks/environment.sh | 3 --- python/setup-hooks.py | 13 ++++++++----- readme.md | 3 +-- 7 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 .buildkite/local-pipeline.yml create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 hooks/environment delete mode 100644 hooks/environment.sh diff --git a/.buildkite/local-pipeline.yml b/.buildkite/local-pipeline.yml new file mode 100644 index 0000000..aacab4a --- /dev/null +++ b/.buildkite/local-pipeline.yml @@ -0,0 +1,9 @@ +steps: + - label: "Test" + command: echo "Hello World" + plugins: + - ./.buildkite/plugins/metahook: + pre-command: echo "pre-command hook" + command: echo "command hook" + post-command: echo "post-command hook" + pre-exit: echo "pre-exit hook" \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f34646c --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +__pycache__/ +*.py[cod] + +.buildkite/plugins +.vscode +.pytest_cache diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..340a609 --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +local_run: vendorize + bk local run .buildkite/local-pipeline.yml + +vendorize: + mkdir .buildkite/plugins/metahook -p + cp hooks python plugin.yml .buildkite/plugins/metahook/ -rf diff --git a/hooks/environment b/hooks/environment new file mode 100644 index 0000000..beaadfe --- /dev/null +++ b/hooks/environment @@ -0,0 +1,2 @@ +#!/bin/bash +python "${BASH_SOURCE%/*}/../python/setup-hooks.py" diff --git a/hooks/environment.sh b/hooks/environment.sh deleted file mode 100644 index 0b7f7a7..0000000 --- a/hooks/environment.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -hooksDir="${0%/*}" -python "${hooksDir}/../python/setup-hooks.py" \ No newline at end of file diff --git a/python/setup-hooks.py b/python/setup-hooks.py index 340c806..7ff2732 100644 --- a/python/setup-hooks.py +++ b/python/setup-hooks.py @@ -17,18 +17,21 @@ def cleanup_metahooks(): """Remove the temporary hooks""" - hooks = [os.path.join(HOOKDIR, hook) for hook in os.listdir(HOOKDIR)] + hooks = [os.path.join(HOOKDIR, hook) for hook in os.listdir(HOOKDIR) if hook != 'environment'] for hook in hooks: - if hook == 'environment.sh': - continue # skip the geniuine plugin hook os.remove(hook) def create_metahooks(): - with open(os.path.join(HOOKDIR, 'pre-checkout.sh'), 'w') as outfile: - outfile.write("ls") + for hook in hooks: + content = os.environ.get("BUILDKITE_PLUGIN_METAHOOK_%s" % hook.replace('-', '_').upper()) + if not content: + continue + with open(os.path.join(HOOKDIR, hook), 'w') as outfile: + outfile.write(content) def main(): + cleanup_metahooks() create_metahooks() if __name__ == "__main__": diff --git a/readme.md b/readme.md index e483f63..610a0fc 100644 --- a/readme.md +++ b/readme.md @@ -18,6 +18,5 @@ steps: - label: "Test" command: "scripts/test.sh" - <<: *common - + <<: *common ``` \ No newline at end of file