Fixed workflow
This commit is contained in:
parent
db60672370
commit
17ed06f120
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@opencode-ai/plugin": "1.0.142",
|
"@opencode-ai/plugin": "1.0.191",
|
||||||
"@types/micromatch": "^4.0.10",
|
"@types/micromatch": "^4.0.10",
|
||||||
"axios": "^1.13.2",
|
"axios": "^1.13.2",
|
||||||
"micromatch": "^4.0.8",
|
"micromatch": "^4.0.8",
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||||
import type { Plugin } from "@opencode-ai/plugin";
|
import type { Plugin } from "@opencode-ai/plugin";
|
||||||
import { Axios } from "axios";
|
import { Axios } from "axios";
|
||||||
import { promises as fs } from "fs";
|
import { promises as fs } from "fs";
|
||||||
|
|
@ -30,52 +31,69 @@ const updateAppStatus = async (status: "Errored" | "Active" | "Pending") => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const sessionRetries: Record<string, number> = {};
|
||||||
|
|
||||||
export const DevServerHMRPlugin: Plugin = async ({ client, $ }) => {
|
export const DevServerHMRPlugin: Plugin = async ({ client, $ }) => {
|
||||||
return {
|
return {
|
||||||
event: async ({ event }) => {
|
event: async ({ event }) => {
|
||||||
if (event.type !== "session.idle") return;
|
const isMessagedDone =
|
||||||
|
event.type === "message.updated" &&
|
||||||
|
// @ts-ignore
|
||||||
|
event.properties.info["finish"] === "stop";
|
||||||
|
|
||||||
const session = await client.session.get({
|
if (!isMessagedDone) return;
|
||||||
path: { id: event.properties.sessionID },
|
|
||||||
});
|
// @ts-ignore
|
||||||
|
const error = event.properties.info["error"];
|
||||||
|
|
||||||
|
const isAbortionError = error && error.name === "MessageAbortedError";
|
||||||
|
|
||||||
const isAnyChange =
|
const isAnyChange =
|
||||||
session.data?.summary?.files && session.data.summary.files > 0;
|
(await $`git status --porcelain`.quiet()).stdout.toString().trim() !==
|
||||||
|
"";
|
||||||
|
|
||||||
if (!isAnyChange) {
|
if (!isAnyChange || isAbortionError) {
|
||||||
await updateAppStatus("Active");
|
await updateAppStatus("Active");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("Building...");
|
||||||
|
|
||||||
const result = await $`pnpm build`.quiet().catch((error) => error);
|
const result = await $`pnpm build`.quiet().catch((error) => error);
|
||||||
|
|
||||||
if (result.exitCode !== 0) {
|
if (result.exitCode !== 0) {
|
||||||
if (!client.session["tries"]) {
|
if (!sessionRetries[event.properties.info.sessionID]) {
|
||||||
client.session["tries"] = 0;
|
sessionRetries[event.properties.info.sessionID] = 1;
|
||||||
} else {
|
} else {
|
||||||
client.session["tries"]++;
|
sessionRetries[event.properties.info.sessionID]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client.session["tries"] > 3) {
|
if (sessionRetries[event.properties.info.sessionID] > 3) {
|
||||||
await updateAppStatus("Errored");
|
await updateAppStatus("Errored");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await client.session.prompt({
|
console.log(
|
||||||
path: { id: event.properties.sessionID },
|
`Retrying... ${sessionRetries[event.properties.info.sessionID]}`
|
||||||
|
);
|
||||||
|
|
||||||
|
await client.session.promptAsync({
|
||||||
|
path: { id: event.properties.info.sessionID },
|
||||||
body: {
|
body: {
|
||||||
parts: [
|
parts: [
|
||||||
{
|
{
|
||||||
type: "text",
|
type: "text",
|
||||||
text: `While building the project, the following error occurred:\n\n${result.stderr.toString()}\n\nPlease fix the error and try again.`,
|
text: `While building the project, the following error occurred:\n\n${result.stdout.toString()}\n\nPlease fix the error and try again.`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sessionRetries[event.properties.info.sessionID] = 1;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const packageJson = JSON.parse(
|
const packageJson = JSON.parse(
|
||||||
await fs.readFile("package.json", "utf-8")
|
await fs.readFile("package.json", "utf-8")
|
||||||
|
|
@ -86,23 +104,30 @@ export const DevServerHMRPlugin: Plugin = async ({ client, $ }) => {
|
||||||
const newVersion = `${major}.${minor}.${patch + 1}`;
|
const newVersion = `${major}.${minor}.${patch + 1}`;
|
||||||
|
|
||||||
const messages = await client.session.messages({
|
const messages = await client.session.messages({
|
||||||
path: { id: event.properties.sessionID },
|
path: { id: event.properties.info.sessionID },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!messages.data) {
|
if (!messages.data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const title = messages.data
|
const currentMessage = messages.data
|
||||||
.reverse()
|
.reverse()
|
||||||
.find(
|
.find(
|
||||||
(message) =>
|
(message) =>
|
||||||
message.info.role === "user" &&
|
message.info.role === "user" &&
|
||||||
message.info.summary &&
|
message.info.summary &&
|
||||||
message.info.summary.title
|
message.info.summary.title
|
||||||
)?.info.summary?.["title"];
|
);
|
||||||
|
|
||||||
const commitMessage = title ?? `feat: release version v${newVersion}`;
|
if (!currentMessage) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const commitMessage =
|
||||||
|
// @ts-ignore
|
||||||
|
currentMessage.info.summary?.["title"] ??
|
||||||
|
`feat: release version v${newVersion}`;
|
||||||
|
|
||||||
packageJson.version = newVersion;
|
packageJson.version = newVersion;
|
||||||
|
|
||||||
|
|
@ -111,10 +136,8 @@ export const DevServerHMRPlugin: Plugin = async ({ client, $ }) => {
|
||||||
JSON.stringify(packageJson, null, 2)
|
JSON.stringify(packageJson, null, 2)
|
||||||
);
|
);
|
||||||
|
|
||||||
await $`git config user.name "Taylor AI"`.quiet();
|
|
||||||
await $`git config user.email "ai@taylordb.io"`.quiet();
|
|
||||||
await $`git add .`.quiet();
|
await $`git add .`.quiet();
|
||||||
await $`git commit -m ${commitMessage}`.quiet();
|
await $`GIT_AUTHOR_NAME="Taylor AI" GIT_AUTHOR_EMAIL="ai@taylordb.io" GIT_COMMITTER_NAME="Taylor AI" GIT_COMMITTER_EMAIL="ai@taylordb.io" git commit -m ${commitMessage}`.quiet();
|
||||||
await $`git tag v${newVersion}`.quiet();
|
await $`git tag v${newVersion}`.quiet();
|
||||||
await $`git push origin main --tags`.quiet();
|
await $`git push origin main --tags`.quiet();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user