Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ my-site.json
{
"path": "/home/code/my-site",
"release": {
"build": "yarn && yarn build",
"deploy": "rsync -av --delete public/ /var/www/html/my-site"
"build": "yarn && yarn build && tar -xvf {{release.sha}}.tar.gz", # you may use handlebar notation to inject GitHub payload values into your steps
"deploy": "rsync -av --delete public/ /var/www/html/my-site",
"cleanup": "rm -rf node_modules/ && rm -rf .cache/ && yarn cache clean"
}
}
```

### Adding listener to GitHub Webhooks

As of `v0.1.0` - Only the `release` event is supported.
As of `v0.2.1` - Only the `release` event is supported.

`https://{domain}/webhooks/{repo}`
or
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name="github-webhooks-listener",
version="0.2.0",
version="0.2.1",
author="Matt Suhay",
author_email="matt@suhay.dev",
description="A simple listener that will trigger custom scripts when it receives events from GitHub.",
Expand All @@ -26,7 +26,8 @@
],
install_requires=[
'quart',
'python-dotenv'
'python-dotenv',
'pybars3'
],
python_requires='>=3.8',
)
23 changes: 16 additions & 7 deletions src/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

from os import path
from pathlib import Path
from pybars import Compiler

compiler = Compiler()

def processRelease(repo, payload):
base_path = Path(__file__).parent
Expand All @@ -27,13 +29,19 @@ def processRelease(repo, payload):
commands.append('nvm use ' + data['node'])

if 'build' in data['release'].keys():
commands.append(data['release']['build'])
source = data['release']['build']
template = compiler.compile(source)
commands.append(template(payload))

if 'deploy' in data['release'].keys():
commands.append(data['release']['deploy'])
source = data['release']['deploy']
template = compiler.compile(source)
commands.append(template(payload))

if 'cleanup' in data['release'].keys():
commands.append(data['release']['cleanup'])
source = data['release']['cleanup']
template = compiler.compile(source)
commands.append(template(payload))

subprocess.check_call(['git', 'fetch', '--all', '--tags'], cwd=data['path'])
subprocess.check_call(['git', 'checkout', 'tags/' + payload['release']['tag_name']], cwd=data['path'])
Expand All @@ -42,11 +50,12 @@ def processRelease(repo, payload):
try:
process.communicate(timeout=300)
except subprocess.TimeoutExpired:
print('Process was killed by timeout: 300 seconds.')
print('Process was killed by timeout: 300 seconds')
raise
finally:
if process.poll() is None:
process.kill()
process.communicate()
print('Process complete')
process.kill()
process.communicate()
print('Release complete!')

return
12 changes: 12 additions & 0 deletions src/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from pybars import Compiler

compiler = Compiler()


source = r'tar xzf /project/repo/{{release.sha}}.tar.gz'
template = compiler.compile(source)
print(template({
'release': {
'sha': '302f2b072d46b2f48706eb156f162d901be2c088'
}
}))