From ecbc4dccb516ec474535cfe964eb157bd10d7a22 Mon Sep 17 00:00:00 2001 From: Sanjula Ganepola Date: Tue, 26 Nov 2024 21:47:48 -0500 Subject: [PATCH] Fix to use default OS shells Signed-off-by: Sanjula Ganepola --- src/act.ts | 40 +++++++++++++------ src/componentsManager.ts | 6 +-- src/settingsManager.ts | 4 +- .../settings/settingsTreeDataProvider.ts | 8 ++-- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/act.ts b/src/act.ts index 8e4e78b..421e0b8 100644 --- a/src/act.ts +++ b/src/act.ts @@ -2,9 +2,9 @@ import * as childProcess from "child_process"; import * as fs from "fs/promises"; import * as path from "path"; import sanitize from "sanitize-filename"; -import { CustomExecution, EventEmitter, ExtensionContext, Pseudoterminal, ShellExecution, TaskDefinition, TaskGroup, TaskPanelKind, TaskRevealKind, tasks, TaskScope, TerminalDimensions, Uri, window, workspace, WorkspaceFolder } from "vscode"; +import { CustomExecution, env, EventEmitter, ExtensionContext, Pseudoterminal, ShellExecution, TaskDefinition, TaskGroup, TaskPanelKind, TaskRevealKind, tasks, TaskScope, TerminalDimensions, Uri, window, workspace, WorkspaceFolder } from "vscode"; import { ComponentsManager } from "./componentsManager"; -import { ConfigurationManager, Section } from "./configurationManager"; +import { ConfigurationManager, Platform, Section } from "./configurationManager"; import { componentsTreeDataProvider, historyTreeDataProvider } from './extension'; import { HistoryManager, HistoryStatus } from './historyManager'; import { SecretManager } from "./secretManager"; @@ -171,9 +171,9 @@ export class Act { }); // Refresh components view after installation - tasks.onDidEndTask(async e => { + tasks.onDidEndTaskProcess(async e => { const taskDefinition = e.execution.task.definition; - if (taskDefinition.type === 'nektos/act installation') { + if (taskDefinition.type === 'nektos/act installation' && e.exitCode === 0) { // Update base act command based on installation method if (taskDefinition.ghCliInstall) { await ConfigurationManager.set(Section.actCommand, Act.githubCliCommand); @@ -190,6 +190,19 @@ export class Act { return ConfigurationManager.get(Section.actCommand) || Act.command; } + private getShell() { + switch (process.platform) { + case Platform.windows: + return 'cmd'; + case Platform.mac: + return 'zsh'; + case Platform.linux: + return 'bash'; + default: + return env.shell; + } + } + async runAllWorkflows(workspaceFolder: WorkspaceFolder) { return await this.runCommand({ path: workspaceFolder.uri.fsPath, @@ -366,13 +379,16 @@ export class Act { command, { cwd: commandArgs.path, - shell: true, - env: settings.secrets - .filter(secret => secret.value) - .reduce((previousValue, currentValue) => { - previousValue[currentValue.key] = currentValue.value; - return previousValue; - }, {} as Record) + shell: this.getShell(), + env: { + ...process.env, + ...settings.secrets + .filter(secret => secret.value) + .reduce((previousValue, currentValue) => { + previousValue[currentValue.key] = currentValue.value; + return previousValue; + }, {} as Record) + } } ); exec.stdout.on('data', handleIO); @@ -454,7 +470,7 @@ export class Act { problemMatchers: [], runOptions: {}, group: TaskGroup.Build, - execution: new ShellExecution(command) + execution: new ShellExecution(command, { executable: this.getShell() }) }); } } diff --git a/src/componentsManager.ts b/src/componentsManager.ts index acdaaeb..d0cd127 100644 --- a/src/componentsManager.ts +++ b/src/componentsManager.ts @@ -104,7 +104,7 @@ export class ComponentsManager { if (selectedPrebuiltExecutable) { await env.openExternal(Uri.parse(selectedPrebuiltExecutable.link)); - window.showInformationMessage('Unpack and run the executable in the terminal specifying the full path or add it to one of the paths in your PATH environment variable. Once nektos/act is successfully installed, refresh the components view.', 'Refresh').then(async value => { + window.showInformationMessage('Unpack the executable and move it to your desired location. Once nektos/act is successfully installed, add it to your shell\'s PATH and then refresh the components view.', 'Refresh').then(async value => { if (value === 'Refresh') { componentsTreeDataProvider.refresh(); } @@ -112,7 +112,7 @@ export class ComponentsManager { } } else if (selectedInstallationMethod.link) { await env.openExternal(Uri.parse(selectedInstallationMethod.link)); - window.showInformationMessage('Once nektos/act is successfully installed, refresh the components view.', 'Refresh').then(async value => { + window.showInformationMessage('Once nektos/act is successfully installed, add it to your shell\'s PATH and then refresh the components view.', 'Refresh').then(async value => { if (value === 'Refresh') { componentsTreeDataProvider.refresh(); } @@ -162,7 +162,7 @@ export class ComponentsManager { problemMatchers: [], runOptions: {}, group: TaskGroup.Build, - execution: new ShellExecution('sudo dockerd') + execution: new ShellExecution('sudo dockerd', { executable: env.shell }) }); } else { window.showErrorMessage(`Invalid environment: ${process.platform}`, 'Report an Issue').then(async value => { diff --git a/src/settingsManager.ts b/src/settingsManager.ts index b0c3a5d..b161ef5 100644 --- a/src/settingsManager.ts +++ b/src/settingsManager.ts @@ -164,7 +164,7 @@ export class SettingsManager { return environments; } - async createSettingFile(workspaceFolder: WorkspaceFolder, storageKey: StorageKey, settingFileName: string) { + async createSettingFile(workspaceFolder: WorkspaceFolder, storageKey: StorageKey, settingFileName: string, content: string) { const settingFileUri = Uri.file(path.join(workspaceFolder.uri.fsPath, settingFileName)); try { @@ -172,7 +172,7 @@ export class SettingsManager { window.showErrorMessage(`A file or folder named ${settingFileName} already exists at ${workspaceFolder.uri.fsPath}. Please choose another name.`); } catch (error: any) { try { - await workspace.fs.writeFile(settingFileUri, new TextEncoder().encode('')); + await workspace.fs.writeFile(settingFileUri, new TextEncoder().encode(content)); await this.locateSettingFile(workspaceFolder, storageKey, [settingFileUri]); const document = await workspace.openTextDocument(settingFileUri); await window.showTextDocument(document); diff --git a/src/views/settings/settingsTreeDataProvider.ts b/src/views/settings/settingsTreeDataProvider.ts index 8a90368..73ec5da 100644 --- a/src/views/settings/settingsTreeDataProvider.ts +++ b/src/views/settings/settingsTreeDataProvider.ts @@ -29,7 +29,7 @@ export default class SettingsTreeDataProvider implements TreeDataProvider