Add setting to change workflow directory (#188)
Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com>
This commit is contained in:
@@ -786,6 +786,11 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"default": "act"
|
"default": "act"
|
||||||
},
|
},
|
||||||
|
"githubLocalActions.workflowsDirectory": {
|
||||||
|
"markdownDescription": "The relative path to the directory containing your workflows. By default, this will be `.github/workflows`.",
|
||||||
|
"type": "string",
|
||||||
|
"default": ".github/workflows"
|
||||||
|
},
|
||||||
"githubLocalActions.dockerDesktopPath": {
|
"githubLocalActions.dockerDesktopPath": {
|
||||||
"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`",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
|||||||
10
src/act.ts
10
src/act.ts
@@ -273,11 +273,12 @@ export class Act {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async runWorkflow(workspaceFolder: WorkspaceFolder, workflow: Workflow) {
|
async runWorkflow(workspaceFolder: WorkspaceFolder, workflow: Workflow) {
|
||||||
|
const workflowsDirectory = WorkflowsManager.getWorkflowsDirectory();
|
||||||
return await this.runCommand({
|
return await this.runCommand({
|
||||||
path: workspaceFolder.uri.fsPath,
|
path: workspaceFolder.uri.fsPath,
|
||||||
workflow: workflow,
|
workflow: workflow,
|
||||||
options: [
|
options: [
|
||||||
`${Option.Workflows} "${WorkflowsManager.WORKFLOWS_DIRECTORY}/${path.parse(workflow.uri.fsPath).base}"`
|
`${Option.Workflows} "${workflowsDirectory}/${path.parse(workflow.uri.fsPath).base}"`
|
||||||
],
|
],
|
||||||
name: workflow.name,
|
name: workflow.name,
|
||||||
extraHeader: [
|
extraHeader: [
|
||||||
@@ -287,11 +288,12 @@ export class Act {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async runJob(workspaceFolder: WorkspaceFolder, workflow: Workflow, job: Job) {
|
async runJob(workspaceFolder: WorkspaceFolder, workflow: Workflow, job: Job) {
|
||||||
|
const workflowsDirectory = WorkflowsManager.getWorkflowsDirectory();
|
||||||
return await this.runCommand({
|
return await this.runCommand({
|
||||||
path: workspaceFolder.uri.fsPath,
|
path: workspaceFolder.uri.fsPath,
|
||||||
workflow: workflow,
|
workflow: workflow,
|
||||||
options: [
|
options: [
|
||||||
`${Option.Workflows} "${WorkflowsManager.WORKFLOWS_DIRECTORY}/${path.parse(workflow.uri.fsPath).base}"`,
|
`${Option.Workflows} "${workflowsDirectory}/${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 +306,7 @@ export class Act {
|
|||||||
|
|
||||||
async runEvent(workspaceFolder: WorkspaceFolder, event: Event) {
|
async runEvent(workspaceFolder: WorkspaceFolder, event: Event) {
|
||||||
let eventExists: boolean = false;
|
let eventExists: boolean = false;
|
||||||
|
const workflowsDirectory = WorkflowsManager.getWorkflowsDirectory();
|
||||||
const workflows = await this.workflowsManager.getWorkflows(workspaceFolder);
|
const workflows = await this.workflowsManager.getWorkflows(workspaceFolder);
|
||||||
if (workflows.length > 0) {
|
if (workflows.length > 0) {
|
||||||
for (const workflow of workflows) {
|
for (const workflow of workflows) {
|
||||||
@@ -314,7 +316,7 @@ export class Act {
|
|||||||
path: workspaceFolder.uri.fsPath,
|
path: workspaceFolder.uri.fsPath,
|
||||||
workflow: workflow,
|
workflow: workflow,
|
||||||
options: [
|
options: [
|
||||||
`${event} ${Option.Workflows} "${WorkflowsManager.WORKFLOWS_DIRECTORY}/${path.parse(workflow.uri.fsPath).base}"`
|
`${event} ${Option.Workflows} "${workflowsDirectory}/${path.parse(workflow.uri.fsPath).base}"`
|
||||||
],
|
],
|
||||||
name: `${workflow.name} (${event})`,
|
name: `${workflow.name} (${event})`,
|
||||||
extraHeader: [
|
extraHeader: [
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { ConfigurationTarget, workspace } from 'vscode';
|
import { ConfigurationTarget, workspace } from 'vscode';
|
||||||
import { Act } from './act';
|
import { Act } from './act';
|
||||||
|
import { WorkflowsManager } from './workflowsManager';
|
||||||
|
|
||||||
export enum Platform {
|
export enum Platform {
|
||||||
windows = 'win32',
|
windows = 'win32',
|
||||||
@@ -9,6 +10,7 @@ export enum Platform {
|
|||||||
|
|
||||||
export enum Section {
|
export enum Section {
|
||||||
actCommand = 'actCommand',
|
actCommand = 'actCommand',
|
||||||
|
workflowsDirectory = 'workflowsDirectory',
|
||||||
dockerDesktopPath = 'dockerDesktopPath'
|
dockerDesktopPath = 'dockerDesktopPath'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,6 +19,16 @@ export namespace ConfigurationManager {
|
|||||||
export const searchPrefix: string = '@ext:sanjulaganepola.github-local-actions';
|
export const searchPrefix: string = '@ext:sanjulaganepola.github-local-actions';
|
||||||
|
|
||||||
export async function initialize(): Promise<void> {
|
export async function initialize(): Promise<void> {
|
||||||
|
let actCommand = ConfigurationManager.get<string>(Section.actCommand);
|
||||||
|
if (!actCommand) {
|
||||||
|
await ConfigurationManager.set(Section.actCommand, Act.defaultActCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
let workflowsDirectory = ConfigurationManager.get<string>(Section.workflowsDirectory);
|
||||||
|
if (!workflowsDirectory) {
|
||||||
|
await ConfigurationManager.set(Section.workflowsDirectory, WorkflowsManager.defaultWorkflowsDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
let dockerDesktopPath = ConfigurationManager.get<string>(Section.dockerDesktopPath);
|
let dockerDesktopPath = ConfigurationManager.get<string>(Section.dockerDesktopPath);
|
||||||
if (!dockerDesktopPath) {
|
if (!dockerDesktopPath) {
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
@@ -32,11 +44,6 @@ export namespace ConfigurationManager {
|
|||||||
|
|
||||||
await 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.defaultActCommand);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSearchTerm(section: Section): string {
|
export function getSearchTerm(section: Section): string {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import * as vscode from 'vscode';
|
import { commands, env, ExtensionContext, TreeCheckboxChangeEvent, Uri, window, workspace } from 'vscode';
|
||||||
import { commands, env, TreeCheckboxChangeEvent, Uri, window, workspace } from 'vscode';
|
|
||||||
import { Act } from './act';
|
import { Act } from './act';
|
||||||
import { ConfigurationManager } from './configurationManager';
|
import { ConfigurationManager, Section } from './configurationManager';
|
||||||
import { IssueHandler } from './issueHandler';
|
import { IssueHandler } from './issueHandler';
|
||||||
import ComponentsTreeDataProvider from './views/components/componentsTreeDataProvider';
|
import ComponentsTreeDataProvider from './views/components/componentsTreeDataProvider';
|
||||||
import { DecorationProvider } from './views/decorationProvider';
|
import { DecorationProvider } from './views/decorationProvider';
|
||||||
@@ -18,7 +17,7 @@ export let workflowsTreeDataProvider: WorkflowsTreeDataProvider;
|
|||||||
export let historyTreeDataProvider: HistoryTreeDataProvider;
|
export let historyTreeDataProvider: HistoryTreeDataProvider;
|
||||||
export let settingsTreeDataProvider: SettingsTreeDataProvider;
|
export let settingsTreeDataProvider: SettingsTreeDataProvider;
|
||||||
|
|
||||||
export function activate(context: vscode.ExtensionContext) {
|
export function activate(context: ExtensionContext) {
|
||||||
console.log('Congratulations, your extension "github-local-actions" is now active!');
|
console.log('Congratulations, your extension "github-local-actions" is now active!');
|
||||||
|
|
||||||
act = new Act(context);
|
act = new Act(context);
|
||||||
@@ -38,26 +37,28 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Create file watcher
|
// Create file watcher
|
||||||
const workflowsFileWatcher = workspace.createFileSystemWatcher(`**/${WorkflowsManager.WORKFLOWS_DIRECTORY}/*.{${WorkflowsManager.YML_EXTENSION},${WorkflowsManager.YAML_EXTENSION}}`);
|
let workflowsFileWatcher = setupFileWatcher(context);
|
||||||
workflowsFileWatcher.onDidCreate(() => {
|
|
||||||
workflowsTreeDataProvider.refresh();
|
|
||||||
settingsTreeDataProvider.refresh();
|
|
||||||
});
|
|
||||||
workflowsFileWatcher.onDidChange(() => {
|
|
||||||
workflowsTreeDataProvider.refresh();
|
|
||||||
settingsTreeDataProvider.refresh();
|
|
||||||
});
|
|
||||||
workflowsFileWatcher.onDidDelete(() => {
|
|
||||||
workflowsTreeDataProvider.refresh();
|
|
||||||
settingsTreeDataProvider.refresh();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Initialize configurations
|
// Initialize configurations
|
||||||
ConfigurationManager.initialize();
|
ConfigurationManager.initialize();
|
||||||
workspace.onDidChangeConfiguration(async event => {
|
workspace.onDidChangeConfiguration(async event => {
|
||||||
if (event.affectsConfiguration(ConfigurationManager.group)) {
|
if (event.affectsConfiguration(ConfigurationManager.group)) {
|
||||||
await ConfigurationManager.initialize();
|
await ConfigurationManager.initialize();
|
||||||
componentsTreeDataProvider.refresh();
|
|
||||||
|
if (event.affectsConfiguration(`${ConfigurationManager.group}.${Section.actCommand}`) ||
|
||||||
|
event.affectsConfiguration(`${ConfigurationManager.group}.${Section.dockerDesktopPath}`)) {
|
||||||
|
componentsTreeDataProvider.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.affectsConfiguration(`${ConfigurationManager.group}.${Section.workflowsDirectory}`)) {
|
||||||
|
workflowsTreeDataProvider.refresh();
|
||||||
|
settingsTreeDataProvider.refresh();
|
||||||
|
|
||||||
|
if (workflowsFileWatcher) {
|
||||||
|
workflowsFileWatcher.dispose();
|
||||||
|
workflowsFileWatcher = setupFileWatcher(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -77,4 +78,23 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setupFileWatcher(context: ExtensionContext) {
|
||||||
|
const workflowsDirectory = WorkflowsManager.getWorkflowsDirectory();
|
||||||
|
const workflowsFileWatcher = workspace.createFileSystemWatcher(`**/${workflowsDirectory}/*.{${WorkflowsManager.ymlExtension},${WorkflowsManager.yamlExtension}}`);
|
||||||
|
workflowsFileWatcher.onDidCreate(() => {
|
||||||
|
workflowsTreeDataProvider.refresh();
|
||||||
|
settingsTreeDataProvider.refresh();
|
||||||
|
});
|
||||||
|
workflowsFileWatcher.onDidChange(() => {
|
||||||
|
workflowsTreeDataProvider.refresh();
|
||||||
|
settingsTreeDataProvider.refresh();
|
||||||
|
});
|
||||||
|
workflowsFileWatcher.onDidDelete(() => {
|
||||||
|
workflowsTreeDataProvider.refresh();
|
||||||
|
settingsTreeDataProvider.refresh();
|
||||||
|
});
|
||||||
|
|
||||||
|
return workflowsFileWatcher;
|
||||||
|
}
|
||||||
|
|
||||||
export function deactivate() { }
|
export function deactivate() { }
|
||||||
|
|||||||
@@ -61,7 +61,8 @@ export default class WorkflowsTreeDataProvider implements TreeDataProvider<Githu
|
|||||||
if (activeTextEditor) {
|
if (activeTextEditor) {
|
||||||
const uri = activeTextEditor.document.uri;
|
const uri = activeTextEditor.document.uri;
|
||||||
const fileName = path.parse(uri.fsPath).base;
|
const fileName = path.parse(uri.fsPath).base;
|
||||||
if (uri.path.match(`.*/${WorkflowsManager.WORKFLOWS_DIRECTORY}/.*\\.(${WorkflowsManager.YAML_EXTENSION}|${WorkflowsManager.YML_EXTENSION})`)) {
|
const workflowsDirectory = WorkflowsManager.getWorkflowsDirectory();
|
||||||
|
if (uri.path.match(`.*/${workflowsDirectory}/.*\\.(${WorkflowsManager.yamlExtension}|${WorkflowsManager.ymlExtension})`)) {
|
||||||
const workspaceFolder = workspace.getWorkspaceFolder(uri);
|
const workspaceFolder = workspace.getWorkspaceFolder(uri);
|
||||||
if (workspaceFolder) {
|
if (workspaceFolder) {
|
||||||
const workflows = await act.workflowsManager.getWorkflows(workspaceFolder);
|
const workflows = await act.workflowsManager.getWorkflows(workspaceFolder);
|
||||||
@@ -69,7 +70,7 @@ export default class WorkflowsTreeDataProvider implements TreeDataProvider<Githu
|
|||||||
if (workflow) {
|
if (workflow) {
|
||||||
await act.runWorkflow(workspaceFolder, workflow);
|
await act.runWorkflow(workspaceFolder, workflow);
|
||||||
} else {
|
} else {
|
||||||
errorMessage = `Workflow not found in workflow directory (${WorkflowsManager.WORKFLOWS_DIRECTORY}).`;
|
errorMessage = `Workflow not found in workflow directory (${workflowsDirectory}).`;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
errorMessage = `${fileName} must be opened in a workspace folder to be executed locally.`;
|
errorMessage = `${fileName} must be opened in a workspace folder to be executed locally.`;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import * as fs from "fs/promises";
|
|||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import { RelativePattern, Uri, workspace, WorkspaceFolder } from "vscode";
|
import { RelativePattern, Uri, workspace, WorkspaceFolder } from "vscode";
|
||||||
import * as yaml from "yaml";
|
import * as yaml from "yaml";
|
||||||
|
import { ConfigurationManager, Section } from "./configurationManager";
|
||||||
|
|
||||||
export interface Workflow {
|
export interface Workflow {
|
||||||
name: string,
|
name: string,
|
||||||
@@ -17,14 +18,19 @@ export interface Job {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class WorkflowsManager {
|
export class WorkflowsManager {
|
||||||
static WORKFLOWS_DIRECTORY: string = '.github/workflows';
|
static defaultWorkflowsDirectory: string = '.github/workflows';
|
||||||
static YAML_EXTENSION: string = 'yaml';
|
static yamlExtension: string = 'yaml';
|
||||||
static YML_EXTENSION: string = 'yml';
|
static ymlExtension: string = 'yml';
|
||||||
|
|
||||||
|
static getWorkflowsDirectory(): string {
|
||||||
|
return ConfigurationManager.get<string>(Section.workflowsDirectory) || WorkflowsManager.defaultWorkflowsDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
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, `${WorkflowsManager.WORKFLOWS_DIRECTORY}/*.{${WorkflowsManager.YAML_EXTENSION},${WorkflowsManager.YML_EXTENSION}}`));
|
const workflowsDirectory = WorkflowsManager.getWorkflowsDirectory();
|
||||||
|
const workflowFileUris = await workspace.findFiles(new RelativePattern(workspaceFolder, `${workflowsDirectory}/*.{${WorkflowsManager.yamlExtension},${WorkflowsManager.ymlExtension}}`));
|
||||||
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