Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ca-johnson committed Jul 24, 2019
0 parents commit 3ac5165
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hooks/environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
hooksDir="${0%/*}"
python "${hooksDir}/../python/setup-hooks.py"
3 changes: 3 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: Metahook
description: Run scripts in a repository as buildkite hooks on a per-step basis
author: https://github.com/ca-johnson
35 changes: 35 additions & 0 deletions python/setup-hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os

HOOKDIR = os.path.join(os.path.dirname(__file__), '..', 'hooks')

hooks = [
# "environment" # not allowed
"pre-checkout",
"checkout",
"post-checkout",
"pre-command",
"command",
"post-command",
"pre-artifact",
"post-artifact",
"pre-exit",
]

def cleanup_metahooks():
"""Remove the temporary hooks"""
hooks = [os.path.join(HOOKDIR, hook) for hook in os.listdir(HOOKDIR)]
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")


def main():
create_metahooks()

if __name__ == "__main__":
main()
23 changes: 23 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Metahook Buildkite Plugin

A Buildkite plugin that allows running additional commands as buildkite hooks on a per-step basis.

# Example

```yaml
common: &common
plugins:
- ca-johnson/metahook:
post-checkout: scripts/setup.sh
pre-exit: scripts/cleanup.sh

steps:
- label: "Build"
command: "scripts/build.sh"
<<: *common

- label: "Test"
command: "scripts/test.sh"
<<: *common

```

0 comments on commit 3ac5165

Please sign in to comment.