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

Fix act not found when installed as GitHub CLI extension #75

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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`",
Expand Down
27 changes: 20 additions & 7 deletions src/act.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand All @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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 = {
Expand Down Expand Up @@ -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();
}
});
Expand Down Expand Up @@ -214,6 +222,10 @@ export class Act {
});
}

static getActCommand() {
return ConfigurationManager.get<string>(Section.actCommand) || Act.command;
}

async runAllWorkflows(workspaceFolder: WorkspaceFolder) {
return await this.runCommand({
path: workspaceFolder.uri.fsPath,
Expand Down Expand Up @@ -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} `)}` : ``) +
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/componentsManager.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -33,7 +34,7 @@ export class ComponentsManager {
async getComponents(): Promise<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({
name: 'nektos/act',
icon: 'terminal',
Expand Down
11 changes: 9 additions & 2 deletions src/configurationManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConfigurationTarget, workspace } from 'vscode';
import { Act } from './act';

export enum Platform {
windows = 'win32',
Expand All @@ -7,14 +8,15 @@ export enum Platform {
}

export enum Section {
actCommand = 'actCommand',
dockerDesktopPath = 'dockerDesktopPath'
}

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<void> {
let dockerDesktopPath = ConfigurationManager.get<string>(Section.dockerDesktopPath);
if (!dockerDesktopPath) {
switch (process.platform) {
Expand All @@ -28,7 +30,12 @@ export namespace ConfigurationManager {
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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});

Expand Down