Skip to content

Commit e47757c

Browse files
yaroslav-codefreshitai-codefresh
authored andcommitted
Support ability to perform wait as fallback for getting logs in case of providing CF_CLI_RUN_WAIT_FALLBACK env var (#313)
1 parent d3111f4 commit e47757c

File tree

13 files changed

+97
-33
lines changed

13 files changed

+97
-33
lines changed

docs/docs.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const docs = require('../docs');
22

33
describe('docs generation', () => {
4+
jest.setTimeout(10000);
45
it('should generate docs', async () => {
56
await docs();
67
});

lib/interface/cli/commands/helm/chart/helm-charts.sdk.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ promoteCmd = promoteCmd.toCommand();
99

1010
jest.mock('../../../helpers/helm');
1111
jest.mock('../../../helpers/workflow');
12+
jest.spyOn(process, 'exit').mockImplementation();
1213

1314
const request = require('requestretry');
1415

lib/interface/cli/commands/helm/chart/install-chart.cmd.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ const install = new Command({
9191
console.log(workflowId);
9292
return;
9393
}
94-
await followLogs(workflowId);
94+
const exitCode = await followLogs(workflowId);
95+
process.exit(exitCode);
9596
} catch (err) {
9697
Output.printError(err);
9798
process.exit(1);

lib/interface/cli/commands/helm/chart/promote-chart.cmd.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ const promote = new Command({
105105
console.log(workflowId);
106106
return;
107107
}
108-
await followLogs(workflowId);
108+
const exitCode = await followLogs(workflowId);
109+
process.exit(exitCode);
109110
} catch (err) {
110111
Output.printError(err);
111112
process.exit(1);

lib/interface/cli/commands/helm/release/delete-release.cmd.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ const install = new Command({
8080
console.log(workflowId);
8181
return;
8282
}
83-
await followLogs(workflowId);
83+
const exitCode = await followLogs(workflowId);
84+
process.exit(exitCode);
8485
} catch (err) {
8586
Output.printError(err);
8687
process.exit(1);

lib/interface/cli/commands/helm/release/helm-releases.sdk.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ testCmd = testCmd.toCommand();
99

1010
jest.mock('../../../helpers/helm');
1111
jest.mock('../../../helpers/workflow');
12+
jest.spyOn(process, 'exit').mockImplementation();
1213

1314
const request = require('requestretry');
1415

lib/interface/cli/commands/helm/release/test-release.cmd.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ const install = new Command({
6363
console.log(workflowId);
6464
return;
6565
}
66-
await followLogs(workflowId);
66+
const exitCode = await followLogs(workflowId);
67+
process.exit(exitCode);
6768
} catch (err) {
6869
Output.printError(err);
6970
process.exit(1);

lib/interface/cli/commands/pipeline/run.cf.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const RunBaseCommand = require('./run.base');
22
const { sdk } = require('../../../../logic');
3-
const Workflow = require('../../../../logic/entities/Workflow');
3+
const { followLogs } = require('../../helpers/workflow');
44

55
function _buildBody(data) {
66
const body = {
@@ -50,22 +50,9 @@ class RunExternalCommand extends RunBaseCommand {
5050
console.log(this.workflowId);
5151
return 0;
5252
}
53-
await sdk.logs.showWorkflowLogs(this.workflowId, true);
54-
const buildResponse = await sdk.workflows.get({ id: this.workflowId });
55-
const workflowInstance = Workflow.fromResponse(buildResponse);
56-
switch (workflowInstance.getStatus()) {
57-
case 'success':
58-
return 0;
59-
case 'error':
60-
return 1;
61-
case 'terminated':
62-
return 2;
63-
default:
64-
return 100;
65-
}
66-
} else {
67-
console.log(this.workflowId);
53+
return followLogs(this.workflowId);
6854
}
55+
console.log(this.workflowId);
6956
}
7057
}
7158

lib/interface/cli/commands/pipeline/run.local.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const path = require('path');
55
const DEFAULTS = require('../../defaults');
66
const _ = require('lodash');
77
const { sdk } = require('../../../../logic');
8+
const { followLogs } = require('../../helpers/workflow');
89
const chalk = require('chalk');
910

1011
const regex = /##[0-9a-f]{24}##/i;
@@ -151,8 +152,7 @@ class RunLocalCommand extends RunBaseCommand {
151152
const include = line.match(regex);
152153
if (include) {
153154
const workflowId = include[0].substring(2, include[0].length - 2);
154-
sdk.logs.showWorkflowLogs(workflowId, true)
155-
.then(() => resolve(0));
155+
followLogs(workflowId).then(resolve);
156156
}
157157
});
158158
stream.on('error', (err) => {

lib/interface/cli/commands/workflow/restart.cmd.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ const restart = new Command({
2929
console.log(workflowId);
3030
return;
3131
}
32-
await followLogs(workflowId);
32+
const exitCode = await followLogs(workflowId);
33+
process.exit(exitCode);
3334
},
3435
});
3536

0 commit comments

Comments
 (0)