Skip to content

Commit 0a22cd6

Browse files
authored
Auto deploy by hook (#24)
* Support triggering builds on Netlify automatically * Update version
1 parent fac3dc0 commit 0a22cd6

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
...
66

7+
## v0.7
8+
9+
### Added
10+
11+
- Support triggering builds on Netlify automatically
12+
713
## v0.6
814

915
### Added

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Deploy your Wagtail site on Netlify. Features include:
2020

2121
1. Add `wagtailnetlify` to your `INSTALLED_APPS`.
2222
2. Run the migrations: `./manage.py migrate wagtailnetlify`.
23-
3. Add `NETLIFY_PATH` to your settings.
23+
3. Add `NETLIFY_PATH` or `NETLIFY_BUILD_HOOK` to your settings.
2424

2525
Check the [Settings](#settings) section below for more customisation options.
2626

@@ -30,7 +30,11 @@ If `NETLIFY_AUTO_DEPLOY` is set to `True`, Wagtail will automatically deploy you
3030

3131
*or*
3232

33-
To deploy changes manually, use `./manage.py netlify`. To generate redirects without deploying, use the `-n` or `--no-deploy` flag: `./manage.py netlify --no-deploy`. To trigger a build on Netlify's servers, configure `settings.NETLIFY_BUILD_HOOK` and use the `-t` or `--trigger-build` flag: `./manage.py netlify --trigger-build`.
33+
To deploy changes manually, use `./manage.py netlify`.
34+
35+
To generate redirects without deploying, use the `-n` or `--no-deploy` flag: `./manage.py netlify --no-deploy`.
36+
37+
To trigger a build on Netlify's servers, configure `settings.NETLIFY_BUILD_HOOK` and use the `-t` or `--trigger-build` flag: `./manage.py netlify --trigger-build`.
3438

3539
## Settings
3640

@@ -56,9 +60,9 @@ Connect to your Netlify account to [generate a token](https://app.netlify.com/ac
5660

5761
### `NETLIFY_AUTO_DEPLOY`
5862

59-
**Default: `True`**
63+
**Default: `False`**
6064

61-
Whether to automatically deploy your site to Netlify every time you publish a page. This make take between a few seconds and a few minutes, depending on the size of your site, and the number of pages which are affected by your change.
65+
Whether to automatically deploy your site to Netlify every time you publish a page. This make take between a few seconds and a few minutes, depending on the size of your site, and the number of pages which are affected by your change. If you have configured `settings.NETLIFY_BUILD_HOOK`, publishing a page will trigger a build on Netlify's servers.
6266

6367
### `NETLIFY_DEPLOY_FUNCTION`
6468

wagtailnetlify/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.6"
1+
__version__ = "0.7"

wagtailnetlify/models.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,43 @@ class Deployment(models.Model):
1515
netlify_id = models.CharField(max_length=30, null=True)
1616
url = models.URLField(null=True)
1717
deployment_url = models.URLField(null=True)
18-
datetime_started = models.DateTimeField(auto_now_add=True, help_text='deployment started')
19-
datetime_finished = models.DateTimeField('deployment completed', null=True)
18+
datetime_started = models.DateTimeField(
19+
auto_now_add=True, help_text="deployment started"
20+
)
21+
datetime_finished = models.DateTimeField("deployment completed", null=True)
2022

2123

2224
def postpone(function):
2325
"""
2426
Cheap aysnc, see https://stackoverflow.com/a/28913218
2527
"""
28+
2629
def decorator(*args, **kwargs):
2730
t = Thread(target=function, args=args, kwargs=kwargs)
2831
t.daemon = True
2932
t.start()
33+
3034
return decorator
3135

3236

3337
@postpone
3438
def deploy(sender, **kwargs):
3539
"""
36-
Build static pages, then send incremental changes to netlify.
40+
Trigger a build on Netlify, if NETLIFY_BUILD_HOOK is supplied, or
41+
build static pages, then upload incremental changes to Netlify.
3742
"""
38-
call_command('build')
39-
call_command('netlify')
43+
netlify_build_hook = getattr(settings, "NETLIFY_BUILD_HOOK", None)
44+
if netlify_build_hook:
45+
call_command("netlify", "--trigger-build")
46+
else:
47+
call_command("build")
48+
call_command("netlify")
4049
connection.close()
4150

4251

43-
if getattr(settings, 'NETLIFY_AUTO_DEPLOY', False) == True:
44-
function_path = getattr(settings, 'NETLIFY_DEPLOY_FUNCTION', 'wagtailnetlify.models.deploy')
52+
if getattr(settings, "NETLIFY_AUTO_DEPLOY", False) == True:
53+
function_path = getattr(
54+
settings, "NETLIFY_DEPLOY_FUNCTION", "wagtailnetlify.models.deploy"
55+
)
4556
function = import_string(function_path)
4657
page_published.connect(function)

0 commit comments

Comments
 (0)