buildnator-personal 0.0.5 → 0.1.0
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/buildnator.client.ts +167 -53
- package/dist/buildnator.client.js +511 -725
- package/index.ts +2 -0
- package/package.json +5 -4
- package/tsconfig.json +7 -2
- package/types.ts +3 -1
package/buildnator.client.ts
CHANGED
|
@@ -3,6 +3,7 @@ import * as https from "https";
|
|
|
3
3
|
import type { BuildnatorConfig, JobsConfig, QueryValue } from "./types";
|
|
4
4
|
|
|
5
5
|
const DEFAULT_BUILD_DELAY_MS = 15000;
|
|
6
|
+
const DEFAULT_FILA_DELAY_MS = 15000;
|
|
6
7
|
|
|
7
8
|
const DEFAULT_JOBS: JobsConfig = {
|
|
8
9
|
agmCompila: "/job/GCS-AGM-Compila%C3%A7%C3%A3o-Automatizada",
|
|
@@ -15,7 +16,9 @@ const DEFAULT_JOBS: JobsConfig = {
|
|
|
15
16
|
publicarDllsNuget: "/job/GCS-AGB-Publicar-dlls-NuGet",
|
|
16
17
|
testeTaVersaoEvolutiva: "/job/QA%20-%20TA%20-%20AGB%20-%20TESTES%20AUTOMATIZADOS%20VERSAO%20EVOLUTIVA%20(GCS)",
|
|
17
18
|
unificarCommits: "/job/GCS-Unificar-commits",
|
|
18
|
-
criarbackup: "job/GCS-CriarBackup"
|
|
19
|
+
criarbackup: "job/GCS-CriarBackup",
|
|
20
|
+
recriarBranch: "view/Ger%C3%AAncia%20de%20Configura%C3%A7%C3%A3o/job/GCS-RecriarBranch/"
|
|
21
|
+
|
|
19
22
|
};
|
|
20
23
|
|
|
21
24
|
function normalizeBaseUrl(url: string): string {
|
|
@@ -27,6 +30,7 @@ export class BuildnatorClient {
|
|
|
27
30
|
private readonly auth: { username: string; password: string };
|
|
28
31
|
private readonly jobs: JobsConfig;
|
|
29
32
|
private readonly buildDelayMs: number;
|
|
33
|
+
private readonly filaDelayMs: number;
|
|
30
34
|
|
|
31
35
|
constructor(private readonly config: BuildnatorConfig) {
|
|
32
36
|
if (!config?.jenkins?.baseUrl || !config.jenkins.user || !config.jenkins.token) {
|
|
@@ -45,25 +49,9 @@ export class BuildnatorClient {
|
|
|
45
49
|
httpsAgent,
|
|
46
50
|
});
|
|
47
51
|
|
|
48
|
-
/*if (config.gateway?.baseUrl) {
|
|
49
|
-
this.gateway = axios.create({
|
|
50
|
-
baseURL: normalizeBaseUrl(config.gateway.baseUrl),
|
|
51
|
-
httpsAgent,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
this.gateway.interceptors.request.use((req) => {
|
|
55
|
-
const token = config.gateway?.restrictToken;
|
|
56
|
-
if (token) {
|
|
57
|
-
const url = new URL(req.url ?? "", req.baseURL);
|
|
58
|
-
url.searchParams.append("token", token);
|
|
59
|
-
req.url = url.toString();
|
|
60
|
-
}
|
|
61
|
-
return req;
|
|
62
|
-
});
|
|
63
|
-
}*/
|
|
64
|
-
|
|
65
52
|
this.jobs = { ...DEFAULT_JOBS, ...(config.jobs ?? {}) };
|
|
66
53
|
this.buildDelayMs = config.delays?.buildTriggerMs ?? DEFAULT_BUILD_DELAY_MS;
|
|
54
|
+
this.filaDelayMs = config.delays?.filaMs ?? DEFAULT_FILA_DELAY_MS
|
|
67
55
|
}
|
|
68
56
|
|
|
69
57
|
private sleep(ms: number): Promise<void> {
|
|
@@ -75,6 +63,11 @@ export class BuildnatorClient {
|
|
|
75
63
|
return res.data;
|
|
76
64
|
}
|
|
77
65
|
|
|
66
|
+
private async jenkinsPostNoData(path: string, params?: Record<string, QueryValue>) {
|
|
67
|
+
const res = await this.jenkins.post(path, null, { auth: this.auth, params });
|
|
68
|
+
return res;
|
|
69
|
+
}
|
|
70
|
+
|
|
78
71
|
private async jenkinsGet(path: string, params?: Record<string, QueryValue>) {
|
|
79
72
|
const res = await this.jenkins.get(path, { auth: this.auth, params });
|
|
80
73
|
return res.data;
|
|
@@ -90,15 +83,22 @@ export class BuildnatorClient {
|
|
|
90
83
|
}
|
|
91
84
|
|
|
92
85
|
async compilaAGM(branch: string, dirPrefix: string, diretivas: string, version: string): Promise<any> {
|
|
93
|
-
await this.
|
|
86
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.agmCompila}/buildWithParameters`, {
|
|
94
87
|
branch,
|
|
95
88
|
dirPrefix,
|
|
96
89
|
diretivas,
|
|
97
90
|
version,
|
|
98
91
|
});
|
|
99
|
-
await this.sleep(this.buildDelayMs);
|
|
92
|
+
/*await this.sleep(this.buildDelayMs);
|
|
100
93
|
const numbuild = await this.jenkinsPost(`${this.jobs.agmCompila}/api/json`);
|
|
101
|
-
return numbuild.builds[0].number
|
|
94
|
+
return numbuild.builds[0].number;*/
|
|
95
|
+
|
|
96
|
+
const location = retorno.headers['location'];
|
|
97
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
98
|
+
|
|
99
|
+
await this.sleep(this.filaDelayMs);
|
|
100
|
+
const id = await this.consultarFila(queueId)
|
|
101
|
+
return id
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
async consultaJenkinsAGM(id: number): Promise<any> {
|
|
@@ -124,7 +124,7 @@ export class BuildnatorClient {
|
|
|
124
124
|
modulos: string,
|
|
125
125
|
gerarVersao: boolean,
|
|
126
126
|
): Promise<any> {
|
|
127
|
-
await this.
|
|
127
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.agbCompila}/buildWithParameters`, {
|
|
128
128
|
branch,
|
|
129
129
|
dirPrefix,
|
|
130
130
|
diretivas,
|
|
@@ -132,9 +132,16 @@ export class BuildnatorClient {
|
|
|
132
132
|
modulosOpcionais: modulos,
|
|
133
133
|
gerarVersao,
|
|
134
134
|
});
|
|
135
|
-
await this.sleep(this.buildDelayMs);
|
|
135
|
+
/*await this.sleep(this.buildDelayMs);
|
|
136
136
|
const numbuild = await this.jenkinsPost(`${this.jobs.agbCompila}/api/json`);
|
|
137
|
-
return numbuild.builds[0].number
|
|
137
|
+
return numbuild.builds[0].number;*/
|
|
138
|
+
|
|
139
|
+
const location = retorno.headers['location'];
|
|
140
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
141
|
+
|
|
142
|
+
await this.sleep(this.filaDelayMs);
|
|
143
|
+
const id = await this.consultarFila(queueId)
|
|
144
|
+
return id
|
|
138
145
|
}
|
|
139
146
|
|
|
140
147
|
async consultaJenkinsAGB(id: number): Promise<any> {
|
|
@@ -163,6 +170,7 @@ export class BuildnatorClient {
|
|
|
163
170
|
versionOld?: string | null,
|
|
164
171
|
datahora?: any
|
|
165
172
|
): Promise<any> {
|
|
173
|
+
let retorno
|
|
166
174
|
if (alterarDTHR) {
|
|
167
175
|
if (!versionOld) {
|
|
168
176
|
throw new Error("versionOld eh obrigatorio quando alterarDTHR=true");
|
|
@@ -220,7 +228,7 @@ export class BuildnatorClient {
|
|
|
220
228
|
String(somasegundos).padStart(2, "0"),
|
|
221
229
|
].join(":");
|
|
222
230
|
|
|
223
|
-
|
|
231
|
+
retorno = await this.jenkinsPostNoData(`${this.jobs.agbCompilaVersao}/buildWithParameters`, {
|
|
224
232
|
branch,
|
|
225
233
|
dirPrefix,
|
|
226
234
|
diretivas,
|
|
@@ -231,7 +239,7 @@ export class BuildnatorClient {
|
|
|
231
239
|
data,
|
|
232
240
|
});
|
|
233
241
|
} else {
|
|
234
|
-
await this.
|
|
242
|
+
retorno = await this.jenkinsPostNoData(`${this.jobs.agbCompilaVersao}/buildWithParameters`, {
|
|
235
243
|
branch,
|
|
236
244
|
dirPrefix,
|
|
237
245
|
diretivas,
|
|
@@ -241,9 +249,16 @@ export class BuildnatorClient {
|
|
|
241
249
|
});
|
|
242
250
|
}
|
|
243
251
|
|
|
244
|
-
await this.sleep(this.buildDelayMs);
|
|
252
|
+
/*await this.sleep(this.buildDelayMs);
|
|
245
253
|
const numbuild = await this.jenkinsPost(`${this.jobs.agbCompilaVersao}/api/json`);
|
|
246
|
-
return numbuild.builds[0].number
|
|
254
|
+
return numbuild.builds[0].number;*/
|
|
255
|
+
|
|
256
|
+
const location = retorno.headers['location'];
|
|
257
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
258
|
+
|
|
259
|
+
await this.sleep(this.filaDelayMs);
|
|
260
|
+
const id = await this.consultarFila(queueId)
|
|
261
|
+
return id
|
|
247
262
|
}
|
|
248
263
|
|
|
249
264
|
async consultaVesaoJenkinsAGB(id: number): Promise<any> {
|
|
@@ -282,43 +297,71 @@ export class BuildnatorClient {
|
|
|
282
297
|
}
|
|
283
298
|
|
|
284
299
|
async liberaAGM(diretorio: string, baseline: string): Promise<any> {
|
|
285
|
-
await this.
|
|
300
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.qaAgmLibera}/buildWithParameters`, {
|
|
286
301
|
diretorioExecutaveis: diretorio,
|
|
287
302
|
baselineExecutaveis: baseline,
|
|
288
303
|
});
|
|
289
|
-
await this.sleep(this.buildDelayMs);
|
|
304
|
+
/*await this.sleep(this.buildDelayMs);
|
|
290
305
|
const numbuild = await this.jenkinsPost(`${this.jobs.qaAgmLibera}/api/json`);
|
|
291
|
-
return numbuild.builds[0].number
|
|
306
|
+
return numbuild.builds[0].number;*/
|
|
307
|
+
|
|
308
|
+
const location = retorno.headers['location'];
|
|
309
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
310
|
+
|
|
311
|
+
await this.sleep(this.filaDelayMs);
|
|
312
|
+
const id = await this.consultarFila(queueId)
|
|
313
|
+
return id
|
|
292
314
|
}
|
|
293
315
|
|
|
294
316
|
async liberaAGB(diretorio: string, baseline: string): Promise<any> {
|
|
295
|
-
await this.
|
|
317
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.qaTaAgbLibera}/buildWithParameters`, {
|
|
296
318
|
diretorioExecutaveis: diretorio,
|
|
297
319
|
baselineExecutaveis: baseline,
|
|
298
320
|
});
|
|
299
|
-
await this.sleep(this.buildDelayMs);
|
|
321
|
+
/*await this.sleep(this.buildDelayMs);
|
|
300
322
|
const numbuild = await this.jenkinsPost(`${this.jobs.qaTaAgbLibera}/api/json`);
|
|
301
|
-
return numbuild.builds[0].number
|
|
323
|
+
return numbuild.builds[0].number;*/
|
|
324
|
+
|
|
325
|
+
const location = retorno.headers['location'];
|
|
326
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
327
|
+
|
|
328
|
+
await this.sleep(this.filaDelayMs);
|
|
329
|
+
const id = await this.consultarFila(queueId)
|
|
330
|
+
return id
|
|
302
331
|
}
|
|
303
332
|
|
|
304
333
|
async liberaAGMEspecifica(diretorio: string, baseline: string): Promise<any> {
|
|
305
|
-
await this.
|
|
334
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.qaAgmLiberaEspecifica}/buildWithParameters`, {
|
|
306
335
|
diretorioExecutaveis: diretorio,
|
|
307
336
|
baselineExecutaveis: baseline,
|
|
308
337
|
});
|
|
309
|
-
await this.sleep(this.buildDelayMs);
|
|
338
|
+
/*await this.sleep(this.buildDelayMs);
|
|
310
339
|
const numbuild = await this.jenkinsPost(`${this.jobs.qaAgmLiberaEspecifica}/api/json`);
|
|
311
|
-
return numbuild.builds[0].number
|
|
340
|
+
return numbuild.builds[0].number;*/
|
|
341
|
+
|
|
342
|
+
const location = retorno.headers['location'];
|
|
343
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
344
|
+
|
|
345
|
+
await this.sleep(this.filaDelayMs);
|
|
346
|
+
const id = await this.consultarFila(queueId)
|
|
347
|
+
return id
|
|
312
348
|
}
|
|
313
349
|
|
|
314
350
|
async liberaAGBEspecifica(diretorio: string, baseline: string): Promise<any> {
|
|
315
|
-
await this.
|
|
351
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.qaTaAgbLiberaEspecifica}/buildWithParameters`, {
|
|
316
352
|
diretorioExecutaveis: diretorio,
|
|
317
353
|
baselineExecutaveis: baseline,
|
|
318
354
|
});
|
|
319
|
-
await this.sleep(this.buildDelayMs);
|
|
355
|
+
/*await this.sleep(this.buildDelayMs);
|
|
320
356
|
const numbuild = await this.jenkinsPost(`${this.jobs.qaTaAgbLiberaEspecifica}/api/json`);
|
|
321
|
-
return numbuild.builds[0].number
|
|
357
|
+
return numbuild.builds[0].number;*/
|
|
358
|
+
|
|
359
|
+
const location = retorno.headers['location'];
|
|
360
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
361
|
+
|
|
362
|
+
await this.sleep(this.filaDelayMs);
|
|
363
|
+
const id = await this.consultarFila(queueId)
|
|
364
|
+
return id
|
|
322
365
|
}
|
|
323
366
|
|
|
324
367
|
async consultaLiberaEspecifica(id: number, projeto: string): Promise<any> {
|
|
@@ -366,13 +409,20 @@ export class BuildnatorClient {
|
|
|
366
409
|
}
|
|
367
410
|
|
|
368
411
|
async PublicarDllsNuGet(versao: string, dirPrefix: string): Promise<any> {
|
|
369
|
-
await this.
|
|
412
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.publicarDllsNuget}/buildWithParameters`, {
|
|
370
413
|
version: versao,
|
|
371
414
|
diretoriobaseversao: dirPrefix,
|
|
372
415
|
});
|
|
373
|
-
await this.sleep(this.buildDelayMs);
|
|
416
|
+
/*await this.sleep(this.buildDelayMs);
|
|
374
417
|
const numbuild = await this.jenkinsPost(`${this.jobs.publicarDllsNuget}/api/json`);
|
|
375
|
-
return numbuild.builds[0].number
|
|
418
|
+
return numbuild.builds[0].number;*/
|
|
419
|
+
|
|
420
|
+
const location = retorno.headers['location'];
|
|
421
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
422
|
+
|
|
423
|
+
await this.sleep(this.filaDelayMs);
|
|
424
|
+
const id = await this.consultarFila(queueId)
|
|
425
|
+
return id
|
|
376
426
|
}
|
|
377
427
|
|
|
378
428
|
async consultaPublicarDllsNuGet(id: number): Promise<any> {
|
|
@@ -391,12 +441,19 @@ export class BuildnatorClient {
|
|
|
391
441
|
}
|
|
392
442
|
|
|
393
443
|
async testeTaVersaoEvolutiva(diretorioExecutaveis: string): Promise<any> {
|
|
394
|
-
await this.
|
|
444
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.testeTaVersaoEvolutiva}/buildWithParameters`, {
|
|
395
445
|
diretorioExecutaveis,
|
|
396
446
|
});
|
|
397
|
-
await this.sleep(this.buildDelayMs);
|
|
447
|
+
/*await this.sleep(this.buildDelayMs);
|
|
398
448
|
const numbuild = await this.jenkinsPost(`${this.jobs.testeTaVersaoEvolutiva}/api/json`);
|
|
399
|
-
return numbuild.builds[0].number
|
|
449
|
+
return numbuild.builds[0].number;*/
|
|
450
|
+
|
|
451
|
+
const location = retorno.headers['location'];
|
|
452
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
453
|
+
|
|
454
|
+
await this.sleep(this.filaDelayMs);
|
|
455
|
+
const id = await this.consultarFila(queueId)
|
|
456
|
+
return id
|
|
400
457
|
}
|
|
401
458
|
|
|
402
459
|
async consultatesteTaVersaoEvolutiva(id: any): Promise<any> {
|
|
@@ -415,13 +472,20 @@ export class BuildnatorClient {
|
|
|
415
472
|
}
|
|
416
473
|
|
|
417
474
|
async unificarCommits(branch: string, sistema: string): Promise<any> {
|
|
418
|
-
await this.
|
|
475
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.unificarCommits}/buildWithParameters`, {
|
|
419
476
|
Branch: branch,
|
|
420
477
|
repositorio: sistema,
|
|
421
478
|
});
|
|
422
|
-
await this.sleep(this.buildDelayMs);
|
|
479
|
+
/*await this.sleep(this.buildDelayMs);
|
|
423
480
|
const numbuild = await this.jenkinsPost(`${this.jobs.unificarCommits}/api/json`);
|
|
424
|
-
return numbuild.builds[0].number
|
|
481
|
+
return numbuild.builds[0].number;*/
|
|
482
|
+
|
|
483
|
+
const location = retorno.headers['location'];
|
|
484
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
485
|
+
|
|
486
|
+
await this.sleep(this.filaDelayMs);
|
|
487
|
+
const id = await this.consultarFila(queueId)
|
|
488
|
+
return id
|
|
425
489
|
}
|
|
426
490
|
|
|
427
491
|
async consultarUnificarCommits(id: any): Promise<any> {
|
|
@@ -473,13 +537,17 @@ export class BuildnatorClient {
|
|
|
473
537
|
}
|
|
474
538
|
|
|
475
539
|
async criarBCK(branch: string, sistema: string): Promise<any> {
|
|
476
|
-
await this.
|
|
540
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.criarbackup}/buildWithParameters`, {
|
|
477
541
|
branch: branch,
|
|
478
542
|
repositorio: sistema,
|
|
479
543
|
});
|
|
480
|
-
|
|
481
|
-
const
|
|
482
|
-
|
|
544
|
+
|
|
545
|
+
const location = retorno.headers['location'];
|
|
546
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
547
|
+
|
|
548
|
+
await this.sleep(this.filaDelayMs);
|
|
549
|
+
const id = await this.consultarFila(queueId)
|
|
550
|
+
return id
|
|
483
551
|
}
|
|
484
552
|
|
|
485
553
|
async consultarCriarBCK(id: any): Promise<any> {
|
|
@@ -500,4 +568,50 @@ export class BuildnatorClient {
|
|
|
500
568
|
return { terminado: true, resultado: false, tipo: "criarbackup", retorno: "erro interno", parou: "" };
|
|
501
569
|
}
|
|
502
570
|
}
|
|
571
|
+
|
|
572
|
+
async RecriarBranch(branch: string, sistema: string, branchBackup: string): Promise<any> {
|
|
573
|
+
const retorno = await this.jenkinsPostNoData(`${this.jobs.recriarBranch}/buildWithParameters`, {
|
|
574
|
+
branch: branch,
|
|
575
|
+
repositorio: sistema,
|
|
576
|
+
branchBackup: branchBackup
|
|
577
|
+
|
|
578
|
+
});
|
|
579
|
+
/*await this.sleep(this.buildDelayMs);
|
|
580
|
+
const numbuild = await this.jenkinsPost(`${this.jobs.recriarBranch}/api/json`);
|
|
581
|
+
return numbuild.builds[0].number;*/
|
|
582
|
+
|
|
583
|
+
const location = retorno.headers['location'];
|
|
584
|
+
const queueId = location.match(/item\/(\d+)/)[1];
|
|
585
|
+
|
|
586
|
+
await this.sleep(this.filaDelayMs);
|
|
587
|
+
const id = await this.consultarFila(queueId)
|
|
588
|
+
return id
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
async consultarRecriarBranch(id: any): Promise<any> {
|
|
592
|
+
try {
|
|
593
|
+
const numbuild = await this.jenkinsPost(`${this.jobs.recriarBranch}/${id}/api/json`);
|
|
594
|
+
if (numbuild && numbuild.inProgress === false) {
|
|
595
|
+
if (numbuild.result === "SUCCESS") {
|
|
596
|
+
return { terminado: true, resultado: true, tipo: "recriarBranch", retorno: numbuild.result };
|
|
597
|
+
}
|
|
598
|
+
return { terminado: true, resultado: false, tipo: "recriarBranch", retorno: numbuild.result };
|
|
599
|
+
}
|
|
600
|
+
return { terminado: false, resultado: false, tipo: "recriarBranch", retorno: numbuild?.result };
|
|
601
|
+
} catch {
|
|
602
|
+
return { terminado: true, resultado: false, tipo: "recriarBranch", retorno: "erro interno" };
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
async consultarFila(id: any): Promise<any> {
|
|
607
|
+
try {
|
|
608
|
+
const retorno = await this.jenkinsGet(`/queue/item/${id}/api/json`);
|
|
609
|
+
if (retorno && retorno.executable) {
|
|
610
|
+
return retorno.executable.number
|
|
611
|
+
}
|
|
612
|
+
return -1
|
|
613
|
+
} catch {
|
|
614
|
+
return -1
|
|
615
|
+
}
|
|
616
|
+
}
|
|
503
617
|
}
|