gitgreen 1.1.2 → 1.1.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/init.js
CHANGED
|
@@ -12,6 +12,7 @@ const prompts_1 = __importDefault(require("prompts"));
|
|
|
12
12
|
const kleur_1 = require("kleur");
|
|
13
13
|
const power_profile_repository_1 = require("./lib/carbon/power-profile-repository");
|
|
14
14
|
const output_integrations_1 = require("./lib/integrations/output-integrations");
|
|
15
|
+
const migration_runner_1 = require("./lib/integrations/migration-runner");
|
|
15
16
|
const hasGlab = () => {
|
|
16
17
|
try {
|
|
17
18
|
(0, child_process_1.execSync)('glab --version', { stdio: 'ignore' });
|
|
@@ -123,6 +124,44 @@ const promptIntegrationFields = async (integration) => {
|
|
|
123
124
|
}
|
|
124
125
|
return { variables: collected, values: valuesByField };
|
|
125
126
|
};
|
|
127
|
+
const runIntegrationMigrations = async (integration, values) => {
|
|
128
|
+
const table = values.table || values.TABLE || values.target_table;
|
|
129
|
+
const database = values.database;
|
|
130
|
+
const host = values.host;
|
|
131
|
+
const username = values.username;
|
|
132
|
+
const password = values.password;
|
|
133
|
+
if (!table || !database || !host || !username || !password)
|
|
134
|
+
return;
|
|
135
|
+
const scope = integration.target;
|
|
136
|
+
if (integration.driver === 'postgres') {
|
|
137
|
+
await (0, migration_runner_1.runMigrations)({
|
|
138
|
+
driver: 'postgres',
|
|
139
|
+
host,
|
|
140
|
+
port: Number(values.port || 5432),
|
|
141
|
+
username,
|
|
142
|
+
password,
|
|
143
|
+
database,
|
|
144
|
+
schema: values.schema || 'public',
|
|
145
|
+
sslMode: values.sslmode,
|
|
146
|
+
table,
|
|
147
|
+
timeseriesTable: scope === 'job' ? `${table}_timeseries` : undefined,
|
|
148
|
+
scope
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
await (0, migration_runner_1.runMigrations)({
|
|
153
|
+
driver: 'mysql',
|
|
154
|
+
host,
|
|
155
|
+
port: Number(values.port || 3306),
|
|
156
|
+
username,
|
|
157
|
+
password,
|
|
158
|
+
database,
|
|
159
|
+
table,
|
|
160
|
+
timeseriesTable: scope === 'job' ? `${table}_timeseries` : undefined,
|
|
161
|
+
scope
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
};
|
|
126
165
|
const selectIntegrationForTarget = async (target) => {
|
|
127
166
|
const available = output_integrations_1.outputIntegrations.filter(integration => integration.target === target);
|
|
128
167
|
if (!available.length)
|
|
@@ -161,6 +200,13 @@ const selectIntegrationForTarget = async (target) => {
|
|
|
161
200
|
process.exit(1);
|
|
162
201
|
}
|
|
163
202
|
}
|
|
203
|
+
try {
|
|
204
|
+
await runIntegrationMigrations(integration, values);
|
|
205
|
+
}
|
|
206
|
+
catch (err) {
|
|
207
|
+
console.log((0, kleur_1.red)(`Failed to run migrations for ${integration.name}: ${err?.message || err}`));
|
|
208
|
+
process.exit(1);
|
|
209
|
+
}
|
|
164
210
|
return variables;
|
|
165
211
|
};
|
|
166
212
|
const promptOutputIntegrations = async (stepNumber) => {
|
|
@@ -9,6 +9,7 @@ const buildMysqlIntegration = (target) => {
|
|
|
9
9
|
return {
|
|
10
10
|
id: `mysql-${scope}`,
|
|
11
11
|
name: `MySQL (${scope === 'job' ? 'per-job emissions' : 'runner inventory'})`,
|
|
12
|
+
driver: 'mysql',
|
|
12
13
|
description: target === 'job'
|
|
13
14
|
? 'Store each CI job calculation (emissions, runtime, runner tags) inside a MySQL table.'
|
|
14
15
|
: 'Store runner metadata (machine type, scope 3 estimates, tags) alongside usage metrics.',
|
|
@@ -78,6 +79,7 @@ const buildPostgresIntegration = (target) => {
|
|
|
78
79
|
return {
|
|
79
80
|
id: `postgres-${scope}`,
|
|
80
81
|
name: `PostgreSQL (${scope === 'job' ? 'per-job emissions' : 'runner inventory'})`,
|
|
82
|
+
driver: 'postgres',
|
|
81
83
|
description: target === 'job'
|
|
82
84
|
? 'Insert each CI job calculation into a PostgreSQL table for downstream analytics.'
|
|
83
85
|
: 'Persist runner metadata in PostgreSQL so you can track each machine in your fleet.',
|