Added ability to patch all template repos and push the changes
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@trigger.dev/sdk": patch
|
||||
---
|
||||
|
||||
Fixed an error message
|
||||
@@ -223,7 +223,7 @@ export class HostConnection implements IConnection {
|
||||
new Date().getTime() - this.#closeUnresponsiveConnectionTimeoutMs
|
||||
) {
|
||||
this.#logger.error(
|
||||
"No pong received in last three minutes, closing connection to Interval and retrying..."
|
||||
"No pong received in last three minutes, closing connection to Trigger.dev and retrying..."
|
||||
);
|
||||
if (this.#pingIntervalHandle) {
|
||||
clearInterval(this.#pingIntervalHandle);
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
const { exec } = require("child_process");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const fetch = require("node-fetch");
|
||||
|
||||
const templatesDir = process.argv[2];
|
||||
if (!templatesDir) {
|
||||
console.error("Please provide a path to the templates directory");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// patch is a path to a patch file
|
||||
async function patchTemplate(templateName, patch, message) {
|
||||
const templateDir = path.join(templatesDir, templateName);
|
||||
|
||||
if (fs.statSync(templateDir).isDirectory()) {
|
||||
console.log(`Patching template '${templateName}'`);
|
||||
// Make sure we're on the main branch and there are no uncommitted changes
|
||||
await execAsync(`cd ${templateDir} && git checkout main`);
|
||||
|
||||
// Make sure there are no uncommitted changes
|
||||
const preStatus = await execAsync(`cd ${templateDir} && git status`);
|
||||
|
||||
if (!preStatus.includes("nothing to commit")) {
|
||||
console.error(
|
||||
`There are uncommitted changes in template '${templateName}'`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Make sure we're up to date with the remote
|
||||
await execAsync(`cd ${templateDir} && git pull origin main`);
|
||||
|
||||
// Apply the patch to the template repo
|
||||
await execAsync(`cd ${templateDir} && git apply ${patch}`);
|
||||
|
||||
// Check if there are any changes
|
||||
const status = await execAsync(`cd ${templateDir} && git status`);
|
||||
|
||||
if (!status.includes("modified:")) {
|
||||
console.log(`No changes for template '${templateName}'`);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Changes for template '${templateName}':`, status);
|
||||
|
||||
// Create a commit
|
||||
await execAsync(
|
||||
`cd ${templateDir} && git add -A && git commit -m "[triggerbot] ${message}"`
|
||||
);
|
||||
|
||||
// Push to remote
|
||||
await execAsync(`cd ${templateDir} && git push origin main`);
|
||||
|
||||
console.log(`Applied patch ${patch} to template '${templateName}'`);
|
||||
} else {
|
||||
console.log(`Skipping '${templateName}'`);
|
||||
}
|
||||
}
|
||||
|
||||
async function execAsync(command) {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(command, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(stdout);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// called like so: node scripts/patchTemplates.js /path/to/templates patchFile.patch "Patch message"
|
||||
async function main() {
|
||||
// Make a JSON request to https://app.trigger.dev/api/v1/templates and parse the response as an array of templates
|
||||
const templates = await fetch(
|
||||
"https://app.trigger.dev/api/v1/templates"
|
||||
).then((res) => res.json());
|
||||
|
||||
for (const template of templates) {
|
||||
try {
|
||||
await patchTemplate(template.slug, process.argv[3], process.argv[4]);
|
||||
} catch (error) {
|
||||
console.log(`Failed to update template '${template.slug}'`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
@@ -0,0 +1,23 @@
|
||||
From a15d8456dfb82b88137d40e0fc0202dcc8134231 Mon Sep 17 00:00:00 2001
|
||||
From: Eric Allam <eallam@icloud.com>
|
||||
Date: Thu, 2 Mar 2023 22:46:05 +0000
|
||||
Subject: [PATCH] Update package.json
|
||||
|
||||
---
|
||||
package.json | 3 +++
|
||||
1 file changed, 3 insertions(+)
|
||||
|
||||
diff --git a/package.json b/package.json
|
||||
index f1616fe..d87cec6 100644
|
||||
--- a/package.json
|
||||
+++ b/package.json
|
||||
@@ -25,5 +25,8 @@
|
||||
"tsup": "^6.5.0",
|
||||
"tsx": "^3.12.2",
|
||||
"typescript": "^4.9.4"
|
||||
+ },
|
||||
+ "triggerdotdev": {
|
||||
+ "template": "hello-world"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user