diff --git a/package.json b/package.json index 3c863b5..43a7578 100644 --- a/package.json +++ b/package.json @@ -685,6 +685,11 @@ "configuration": { "title": "GitHub Local Actions", "properties": { + "githubLocalActions.actCommand": { + "markdownDescription": "The base `nektos/act` command to be called. By default, this will be `act` (requires the binary to be on your `PATH`). If the binary is not on your `PATH`, the command should be fully qualified. If `act` is installed as a GitHub CLI extension, this command should be set to `gh act`.", + "type": "string", + "default": "act" + }, "githubLocalActions.dockerDesktopPath": { "type": "string", "markdownDescription": "The path to your Docker Desktop executable (used for Windows and MacOS). To start Docker Engine from the `Components` view, this application will be launched. Refer to the default path based on OS:\n\n* **Windows**: `C:/Program Files/Docker/Docker/Docker Desktop.exe`\n\n* **MacOS**: `/Applications/Docker.app`", diff --git a/src/act.ts b/src/act.ts index dc84b68..f604325 100644 --- a/src/act.ts +++ b/src/act.ts @@ -2,6 +2,7 @@ import * as path from "path"; import sanitize from "sanitize-filename"; import { ExtensionContext, ShellExecution, TaskGroup, TaskPanelKind, TaskRevealKind, tasks, TaskScope, Uri, window, workspace, WorkspaceFolder } from "vscode"; import { ComponentsManager } from "./componentsManager"; +import { ConfigurationManager, Section } from "./configurationManager"; import { componentsTreeDataProvider, historyTreeDataProvider } from './extension'; import { HistoryManager, HistoryStatus } from './historyManager'; import { SecretManager } from "./secretManager"; @@ -66,7 +67,8 @@ export interface CommandArgs { } export class Act { - private static base: string = 'act'; + static command: string = 'act'; + static githubCliCommand: string = 'gh act'; context: ExtensionContext; storageManager: StorageManager; secretManager: SecretManager; @@ -92,7 +94,7 @@ export class Act { 'Chocolatey': 'choco install act-cli', 'Winget': 'winget install nektos.act', 'Scoop': 'scoop install act', - 'GitHub CLI': 'gh extension install https://github.com/nektos/gh-act' + 'GitHub CLI': 'gh auth status || gh auth login && gh extension install https://github.com/nektos/gh-act' }; this.prebuiltExecutables = { @@ -107,7 +109,7 @@ export class Act { 'Homebrew': 'brew install act', 'Nix': 'nix run nixpkgs#act', 'MacPorts': 'sudo port install act', - 'GitHub CLI': 'gh extension install https://github.com/nektos/gh-act' + 'GitHub CLI': 'gh auth status || gh auth login && gh extension install https://github.com/nektos/gh-act' }; this.prebuiltExecutables = { @@ -121,7 +123,7 @@ export class Act { 'Nix': 'nix run nixpkgs#act', 'AUR': 'yay -Syu act', 'COPR': 'dnf copr enable goncalossilva/act && dnf install act-cli', - 'GitHub CLI': 'gh extension install https://github.com/nektos/gh-act' + 'GitHub CLI': 'gh auth status || gh auth login && gh extension install https://github.com/nektos/gh-act' }; this.prebuiltExecutables = { @@ -158,9 +160,15 @@ export class Act { }); // Refresh components view after installation - tasks.onDidEndTask(e => { + tasks.onDidEndTask(async e => { const taskDefinition = e.execution.task.definition; if (taskDefinition.type === 'nektos/act installation') { + if (taskDefinition.ghCliInstall) { + await ConfigurationManager.set(Section.actCommand, Act.githubCliCommand); + } else { + await ConfigurationManager.set(Section.actCommand, Act.command); + } + componentsTreeDataProvider.refresh(); } }); @@ -214,6 +222,10 @@ export class Act { }); } + static getActCommand() { + return ConfigurationManager.get(Section.actCommand) || Act.command; + } + async runAllWorkflows(workspaceFolder: WorkspaceFolder) { return await this.runCommand({ path: workspaceFolder.uri.fsPath, @@ -305,10 +317,11 @@ export class Act { } catch (error: any) { } // Build command with settings + const actCommand = Act.getActCommand(); const settings = await this.settingsManager.getSettings(workspaceFolder, true); const command = `set -o pipefail; ` + - `${Act.base} ${commandArgs.options}` + + `${actCommand} ${commandArgs.options}` + (settings.secrets.length > 0 ? ` ${Option.Secret} ${settings.secrets.map(secret => secret.key).join(` ${Option.Secret} `)}` : ``) + (settings.secretFiles.length > 0 ? ` ${Option.SecretFile} "${settings.secretFiles[0].path}"` : ` ${Option.SecretFile} ""`) + (settings.variables.length > 0 ? ` ${Option.Variable} ${settings.variables.map(variable => (variable.value ? `${variable.key}=${variable.value}` : variable.key)).join(` ${Option.Variable} `)}` : ``) + @@ -368,7 +381,7 @@ export class Act { await tasks.executeTask({ name: 'nektos/act', detail: 'Install nektos/act', - definition: { type: 'nektos/act installation' }, + definition: { type: 'nektos/act installation', ghCliInstall: command.includes('gh-act') }, source: 'GitHub Local Actions', scope: TaskScope.Workspace, isBackground: true, diff --git a/src/componentsManager.ts b/src/componentsManager.ts index d3400e2..acdaaeb 100644 --- a/src/componentsManager.ts +++ b/src/componentsManager.ts @@ -1,5 +1,6 @@ import * as childProcess from "child_process"; import { commands, env, extensions, QuickPickItemKind, ShellExecution, TaskGroup, TaskPanelKind, TaskRevealKind, tasks, TaskScope, ThemeIcon, Uri, window } from "vscode"; +import { Act } from "./act"; import { ConfigurationManager, Platform, Section } from "./configurationManager"; import { act, componentsTreeDataProvider } from "./extension"; import ComponentsTreeDataProvider from "./views/components/componentsTreeDataProvider"; @@ -33,7 +34,7 @@ export class ComponentsManager { async getComponents(): Promise[]> { const components: Component[] = []; - const actCliInfo = await this.getCliInfo('act --version', /act version (.+)/, false, false); + const actCliInfo = await this.getCliInfo(`${Act.getActCommand()} --version`, /act version (.+)/, false, false); components.push({ name: 'nektos/act', icon: 'terminal', diff --git a/src/configurationManager.ts b/src/configurationManager.ts index bf047bc..e6c8c84 100644 --- a/src/configurationManager.ts +++ b/src/configurationManager.ts @@ -1,4 +1,5 @@ import { ConfigurationTarget, workspace } from 'vscode'; +import { Act } from './act'; export enum Platform { windows = 'win32', @@ -7,6 +8,7 @@ export enum Platform { } export enum Section { + actCommand = 'actCommand', dockerDesktopPath = 'dockerDesktopPath' } @@ -14,7 +16,7 @@ export namespace ConfigurationManager { export const group: string = 'githubLocalActions'; export const searchPrefix: string = '@ext:sanjulaganepola.github-local-actions'; - export function initialize(): void { + export async function initialize(): Promise { let dockerDesktopPath = ConfigurationManager.get(Section.dockerDesktopPath); if (!dockerDesktopPath) { switch (process.platform) { @@ -28,7 +30,12 @@ export namespace ConfigurationManager { return; } - ConfigurationManager.set(Section.dockerDesktopPath, dockerDesktopPath); + await ConfigurationManager.set(Section.dockerDesktopPath, dockerDesktopPath); + } + + let actCommand = ConfigurationManager.get(Section.actCommand); + if (!actCommand) { + await ConfigurationManager.set(Section.actCommand, Act.command); } } diff --git a/src/extension.ts b/src/extension.ts index c39afb8..7aa315c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -54,7 +54,8 @@ export function activate(context: vscode.ExtensionContext) { ConfigurationManager.initialize(); workspace.onDidChangeConfiguration(async event => { if (event.affectsConfiguration(ConfigurationManager.group)) { - ConfigurationManager.initialize(); + await ConfigurationManager.initialize(); + componentsTreeDataProvider.refresh(); } });