Skip to content

Commit f79e2e5

Browse files
authored
Merge pull request #9 from suhay/8-github-injection
Adding in payload injection from github post json
2 parents e07a655 + 7ba511e commit f79e2e5

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ my-site.json
3333
{
3434
"path": "/home/code/my-site",
3535
"release": {
36-
"build": "yarn && yarn build",
37-
"deploy": "rsync -av --delete public/ /var/www/html/my-site"
36+
"build": "yarn && yarn build && tar -xvf {{release.sha}}.tar.gz", # you may use handlebar notation to inject GitHub payload values into your steps
37+
"deploy": "rsync -av --delete public/ /var/www/html/my-site",
38+
"cleanup": "rm -rf node_modules/ && rm -rf .cache/ && yarn cache clean"
3839
}
3940
}
4041
```
4142

4243
### Adding listener to GitHub Webhooks
4344

44-
As of `v0.1.0` - Only the `release` event is supported.
45+
As of `v0.2.1` - Only the `release` event is supported.
4546

4647
`https://{domain}/webhooks/{repo}`
4748
or

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
setup(
1010
name="github-webhooks-listener",
11-
version="0.2.0",
11+
version="0.2.1",
1212
author="Matt Suhay",
1313
author_email="matt@suhay.dev",
1414
description="A simple listener that will trigger custom scripts when it receives events from GitHub.",
@@ -26,7 +26,8 @@
2626
],
2727
install_requires=[
2828
'quart',
29-
'python-dotenv'
29+
'python-dotenv',
30+
'pybars3'
3031
],
3132
python_requires='>=3.8',
3233
)

src/release.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
from os import path
66
from pathlib import Path
7+
from pybars import Compiler
78

9+
compiler = Compiler()
810

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

2931
if 'build' in data['release'].keys():
30-
commands.append(data['release']['build'])
32+
source = data['release']['build']
33+
template = compiler.compile(source)
34+
commands.append(template(payload))
3135

3236
if 'deploy' in data['release'].keys():
33-
commands.append(data['release']['deploy'])
37+
source = data['release']['deploy']
38+
template = compiler.compile(source)
39+
commands.append(template(payload))
3440

3541
if 'cleanup' in data['release'].keys():
36-
commands.append(data['release']['cleanup'])
42+
source = data['release']['cleanup']
43+
template = compiler.compile(source)
44+
commands.append(template(payload))
3745

3846
subprocess.check_call(['git', 'fetch', '--all', '--tags'], cwd=data['path'])
3947
subprocess.check_call(['git', 'checkout', 'tags/' + payload['release']['tag_name']], cwd=data['path'])
@@ -42,11 +50,12 @@ def processRelease(repo, payload):
4250
try:
4351
process.communicate(timeout=300)
4452
except subprocess.TimeoutExpired:
45-
print('Process was killed by timeout: 300 seconds.')
53+
print('Process was killed by timeout: 300 seconds')
4654
raise
4755
finally:
48-
if process.poll() is None:
49-
process.kill()
50-
process.communicate()
56+
print('Process complete')
57+
process.kill()
58+
process.communicate()
59+
print('Release complete!')
5160

5261
return

src/test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from pybars import Compiler
2+
3+
compiler = Compiler()
4+
5+
6+
source = r'tar xzf /project/repo/{{release.sha}}.tar.gz'
7+
template = compiler.compile(source)
8+
print(template({
9+
'release': {
10+
'sha': '302f2b072d46b2f48706eb156f162d901be2c088'
11+
}
12+
}))

0 commit comments

Comments
 (0)