New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement auto deploy on pull requests #24
Conversation
0deb246
to
501dc42
Compare
🎉 Thanks @imella I'll take a look at this as soon as I can, I guess the tests don't run on forks so I'll have to figure that out first here. |
I was reading through the GitHub events and I think there may be a simpler way to write this logic. There is a pull request "synchronized" event which I believe is fired when a PR is pushed: We could add a new listener for this event and just trigger the automatic deployment logic on this event specifically. It would save an extra call to getAssociatedPullRequests as well. |
You're right! I'll check that "synchronized" event and make the necessary changes, thanks! |
bdfce92
to
65e8dde
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
I like using the original PR code so if there are errors this will write comments into the pull request with the error messages.
@imella tested this out, I realized this doesn't wait for the necessary checks before deploying like the code in the Thanks so much for your patience here :) Going to play around with this for a bit... |
Something like this will create a 'watch' on the new ref synchronized by the pull request. This will then wait for the necessary checks before continuing to deploy. I think this is probably a better situation since most people may need to build containers or other artifacts before deploying in a PR. $ git diff src/
diff --git a/src/auto.ts b/src/auto.ts
index 7e48a7e..7909807 100644
--- a/src/auto.ts
+++ b/src/auto.ts
@@ -31,6 +31,7 @@ export function auto(
*/
async function addWatch(
context: Context,
+ matchRef: string, // The ref to match for auto deployments.
ref: string,
sha: string,
repository: PayloadRepository
@@ -40,7 +41,7 @@ export function auto(
const conf = await config(context.github, context.repo());
for (const target in conf) {
const targetVal = conf[target]!;
- if (!match(targetVal.auto_deploy_on, ref)) {
+ if (!match(targetVal.auto_deploy_on, matchRef)) {
continue;
}
context.log.info(
@@ -283,8 +284,28 @@ export function auto(
await addWatch(
context,
context.payload.ref,
+ context.payload.ref,
context.payload.after,
context.payload.repository
);
});
+
+ app.on("pull_request.synchronize", async context => {
+ await addWatch(
+ context,
+ "pr", // If auto_deploy_on matches "pr" then deploy.
+ context.payload.pull_request.head.ref,
+ context.payload.pull_request.head.sha,
+ context.payload.repository,
+ )
+ })
+ app.on("pull_request.opened", async context => {
+ await addWatch(
+ context,
+ "pr", // If auto_deploy_on matches "pr" then deploy.
+ context.payload.pull_request.head.ref,
+ context.payload.pull_request.head.sha,
+ context.payload.repository,
+ )
+ })
}
|
Oh you're right, it doesn't wait for anything. So using 'watches' will only deploy if all checks passes, doesn't it? I'll give it a go with those changes, thanks! |
65e8dde
to
a941136
Compare
Use 'auto_deploy_on: pr' configuration to enable automatic deployments in a pull request. FIXES: deliverybot#10
a941136
to
b741a7d
Compare
Excited to see this in production :) |
Thanks very much @imella! |
Use 'auto_deploy_on: pr' configuration to enable automatic deployments
in a pull request.