gitship-core 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/db.d.ts +31 -0
- package/dist/db.js +325 -0
- package/dist/db.js.map +1 -0
- package/dist/engine.d.ts +2 -0
- package/dist/engine.js +373 -0
- package/dist/engine.js.map +1 -0
- package/dist/github.d.ts +25 -0
- package/dist/github.js +98 -0
- package/dist/github.js.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/paths.d.ts +13 -0
- package/dist/paths.js +33 -0
- package/dist/paths.js.map +1 -0
- package/dist/queue.d.ts +10 -0
- package/dist/queue.js +102 -0
- package/dist/queue.js.map +1 -0
- package/package.json +4 -1
- package/src/db.ts +0 -425
- package/src/engine.ts +0 -477
- package/src/github.ts +0 -124
- package/src/paths.ts +0 -35
- package/src/queue.ts +0 -130
- package/tsconfig.json +0 -8
- /package/{src/index.ts → dist/index.d.ts} +0 -0
package/src/queue.ts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { nanoid } from "nanoid";
|
|
2
|
-
import { Deployment, DeploymentStatus } from "gitship-shared";
|
|
3
|
-
import {
|
|
4
|
-
createDeployment,
|
|
5
|
-
getProject,
|
|
6
|
-
getQueuedDeployments,
|
|
7
|
-
getRunningDeployment,
|
|
8
|
-
updateDeploymentStatus,
|
|
9
|
-
getDeployment,
|
|
10
|
-
appendDeploymentLog,
|
|
11
|
-
} from "./db.js";
|
|
12
|
-
import { runDeploymentPipeline } from "./engine.js";
|
|
13
|
-
|
|
14
|
-
// Global map to track active execa processes for cancelling running tasks
|
|
15
|
-
export const activeProcesses = new Map<string, { kill: () => void }>();
|
|
16
|
-
|
|
17
|
-
export async function enqueueDeployment(
|
|
18
|
-
projectId: string,
|
|
19
|
-
branch: string,
|
|
20
|
-
commitSha: string | null,
|
|
21
|
-
commitMessage: string | null,
|
|
22
|
-
author: string | null,
|
|
23
|
-
rollbackOfId: string | null = null
|
|
24
|
-
): Promise<Deployment> {
|
|
25
|
-
const deploymentId = `dep_${nanoid(10)}`;
|
|
26
|
-
const deployment = createDeployment({
|
|
27
|
-
id: deploymentId,
|
|
28
|
-
project_id: projectId,
|
|
29
|
-
branch,
|
|
30
|
-
commit_sha: commitSha,
|
|
31
|
-
commit_message: commitMessage,
|
|
32
|
-
author,
|
|
33
|
-
status: "QUEUED",
|
|
34
|
-
started_at: null,
|
|
35
|
-
finished_at: null,
|
|
36
|
-
total_duration_ms: null,
|
|
37
|
-
rollback_of_id: rollbackOfId,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// Trigger queue processing asynchronously
|
|
41
|
-
processQueue(projectId).catch(err => {
|
|
42
|
-
console.error(`Error processing queue for project ${projectId}:`, err);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
return deployment;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export async function processQueue(projectId: string): Promise<void> {
|
|
49
|
-
// 1. Check if there is already a running deployment for this project
|
|
50
|
-
const running = getRunningDeployment(projectId);
|
|
51
|
-
if (running) {
|
|
52
|
-
// A deployment is already running, wait for it to finish.
|
|
53
|
-
// It will trigger processQueue again upon completion.
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// 2. Get the next queued deployment
|
|
58
|
-
const queued = getQueuedDeployments(projectId);
|
|
59
|
-
if (queued.length === 0) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const nextDeployment = queued[0];
|
|
64
|
-
const project = getProject(projectId);
|
|
65
|
-
|
|
66
|
-
if (!project) {
|
|
67
|
-
console.error(`Project ${projectId} not found for deployment ${nextDeployment.id}`);
|
|
68
|
-
updateDeploymentStatus(nextDeployment.id, "FAILED", {
|
|
69
|
-
finished_at: Date.now(),
|
|
70
|
-
total_duration_ms: 0,
|
|
71
|
-
});
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
// Execute the deployment pipeline
|
|
77
|
-
await runDeploymentPipeline(project, nextDeployment);
|
|
78
|
-
} catch (err) {
|
|
79
|
-
console.error(`Pipeline exception for deployment ${nextDeployment.id}:`, err);
|
|
80
|
-
} finally {
|
|
81
|
-
// Process the next item in the queue
|
|
82
|
-
processQueue(projectId).catch(err => {
|
|
83
|
-
console.error(`Error in queue recursion for project ${projectId}:`, err);
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function cancelDeployment(id: string): { success: boolean; message: string } {
|
|
89
|
-
const dep = getDeployment(id);
|
|
90
|
-
if (!dep) {
|
|
91
|
-
return { success: false, message: "Deployment not found" };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (dep.status === "SUCCESS" || dep.status === "FAILED" || dep.status === "CANCELLED") {
|
|
95
|
-
return { success: false, message: `Deployment already finished with status: ${dep.status}` };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (dep.status === "QUEUED") {
|
|
99
|
-
updateDeploymentStatus(id, "CANCELLED", {
|
|
100
|
-
finished_at: Date.now(),
|
|
101
|
-
total_duration_ms: 0,
|
|
102
|
-
});
|
|
103
|
-
appendDeploymentLog(id, "\n=== Deployment CANCELLED while in queue ===\n");
|
|
104
|
-
return { success: true, message: "Queued deployment cancelled successfully" };
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (dep.status === "RUNNING") {
|
|
108
|
-
// Set status to CANCELLED in DB first
|
|
109
|
-
updateDeploymentStatus(id, "CANCELLED", {
|
|
110
|
-
finished_at: Date.now(),
|
|
111
|
-
});
|
|
112
|
-
appendDeploymentLog(id, "\n=== Deployment CANCELLATION REQUESTED ===\n");
|
|
113
|
-
|
|
114
|
-
// Check if we have an active process to kill
|
|
115
|
-
const proc = activeProcesses.get(id);
|
|
116
|
-
if (proc) {
|
|
117
|
-
try {
|
|
118
|
-
proc.kill();
|
|
119
|
-
activeProcesses.delete(id);
|
|
120
|
-
return { success: true, message: "Running deployment cancelled and terminated" };
|
|
121
|
-
} catch (err: any) {
|
|
122
|
-
return { success: true, message: `Running deployment status set to CANCELLED, but failed to kill process: ${err.message}` };
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return { success: true, message: "Running deployment marked as CANCELLED" };
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return { success: false, message: "Unknown status" };
|
|
130
|
-
}
|
package/tsconfig.json
DELETED
|
File without changes
|