Skip to content

Commit

Permalink
Fix run command (#342)
Browse files Browse the repository at this point in the history
* upstream func cli 1.13.0 and fixed build issues

Signed-off-by: msivasubramaniaan <[email protected]>

* upstream vscode-test v1.6.1

Signed-off-by: msivasubramaniaan <[email protected]>

* upstream vscode-test v1.6.1

Signed-off-by: msivasubramaniaan <[email protected]>

* added @vscode/test-electron

Signed-off-by: msivasubramaniaan <[email protected]>

* removed vscode-test

Signed-off-by: msivasubramaniaan <[email protected]>

* updated package-lock.json

Signed-off-by: msivasubramaniaan <[email protected]>

* fix lint issues

Signed-off-by: msivasubramaniaan <[email protected]>

* add -i param on extest

Signed-off-by: msivasubramaniaan <[email protected]>

* update GH action version

Signed-off-by: msivasubramaniaan <[email protected]>

* check console message

Signed-off-by: msivasubramaniaan <[email protected]>

* check console message

Signed-off-by: msivasubramaniaan <[email protected]>

* check console message

Signed-off-by: msivasubramaniaan <[email protected]>

* check console message

Signed-off-by: msivasubramaniaan <[email protected]>

* update install-vscode

Signed-off-by: msivasubramaniaan <[email protected]>

* update install-vscode

Signed-off-by: msivasubramaniaan <[email protected]>

* fixed run command error

Signed-off-by: msivasubramaniaan <[email protected]>

* fixed ui test

Signed-off-by: msivasubramaniaan <[email protected]>

---------

Signed-off-by: msivasubramaniaan <[email protected]>
  • Loading branch information
msivasubramaniaan authored Mar 5, 2024
1 parent dc42a9c commit 34c2b29
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/cli/func-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,11 @@ export class FuncAPI {
return funcCliCommand(deployCommand);
}

static runFunc(location: string): CliCommand {
static runFunc(location: string, image: string): CliCommand {
const runCommand = ['run', `-p=${location}`, '-v'];
if (image && image.trim().length > 0) {
runCommand.push(`-i=${image}`);
}
return funcCliCommand(runCommand);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async function getImageAndBuildStrategy(funcData?: FuncContent, forceImageStrate
return { image: imagePick };
}

async function getFunctionImageInteractively(
export async function getFunctionImageInteractively(
selectedFolderPick: vscode.Uri,
forceImageStrategyPicker?: boolean,
): Promise<ImageAndBuild> {
Expand Down
12 changes: 7 additions & 5 deletions src/functions/function-command/run-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
*-----------------------------------------------------------------------------------------------*/

import { window } from 'vscode';
import { buildFunction, restartBuildCommand } from './build-and-deploy-function';
import { buildFunction, getFunctionImageInteractively, restartBuildCommand } from './build-and-deploy-function';
import { CliCommand, CliExitData } from '../../cli/cmdCli';
import { FuncAPI } from '../../cli/func-api';
import { telemetryLog } from '../../telemetry';
import { CACHED_CHILDPROCESS, executeCommandInOutputChannels, STILL_EXECUTING_COMMAND } from '../../util/output_channels';
import { FunctionNode } from '../function-tree-view/functionsTreeItem';
import { ImageAndBuild } from '../function-type';

export const restartRunCommand = new Map<string, boolean>();
const delay = (ms) =>
Expand All @@ -22,7 +23,6 @@ const delay = (ms) =>

async function executeRunCommand(command: CliCommand, context: FunctionNode, name: string): Promise<void> {
if (!STILL_EXECUTING_COMMAND.get(name)) {
command.cliArguments.push('--build=false');
await executeCommandInOutputChannels(command, name);
if (restartRunCommand.get(context.getName())) {
restartRunCommand.set(context.getName(), false);
Expand All @@ -49,7 +49,6 @@ export async function buildAndRun(context: FunctionNode, command: CliCommand): P
if (!STILL_EXECUTING_COMMAND.get(runName) && !STILL_EXECUTING_COMMAND.get(buildName)) {
const buildResult: CliExitData = await buildFunction(context);
if (buildResult?.stdout) {
command.cliArguments.push('--build=true');
await executeRunCommand(command, context, runName);
}
return null;
Expand All @@ -66,13 +65,16 @@ export async function buildAndRun(context: FunctionNode, command: CliCommand): P
}
}

export async function runFunction(context?: FunctionNode): Promise<void> {
export async function runFunction(context?: FunctionNode, readImage = true): Promise<void> {
if (!context) {
return null;
}
telemetryLog('Function_run_command', `Function run command click name: ${context.getName()}`);
// TO DO
const command = FuncAPI.runFunc(context.contextPath.fsPath);
const imageAndBuildModel: ImageAndBuild = readImage
? await getFunctionImageInteractively(context?.contextPath)
: { image: '', builder: '', autoGenerateImage: false };
const command = FuncAPI.runFunc(context.contextPath.fsPath, imageAndBuildModel.image);
const name = `Run: ${context.getName()}`;
// const buildName = `Build: ${context.getName()}`;
const result = await window.showInformationMessage('Do you want to run with build?', 'Yes', 'No');
Expand Down
2 changes: 1 addition & 1 deletion test/functions/function-command/run-function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ suite('Function/Run', () => {
});

test('delete function from tree view', async () => {
await runFunction(taskRunNode);
await runFunction(taskRunNode, false);
// eslint-disable-next-line no-unused-expressions
expect(showInformationMessageStub).calledOnce;
});
Expand Down

0 comments on commit 34c2b29

Please sign in to comment.