Add keybinding to run workflow in active editor (#141)
Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
@@ -131,6 +131,13 @@
|
|||||||
"when": "githubLocalActions:noSettings && workspaceFolderCount > 0"
|
"when": "githubLocalActions:noSettings && workspaceFolderCount > 0"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"keybindings": [
|
||||||
|
{
|
||||||
|
"command": "githubLocalActions.runWorkflow",
|
||||||
|
"key": "ctrl+g",
|
||||||
|
"mac": "cmd+g"
|
||||||
|
}
|
||||||
|
],
|
||||||
"commands": [
|
"commands": [
|
||||||
{
|
{
|
||||||
"category": "GitHub Local Actions",
|
"category": "GitHub Local Actions",
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ export class Act {
|
|||||||
path: workspaceFolder.uri.fsPath,
|
path: workspaceFolder.uri.fsPath,
|
||||||
workflow: workflow,
|
workflow: workflow,
|
||||||
options: [
|
options: [
|
||||||
`${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}"`
|
`${Option.Workflows} "${WorkflowsManager.WORKFLOWS_DIRECTORY}/${path.parse(workflow.uri.fsPath).base}"`
|
||||||
],
|
],
|
||||||
name: workflow.name,
|
name: workflow.name,
|
||||||
extraHeader: [
|
extraHeader: [
|
||||||
@@ -281,7 +281,7 @@ export class Act {
|
|||||||
path: workspaceFolder.uri.fsPath,
|
path: workspaceFolder.uri.fsPath,
|
||||||
workflow: workflow,
|
workflow: workflow,
|
||||||
options: [
|
options: [
|
||||||
`${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}"`,
|
`${Option.Workflows} "${WorkflowsManager.WORKFLOWS_DIRECTORY}/${path.parse(workflow.uri.fsPath).base}"`,
|
||||||
`${Option.Job} "${job.id}"`
|
`${Option.Job} "${job.id}"`
|
||||||
],
|
],
|
||||||
name: `${workflow.name}/${job.name}`,
|
name: `${workflow.name}/${job.name}`,
|
||||||
@@ -304,7 +304,7 @@ export class Act {
|
|||||||
path: workspaceFolder.uri.fsPath,
|
path: workspaceFolder.uri.fsPath,
|
||||||
workflow: workflow,
|
workflow: workflow,
|
||||||
options: [
|
options: [
|
||||||
`${event} ${Option.Workflows} ".github/workflows/${path.parse(workflow.uri.fsPath).base}"`
|
`${event} ${Option.Workflows} "${WorkflowsManager.WORKFLOWS_DIRECTORY}/${path.parse(workflow.uri.fsPath).base}"`
|
||||||
],
|
],
|
||||||
name: `${workflow.name} (${event})`,
|
name: `${workflow.name} (${event})`,
|
||||||
extraHeader: [
|
extraHeader: [
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import HistoryTreeDataProvider from './views/history/historyTreeDataProvider';
|
|||||||
import SettingTreeItem from './views/settings/setting';
|
import SettingTreeItem from './views/settings/setting';
|
||||||
import SettingsTreeDataProvider from './views/settings/settingsTreeDataProvider';
|
import SettingsTreeDataProvider from './views/settings/settingsTreeDataProvider';
|
||||||
import WorkflowsTreeDataProvider from './views/workflows/workflowsTreeDataProvider';
|
import WorkflowsTreeDataProvider from './views/workflows/workflowsTreeDataProvider';
|
||||||
|
import { WorkflowsManager } from './workflowsManager';
|
||||||
|
|
||||||
export let act: Act;
|
export let act: Act;
|
||||||
export let componentsTreeDataProvider: ComponentsTreeDataProvider;
|
export let componentsTreeDataProvider: ComponentsTreeDataProvider;
|
||||||
@@ -36,7 +37,7 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Create file watcher
|
// Create file watcher
|
||||||
const workflowsFileWatcher = workspace.createFileSystemWatcher('**/.github/workflows/*.{yml,yaml}');
|
const workflowsFileWatcher = workspace.createFileSystemWatcher(`**/${WorkflowsManager.WORKFLOWS_DIRECTORY}/*.{${WorkflowsManager.YML_EXTENSION},${WorkflowsManager.YAML_EXTENSION}}`);
|
||||||
workflowsFileWatcher.onDidCreate(() => {
|
workflowsFileWatcher.onDidCreate(() => {
|
||||||
workflowsTreeDataProvider.refresh();
|
workflowsTreeDataProvider.refresh();
|
||||||
settingsTreeDataProvider.refresh();
|
settingsTreeDataProvider.refresh();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { CancellationToken, commands, EventEmitter, ExtensionContext, TreeDataPr
|
|||||||
import { Event } from "../../act";
|
import { Event } from "../../act";
|
||||||
import { act } from "../../extension";
|
import { act } from "../../extension";
|
||||||
import { Utils } from "../../utils";
|
import { Utils } from "../../utils";
|
||||||
|
import { WorkflowsManager } from "../../workflowsManager";
|
||||||
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
import { GithubLocalActionsTreeItem } from "../githubLocalActionsTreeItem";
|
||||||
import JobTreeItem from "./job";
|
import JobTreeItem from "./job";
|
||||||
import WorkflowTreeItem from "./workflow";
|
import WorkflowTreeItem from "./workflow";
|
||||||
@@ -51,7 +52,43 @@ export default class WorkflowsTreeDataProvider implements TreeDataProvider<Githu
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
commands.registerCommand('githubLocalActions.runWorkflow', async (workflowTreeItem: WorkflowTreeItem) => {
|
commands.registerCommand('githubLocalActions.runWorkflow', async (workflowTreeItem: WorkflowTreeItem) => {
|
||||||
|
if (workflowTreeItem) {
|
||||||
await act.runWorkflow(workflowTreeItem.workspaceFolder, workflowTreeItem.workflow);
|
await act.runWorkflow(workflowTreeItem.workspaceFolder, workflowTreeItem.workflow);
|
||||||
|
} else {
|
||||||
|
let errorMessage: string | undefined;
|
||||||
|
|
||||||
|
const activeTextEditor = window.activeTextEditor;
|
||||||
|
if (activeTextEditor) {
|
||||||
|
const uri = activeTextEditor.document.uri;
|
||||||
|
const fileName = path.parse(uri.fsPath).base;
|
||||||
|
if (uri.path.match(`.*/${WorkflowsManager.WORKFLOWS_DIRECTORY}/.*\\.(${WorkflowsManager.YAML_EXTENSION}|${WorkflowsManager.YML_EXTENSION})`)) {
|
||||||
|
const workspaceFolder = workspace.getWorkspaceFolder(uri);
|
||||||
|
if (workspaceFolder) {
|
||||||
|
const workflows = await act.workflowsManager.getWorkflows(workspaceFolder);
|
||||||
|
const workflow = workflows.find(workflow => workflow.uri.fsPath === uri.fsPath);
|
||||||
|
if (workflow) {
|
||||||
|
await act.runWorkflow(workspaceFolder, workflow);
|
||||||
|
} else {
|
||||||
|
errorMessage = `Workflow not found in workflow directory (${WorkflowsManager.WORKFLOWS_DIRECTORY}).`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
errorMessage = `${fileName} must be opened in a workspace folder to be executed locally.`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
errorMessage = `${fileName} is not a workflow that can be executed locally.`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
errorMessage = 'No workflow opened to execute locally.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errorMessage) {
|
||||||
|
window.showErrorMessage(errorMessage, 'View Workflows').then(async value => {
|
||||||
|
if (value === 'View Workflows') {
|
||||||
|
await commands.executeCommand('workflows.focus');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
commands.registerCommand('githubLocalActions.runJob', async (jobTreeItem: JobTreeItem) => {
|
commands.registerCommand('githubLocalActions.runJob', async (jobTreeItem: JobTreeItem) => {
|
||||||
await act.runJob(jobTreeItem.workspaceFolder, jobTreeItem.workflow, jobTreeItem.job);
|
await act.runJob(jobTreeItem.workspaceFolder, jobTreeItem.workflow, jobTreeItem.job);
|
||||||
|
|||||||
@@ -17,10 +17,14 @@ export interface Job {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class WorkflowsManager {
|
export class WorkflowsManager {
|
||||||
|
static WORKFLOWS_DIRECTORY: string = '.github/workflows';
|
||||||
|
static YAML_EXTENSION: string = 'yaml';
|
||||||
|
static YML_EXTENSION: string = 'yml';
|
||||||
|
|
||||||
async getWorkflows(workspaceFolder: WorkspaceFolder): Promise<Workflow[]> {
|
async getWorkflows(workspaceFolder: WorkspaceFolder): Promise<Workflow[]> {
|
||||||
const workflows: Workflow[] = [];
|
const workflows: Workflow[] = [];
|
||||||
|
|
||||||
const workflowFileUris = await workspace.findFiles(new RelativePattern(workspaceFolder, `.github/workflows/*.{yml,yaml}`));
|
const workflowFileUris = await workspace.findFiles(new RelativePattern(workspaceFolder, `${WorkflowsManager.WORKFLOWS_DIRECTORY}/*.{${WorkflowsManager.YAML_EXTENSION},${WorkflowsManager.YML_EXTENSION}}`));
|
||||||
for await (const workflowFileUri of workflowFileUris) {
|
for await (const workflowFileUri of workflowFileUris) {
|
||||||
let yamlContent: any | undefined;
|
let yamlContent: any | undefined;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user