Skip to content

Commit 93e95b1

Browse files
fix(trigger) Missing await + indicate that inputs MUST be strings
1 parent dccdc41 commit 93e95b1

File tree

6 files changed

+62
-15
lines changed

6 files changed

+62
-15
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ _This action is a fork of `benc-uk/workflow-dispatch` to add support for waiting
2424
The solution is to manually create a PAT and store it as a secret e.g. `${{ secrets.PERSONAL_TOKEN }}`
2525

2626
### `inputs`
27-
**Optional.** The inputs to pass to the workflow (if any are configured), this must be a JSON encoded string, e.g. `{ "myInput": "foobar" }`
27+
**Optional.** The inputs to pass to the workflow (if any are configured), this must be a JSON encoded string, e.g. `{ "myInput": "foobar" }`.
28+
29+
All values must be strings (even if they are used as booleans or numbers in the triggered workflow). The triggered workflow should use `fromJson` function to get the right type
2830

2931
### `ref`
3032
**Optional.** The Git reference used with the triggered workflow run. The reference can be a branch, tag, or a commit SHA. If omitted the context ref of the triggering workflow is used. If you want to trigger on pull requests and run the target workflow in the context of the pull request branch, set the ref to `${{ github.event.pull_request.head.ref }}`

action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ inputs:
99
description: 'GitHub token with repo write access, can NOT use secrets.GITHUB_TOKEN, see readme'
1010
required: true
1111
inputs:
12-
description: 'Inputs to pass to the workflow, must be a JSON string'
12+
description: 'Inputs to pass to the workflow, must be a JSON string. All values must be strings (even if used as boolean or number)'
1313
required: false
1414
ref:
1515
description: 'The reference of the workflow run. The reference can be a branch, tag, or a commit SHA'

dist/index.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5912,7 +5912,7 @@ function run() {
59125912
const args = utils_1.getArgs();
59135913
const workflowHandler = new workflow_handler_1.WorkflowHandler(args.token, args.workflowRef, args.owner, args.repo, args.ref);
59145914
// Trigger workflow run
5915-
workflowHandler.triggerWorkflow(args.inputs);
5915+
yield workflowHandler.triggerWorkflow(args.inputs);
59165916
core.info(`Workflow triggered 🚀`);
59175917
if (args.displayWorkflowUrl) {
59185918
const url = yield getFollowUrl(workflowHandler, args.displayWorkflowUrlInterval, args.displayWorkflowUrlTimeout);
@@ -6147,7 +6147,8 @@ class WorkflowHandler {
61476147
debug_1.debug('Workflow Dispatch', dispatchResp);
61486148
}
61496149
catch (error) {
6150-
core.setFailed(error.message);
6150+
debug_1.debug('Workflow Dispatch error', error.message);
6151+
throw error;
61516152
}
61526153
});
61536154
}
@@ -6168,6 +6169,29 @@ class WorkflowHandler {
61686169
};
61696170
}
61706171
catch (error) {
6172+
debug_1.debug('Workflow Run status error', error);
6173+
throw error;
6174+
}
6175+
});
6176+
}
6177+
getWorkflowRunArtifacts() {
6178+
return __awaiter(this, void 0, void 0, function* () {
6179+
try {
6180+
const runId = yield this.getWorkflowRunId();
6181+
const response = yield this.octokit.actions.getWorkflowRunArtifacts({
6182+
owner: this.owner,
6183+
repo: this.repo,
6184+
run_id: runId
6185+
});
6186+
debug_1.debug('Workflow Run artifacts', response);
6187+
return {
6188+
url: response.data.html_url,
6189+
status: ofStatus(response.data.status),
6190+
conclusion: ofConclusion(response.data.conclusion)
6191+
};
6192+
}
6193+
catch (error) {
6194+
debug_1.debug('Workflow Run artifacts error', error);
61716195
throw error;
61726196
}
61736197
});
@@ -6204,6 +6228,7 @@ class WorkflowHandler {
62046228
return this.workflowRunId;
62056229
}
62066230
catch (error) {
6231+
debug_1.debug('Get workflow run id error', error);
62076232
throw error;
62086233
}
62096234
});
@@ -6234,7 +6259,7 @@ class WorkflowHandler {
62346259
return this.workflowId;
62356260
}
62366261
catch (error) {
6237-
// core.setFailed(error.message);
6262+
debug_1.debug('List workflows error', error);
62386263
throw error;
62396264
}
62406265
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "workflow-dispatch-and-wait",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "Trigger running GitHub Actions workflows and wait for result",
55
"main": "dist/index.js",
66
"scripts": {

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async function run(): Promise<void> {
6969
const workflowHandler = new WorkflowHandler(args.token, args.workflowRef, args.owner, args.repo, args.ref);
7070

7171
// Trigger workflow run
72-
workflowHandler.triggerWorkflow(args.inputs);
72+
await workflowHandler.triggerWorkflow(args.inputs);
7373
core.info(`Workflow triggered 🚀`);
7474

7575
if (args.displayWorkflowUrl) {

src/workflow-handler.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ export class WorkflowHandler {
6767
ref: this.ref,
6868
inputs
6969
});
70-
7170
debug('Workflow Dispatch', dispatchResp);
72-
7371
} catch (error) {
74-
core.setFailed(error.message)
72+
debug('Workflow Dispatch error', error.message);
73+
throw error;
7574
}
7675
}
7776

@@ -83,7 +82,6 @@ export class WorkflowHandler {
8382
repo: this.repo,
8483
run_id: runId
8584
});
86-
8785
debug('Workflow Run status', response);
8886

8987
return {
@@ -93,6 +91,30 @@ export class WorkflowHandler {
9391
};
9492

9593
} catch (error) {
94+
debug('Workflow Run status error', error);
95+
throw error;
96+
}
97+
}
98+
99+
100+
async getWorkflowRunArtifacts(): Promise<WorkflowRunResult> {
101+
try {
102+
const runId = await this.getWorkflowRunId();
103+
const response = await this.octokit.actions.getWorkflowRunArtifacts({
104+
owner: this.owner,
105+
repo: this.repo,
106+
run_id: runId
107+
});
108+
debug('Workflow Run artifacts', response);
109+
110+
return {
111+
url: response.data.html_url,
112+
status: ofStatus(response.data.status),
113+
conclusion: ofConclusion(response.data.conclusion)
114+
};
115+
116+
} catch (error) {
117+
debug('Workflow Run artifacts error', error);
96118
throw error;
97119
}
98120
}
@@ -110,12 +132,10 @@ export class WorkflowHandler {
110132
workflow_id: workflowId,
111133
event: 'workflow_dispatch'
112134
});
113-
114135
debug('List Workflow Runs', response);
115136

116137
const runs = response.data.workflow_runs
117138
.filter((r: any) => new Date(r.created_at).valueOf() >= this.triggerDate);
118-
119139
debug(`Filtered Workflow Runs (after trigger date: ${new Date(this.triggerDate).toISOString()})`, runs.map((r: any) => ({
120140
id: r.id,
121141
name: r.name,
@@ -132,6 +152,7 @@ export class WorkflowHandler {
132152
this.workflowRunId = runs[0].id as number;
133153
return this.workflowRunId;
134154
} catch (error) {
155+
debug('Get workflow run id error', error);
135156
throw error;
136157
}
137158

@@ -152,7 +173,6 @@ export class WorkflowHandler {
152173
repo: this.repo
153174
});
154175
const workflows = workflowsResp.data.workflows;
155-
156176
debug(`List Workflows`, workflows);
157177

158178
// Locate workflow either by name or id
@@ -162,7 +182,7 @@ export class WorkflowHandler {
162182
this.workflowId = workflowFind.id as number;
163183
return this.workflowId;
164184
} catch(error) {
165-
// core.setFailed(error.message);
185+
debug('List workflows error', error);
166186
throw error;
167187
}
168188
}

0 commit comments

Comments
 (0)