Merge pull request #75 from SanjulaGanepola/fix/github-cli-extension-support

Fix act not found when installed as GitHub CLI extension
This commit is contained in:
Sanjula Ganepola
2024-11-25 00:18:11 -05:00
committed by GitHub
5 changed files with 38 additions and 11 deletions

View File

@@ -685,6 +685,11 @@
"configuration": { "configuration": {
"title": "GitHub Local Actions", "title": "GitHub Local Actions",
"properties": { "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": { "githubLocalActions.dockerDesktopPath": {
"type": "string", "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`", "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`",

View File

@@ -2,6 +2,7 @@ import * as path from "path";
import sanitize from "sanitize-filename"; import sanitize from "sanitize-filename";
import { ExtensionContext, ShellExecution, TaskGroup, TaskPanelKind, TaskRevealKind, tasks, TaskScope, Uri, window, workspace, WorkspaceFolder } from "vscode"; import { ExtensionContext, ShellExecution, TaskGroup, TaskPanelKind, TaskRevealKind, tasks, TaskScope, Uri, window, workspace, WorkspaceFolder } from "vscode";
import { ComponentsManager } from "./componentsManager"; import { ComponentsManager } from "./componentsManager";
import { ConfigurationManager, Section } from "./configurationManager";
import { componentsTreeDataProvider, historyTreeDataProvider } from './extension'; import { componentsTreeDataProvider, historyTreeDataProvider } from './extension';
import { HistoryManager, HistoryStatus } from './historyManager'; import { HistoryManager, HistoryStatus } from './historyManager';
import { SecretManager } from "./secretManager"; import { SecretManager } from "./secretManager";
@@ -66,7 +67,8 @@ export interface CommandArgs {
} }
export class Act { export class Act {
private static base: string = 'act'; static command: string = 'act';
static githubCliCommand: string = 'gh act';
context: ExtensionContext; context: ExtensionContext;
storageManager: StorageManager; storageManager: StorageManager;
secretManager: SecretManager; secretManager: SecretManager;
@@ -92,7 +94,7 @@ export class Act {
'Chocolatey': 'choco install act-cli', 'Chocolatey': 'choco install act-cli',
'Winget': 'winget install nektos.act', 'Winget': 'winget install nektos.act',
'Scoop': 'scoop install 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 = { this.prebuiltExecutables = {
@@ -107,7 +109,7 @@ export class Act {
'Homebrew': 'brew install act', 'Homebrew': 'brew install act',
'Nix': 'nix run nixpkgs#act', 'Nix': 'nix run nixpkgs#act',
'MacPorts': 'sudo port install 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 = { this.prebuiltExecutables = {
@@ -121,7 +123,7 @@ export class Act {
'Nix': 'nix run nixpkgs#act', 'Nix': 'nix run nixpkgs#act',
'AUR': 'yay -Syu act', 'AUR': 'yay -Syu act',
'COPR': 'dnf copr enable goncalossilva/act && dnf install act-cli', '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 = { this.prebuiltExecutables = {
@@ -158,9 +160,15 @@ export class Act {
}); });
// Refresh components view after installation // Refresh components view after installation
tasks.onDidEndTask(e => { tasks.onDidEndTask(async e => {
const taskDefinition = e.execution.task.definition; const taskDefinition = e.execution.task.definition;
if (taskDefinition.type === 'nektos/act installation') { 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(); componentsTreeDataProvider.refresh();
} }
}); });
@@ -214,6 +222,10 @@ export class Act {
}); });
} }
static getActCommand() {
return ConfigurationManager.get<string>(Section.actCommand) || Act.command;
}
async runAllWorkflows(workspaceFolder: WorkspaceFolder) { async runAllWorkflows(workspaceFolder: WorkspaceFolder) {
return await this.runCommand({ return await this.runCommand({
path: workspaceFolder.uri.fsPath, path: workspaceFolder.uri.fsPath,
@@ -305,10 +317,11 @@ export class Act {
} catch (error: any) { } } catch (error: any) { }
// Build command with settings // Build command with settings
const actCommand = Act.getActCommand();
const settings = await this.settingsManager.getSettings(workspaceFolder, true); const settings = await this.settingsManager.getSettings(workspaceFolder, true);
const command = const command =
`set -o pipefail; ` + `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.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.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} `)}` : ``) + (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({ await tasks.executeTask({
name: 'nektos/act', name: 'nektos/act',
detail: 'Install 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', source: 'GitHub Local Actions',
scope: TaskScope.Workspace, scope: TaskScope.Workspace,
isBackground: true, isBackground: true,

View File

@@ -1,5 +1,6 @@
import * as childProcess from "child_process"; import * as childProcess from "child_process";
import { commands, env, extensions, QuickPickItemKind, ShellExecution, TaskGroup, TaskPanelKind, TaskRevealKind, tasks, TaskScope, ThemeIcon, Uri, window } from "vscode"; 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 { ConfigurationManager, Platform, Section } from "./configurationManager";
import { act, componentsTreeDataProvider } from "./extension"; import { act, componentsTreeDataProvider } from "./extension";
import ComponentsTreeDataProvider from "./views/components/componentsTreeDataProvider"; import ComponentsTreeDataProvider from "./views/components/componentsTreeDataProvider";
@@ -33,7 +34,7 @@ export class ComponentsManager {
async getComponents(): Promise<Component<CliStatus | ExtensionStatus>[]> { async getComponents(): Promise<Component<CliStatus | ExtensionStatus>[]> {
const components: Component<CliStatus | ExtensionStatus>[] = []; const components: Component<CliStatus | ExtensionStatus>[] = [];
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({ components.push({
name: 'nektos/act', name: 'nektos/act',
icon: 'terminal', icon: 'terminal',

View File

@@ -1,4 +1,5 @@
import { ConfigurationTarget, workspace } from 'vscode'; import { ConfigurationTarget, workspace } from 'vscode';
import { Act } from './act';
export enum Platform { export enum Platform {
windows = 'win32', windows = 'win32',
@@ -7,6 +8,7 @@ export enum Platform {
} }
export enum Section { export enum Section {
actCommand = 'actCommand',
dockerDesktopPath = 'dockerDesktopPath' dockerDesktopPath = 'dockerDesktopPath'
} }
@@ -14,7 +16,7 @@ export namespace ConfigurationManager {
export const group: string = 'githubLocalActions'; export const group: string = 'githubLocalActions';
export const searchPrefix: string = '@ext:sanjulaganepola.github-local-actions'; export const searchPrefix: string = '@ext:sanjulaganepola.github-local-actions';
export function initialize(): void { export async function initialize(): Promise<void> {
let dockerDesktopPath = ConfigurationManager.get<string>(Section.dockerDesktopPath); let dockerDesktopPath = ConfigurationManager.get<string>(Section.dockerDesktopPath);
if (!dockerDesktopPath) { if (!dockerDesktopPath) {
switch (process.platform) { switch (process.platform) {
@@ -28,7 +30,12 @@ export namespace ConfigurationManager {
return; return;
} }
ConfigurationManager.set(Section.dockerDesktopPath, dockerDesktopPath); await ConfigurationManager.set(Section.dockerDesktopPath, dockerDesktopPath);
}
let actCommand = ConfigurationManager.get<string>(Section.actCommand);
if (!actCommand) {
await ConfigurationManager.set(Section.actCommand, Act.command);
} }
} }

View File

@@ -54,7 +54,8 @@ export function activate(context: vscode.ExtensionContext) {
ConfigurationManager.initialize(); ConfigurationManager.initialize();
workspace.onDidChangeConfiguration(async event => { workspace.onDidChangeConfiguration(async event => {
if (event.affectsConfiguration(ConfigurationManager.group)) { if (event.affectsConfiguration(ConfigurationManager.group)) {
ConfigurationManager.initialize(); await ConfigurationManager.initialize();
componentsTreeDataProvider.refresh();
} }
}); });