Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ permissions:

jobs:
build:
runs-on: ubuntu-latest
# Keep the runner compatible with the locked Playwright browser installer.
runs-on: ubuntu-24.04
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16.x
node-version: 24.x
cache: "npm"
registry-url: "https://npm.pkg.github.com"
- run: npm ci
Expand Down
78 changes: 75 additions & 3 deletions src/commands/triggerWorkflowRun.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
import {basename} from "path";
import * as vscode from "vscode";

import {getGitHead, getGitHubContextForWorkspaceUri, GitHubRepoContext} from "../git/repository";
import {getWorkflowUri, parseWorkflowFile} from "../workflow/workflow";

import {Workflow} from "../model";
import {RunStore} from "../store/store";

import {log} from "../log";

interface TriggerRunCommandOptions {
wf?: Workflow;
gitHubRepoContext: GitHubRepoContext;
}

export function registerTriggerWorkflowRun(context: vscode.ExtensionContext) {
export function registerTriggerWorkflowRun(context: vscode.ExtensionContext, store: RunStore) {
context.subscriptions.push(
vscode.commands.registerCommand(
"github-actions.explorer.triggerRun",
async (args: TriggerRunCommandOptions | vscode.Uri) => {
let workflowUri: vscode.Uri | null = null;
let workflowIdForApi: number | string | undefined;

if (args instanceof vscode.Uri) {
workflowUri = args;
workflowIdForApi = basename(workflowUri.fsPath);
} else if (args.wf) {
const wf: Workflow = args.wf;
workflowUri = getWorkflowUri(args.gitHubRepoContext, wf.path);
workflowIdForApi = wf.id;
}

if (!workflowUri) {
Expand All @@ -43,6 +51,28 @@ export function registerTriggerWorkflowRun(context: vscode.ExtensionContext) {
return;
}

const relativeWorkflowPath = vscode.workspace.asRelativePath(workflowUri, false);
if (!workflowIdForApi) {
workflowIdForApi = basename(workflowUri.fsPath);
Comment thread
spboyer marked this conversation as resolved.
Resolved
}

let latestRunId: number | undefined;
try {
log(`Fetching latest run for workflow: ${workflowIdForApi}`);
const result = await gitHubRepoContext.client.actions.listWorkflowRuns({
owner: gitHubRepoContext.owner,
repo: gitHubRepoContext.name,
workflow_id: workflowIdForApi,
per_page: 1
});
latestRunId = result.data.workflow_runs[0]?.id;
log(`Latest run ID before trigger: ${latestRunId}`);
} catch (e) {
log(`Error fetching latest run: ${(e as Error).message}`);
}

let dispatched = false;

let selectedEvent: string | undefined;
if (workflow.events.workflow_dispatch !== undefined && workflow.events.repository_dispatch !== undefined) {
selectedEvent = await vscode.window.showQuickPick(["repository_dispatch", "workflow_dispatch"], {
Expand Down Expand Up @@ -85,8 +115,6 @@ export function registerTriggerWorkflowRun(context: vscode.ExtensionContext) {
}

try {
const relativeWorkflowPath = vscode.workspace.asRelativePath(workflowUri, false);

await gitHubRepoContext.client.actions.createWorkflowDispatch({
owner: gitHubRepoContext.owner,
repo: gitHubRepoContext.name,
Expand All @@ -95,6 +123,7 @@ export function registerTriggerWorkflowRun(context: vscode.ExtensionContext) {
inputs
});

dispatched = true;
vscode.window.setStatusBarMessage(`GitHub Actions: Workflow event dispatched`, 2000);
} catch (error) {
return vscode.window.showErrorMessage(`Could not create workflow dispatch: ${(error as Error)?.message}`);
Expand Down Expand Up @@ -134,10 +163,53 @@ export function registerTriggerWorkflowRun(context: vscode.ExtensionContext) {
client_payload: {}
});

dispatched = true;
vscode.window.setStatusBarMessage(`GitHub Actions: Repository event '${event_type}' dispatched`, 2000);
}
}

if (dispatched) {
const refreshed = await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Window,
title: "Waiting for workflow run to start..."
},
async () => {
log("Starting loop to check for new workflow run...");
for (let i = 0; i < 20; i++) {
if (i > 0) {
await new Promise(resolve => setTimeout(resolve, 1000));
}
try {
log(`Checking for new run (attempt ${i + 1}/20)...`);
const result = await gitHubRepoContext.client.actions.listWorkflowRuns({
owner: gitHubRepoContext.owner,
repo: gitHubRepoContext.name,
workflow_id: workflowIdForApi as string | number,
per_page: 1
});
const newLatestRunId = result.data.workflow_runs[0]?.id;
log(`Latest run ID found: ${newLatestRunId} (Previous: ${latestRunId ?? "none"})`);

if (newLatestRunId && newLatestRunId !== latestRunId) {
log(`Found new workflow run: ${newLatestRunId}. Triggering refresh and polling.`);
await vscode.commands.executeCommand("github-actions.explorer.refresh");
// Poll for 15 minutes (225 * 4s)
store.pollRun(newLatestRunId, gitHubRepoContext, 4000, 225);
Comment thread
spboyer marked this conversation as resolved.
Resolved
return true;
}
} catch (e) {
log(`Error checking for new run: ${(e as Error).message}`);
}
}
return false;
}
);
if (refreshed) {
return;
}
}

return vscode.commands.executeCommand("github-actions.explorer.refresh");
Comment thread
spboyer marked this conversation as resolved.
Resolved
}
)
Expand Down
9 changes: 8 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ export async function activate(context: vscode.ExtensionContext) {

const store = new RunStore();

// Handle focus changes to pause/resume polling
context.subscriptions.push(
vscode.window.onDidChangeWindowState(e => {
store.setFocused(e.focused);
})
);

// Pinned workflows
await initPinnedWorkflows(store);

Expand All @@ -73,7 +80,7 @@ export async function activate(context: vscode.ExtensionContext) {
registerOpenWorkflowFile(context);
registerOpenWorkflowJobLogs(context);
registerOpenWorkflowStepLogs(context);
registerTriggerWorkflowRun(context);
registerTriggerWorkflowRun(context, store);
registerReRunWorkflowRun(context);
registerCancelWorkflowRun(context);

Expand Down
Loading
Loading