Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Right click option for building an EE when execution-environment.yml is recognized #1778

Merged
merged 19 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"activationEvents": [
"onLanguage:yaml",
"onLanguage:yml",
"workspaceContains:tox-ansible.ini",
"onWebviewPanel:ansible-home"
],
Expand Down Expand Up @@ -444,6 +445,10 @@
{
"command": "ansible.open-language-server-logs",
"title": "Ansible: Open Language Server Logs"
},
{
"command": "extension.buildExecutionEnvironment",
"title": "Build Ansible Execution Environment"
abhikdps marked this conversation as resolved.
Show resolved Hide resolved
}
],
"configuration": [
Expand Down Expand Up @@ -795,13 +800,23 @@
"group": "2_main@1",
"command": "ansible.lightspeed.playbookExplanation",
"when": "redhat.ansible.lightspeedSuggestionsEnabled && editorLangId == ansible"
},
{
"when": "resourceFilename == 'execution-environment.yml' || resourceFilename == 'execution-environment.yaml'",
"command": "extension.buildExecutionEnvironment",
"group": "navigation"
}
],
"explorer/context": [
{
"group": "2_main@1",
"submenu": "ansible.playbook.run",
"when": "isFileSystemResource && resourceLangId == ansible"
},
{
"when": "resourceFilename == 'execution-environment.yml' || resourceFilename == 'execution-environment.yaml'",
"command": "extension.buildExecutionEnvironment",
"group": "navigation"
}
],
"view/title": [
Expand Down
43 changes: 42 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
import { IFileSystemWatchers } from "./interfaces/watchers";
import { showPlaybookGenerationPage } from "./features/lightspeed/playbookGeneration";
import { showRoleGenerationPage } from "./features/lightspeed/roleGeneration";
import { ExecException, execSync } from "child_process";
import { ExecException, execSync, spawnSync } from "child_process";
import { CreateAnsibleProject } from "./features/contentCreator/createAnsibleProjectPage";
import { AddPlugin } from "./features/contentCreator/addPluginPage";
// import { LightspeedExplorerWebviewViewProvider } from "./features/lightspeed/explorerWebviewViewProvider";
Expand Down Expand Up @@ -168,6 +168,46 @@

vscode.commands.executeCommand("setContext", "lightspeedConnectReady", true);

const eeBuilderCommand = vscode.commands.registerCommand(
"extension.buildExecutionEnvironment",
(uri: vscode.Uri) => {
if (uri) {
const filePath = uri.fsPath;
const dirPath =

Check warning on line 176 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L175-L176

Added lines #L175 - L176 were not covered by tests
vscode.workspace.getWorkspaceFolder(uri)?.uri.fsPath ?? process.cwd();
const command = "ansible-builder";
const args = ["build", "-f", filePath];

vscode.window.showInformationMessage(
`Running: ${command} ${args.join(" ")}`,
);

const result = spawnSync(command, args, {
cwd: dirPath,
encoding: "utf-8",
shell: false,
});

Check warning on line 190 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L178-L190

Added lines #L178 - L190 were not covered by tests
if (result.error) {
vscode.window.showErrorMessage(`Error: ${result.error.message}`);
return;
}

Check warning on line 195 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L192-L195

Added lines #L192 - L195 were not covered by tests
if (result.stderr) {
vscode.window.showErrorMessage(`Error: ${result.stderr}`);
return;
}

vscode.window.showInformationMessage(

Check warning on line 201 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L197-L201

Added lines #L197 - L201 were not covered by tests
result.stdout ||
"Execution Environment Image was built successfully!",
);
} else {
vscode.window.showErrorMessage("No file selected.");
}

Check warning on line 207 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L203-L207

Added lines #L203 - L207 were not covered by tests
},
);

context.subscriptions.push(
vscode.commands.registerCommand(
LightSpeedCommands.LIGHTSPEED_STATUS_BAR_CLICK,
Expand Down Expand Up @@ -833,6 +873,7 @@
lsOutputChannel.show();
}),
);
context.subscriptions.push(eeBuilderCommand);
}

const startClient = async (
Expand Down