diff --git a/README.md b/README.md index fbe2585..b428252 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,9 @@ _This action is a fork of `benc-uk/workflow-dispatch` to add support for waiting The solution is to manually create a PAT and store it as a secret e.g. `${{ secrets.PERSONAL_TOKEN }}` ### `inputs` -**Optional.** The inputs to pass to the workflow (if any are configured), this must be a JSON encoded string, e.g. `{ "myInput": "foobar" }` +**Optional.** The inputs to pass to the workflow (if any are configured), this must be a JSON encoded string, e.g. `{ "myInput": "foobar" }`. + +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 ### `ref` **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 }}` diff --git a/action.yaml b/action.yaml index da43d6d..8e89b50 100644 --- a/action.yaml +++ b/action.yaml @@ -9,7 +9,7 @@ inputs: description: 'GitHub token with repo write access, can NOT use secrets.GITHUB_TOKEN, see readme' required: true inputs: - description: 'Inputs to pass to the workflow, must be a JSON string' + description: 'Inputs to pass to the workflow, must be a JSON string. All values must be strings (even if used as boolean or number)' required: false ref: description: 'The reference of the workflow run. The reference can be a branch, tag, or a commit SHA' diff --git a/dist/index.js b/dist/index.js index d134a3e..93a903d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -5912,7 +5912,7 @@ function run() { const args = utils_1.getArgs(); const workflowHandler = new workflow_handler_1.WorkflowHandler(args.token, args.workflowRef, args.owner, args.repo, args.ref); // Trigger workflow run - workflowHandler.triggerWorkflow(args.inputs); + yield workflowHandler.triggerWorkflow(args.inputs); core.info(`Workflow triggered 🚀`); if (args.displayWorkflowUrl) { const url = yield getFollowUrl(workflowHandler, args.displayWorkflowUrlInterval, args.displayWorkflowUrlTimeout); @@ -6147,7 +6147,8 @@ class WorkflowHandler { debug_1.debug('Workflow Dispatch', dispatchResp); } catch (error) { - core.setFailed(error.message); + debug_1.debug('Workflow Dispatch error', error.message); + throw error; } }); } @@ -6168,6 +6169,29 @@ class WorkflowHandler { }; } catch (error) { + debug_1.debug('Workflow Run status error', error); + throw error; + } + }); + } + getWorkflowRunArtifacts() { + return __awaiter(this, void 0, void 0, function* () { + try { + const runId = yield this.getWorkflowRunId(); + const response = yield this.octokit.actions.getWorkflowRunArtifacts({ + owner: this.owner, + repo: this.repo, + run_id: runId + }); + debug_1.debug('Workflow Run artifacts', response); + return { + url: response.data.html_url, + status: ofStatus(response.data.status), + conclusion: ofConclusion(response.data.conclusion) + }; + } + catch (error) { + debug_1.debug('Workflow Run artifacts error', error); throw error; } }); @@ -6204,6 +6228,7 @@ class WorkflowHandler { return this.workflowRunId; } catch (error) { + debug_1.debug('Get workflow run id error', error); throw error; } }); @@ -6234,7 +6259,7 @@ class WorkflowHandler { return this.workflowId; } catch (error) { - // core.setFailed(error.message); + debug_1.debug('List workflows error', error); throw error; } }); diff --git a/package.json b/package.json index 44ebf47..39e93ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "workflow-dispatch-and-wait", - "version": "2.1.0", + "version": "2.1.1", "description": "Trigger running GitHub Actions workflows and wait for result", "main": "dist/index.js", "scripts": { diff --git a/src/main.ts b/src/main.ts index 21b5d9a..2d71ef3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -69,7 +69,7 @@ async function run(): Promise { const workflowHandler = new WorkflowHandler(args.token, args.workflowRef, args.owner, args.repo, args.ref); // Trigger workflow run - workflowHandler.triggerWorkflow(args.inputs); + await workflowHandler.triggerWorkflow(args.inputs); core.info(`Workflow triggered 🚀`); if (args.displayWorkflowUrl) { diff --git a/src/workflow-handler.ts b/src/workflow-handler.ts index a6f4ba5..ac7e4d0 100644 --- a/src/workflow-handler.ts +++ b/src/workflow-handler.ts @@ -67,11 +67,10 @@ export class WorkflowHandler { ref: this.ref, inputs }); - debug('Workflow Dispatch', dispatchResp); - } catch (error) { - core.setFailed(error.message) + debug('Workflow Dispatch error', error.message); + throw error; } } @@ -83,7 +82,6 @@ export class WorkflowHandler { repo: this.repo, run_id: runId }); - debug('Workflow Run status', response); return { @@ -93,6 +91,30 @@ export class WorkflowHandler { }; } catch (error) { + debug('Workflow Run status error', error); + throw error; + } + } + + + async getWorkflowRunArtifacts(): Promise { + try { + const runId = await this.getWorkflowRunId(); + const response = await this.octokit.actions.getWorkflowRunArtifacts({ + owner: this.owner, + repo: this.repo, + run_id: runId + }); + debug('Workflow Run artifacts', response); + + return { + url: response.data.html_url, + status: ofStatus(response.data.status), + conclusion: ofConclusion(response.data.conclusion) + }; + + } catch (error) { + debug('Workflow Run artifacts error', error); throw error; } } @@ -110,12 +132,10 @@ export class WorkflowHandler { workflow_id: workflowId, event: 'workflow_dispatch' }); - debug('List Workflow Runs', response); const runs = response.data.workflow_runs .filter((r: any) => new Date(r.created_at).valueOf() >= this.triggerDate); - debug(`Filtered Workflow Runs (after trigger date: ${new Date(this.triggerDate).toISOString()})`, runs.map((r: any) => ({ id: r.id, name: r.name, @@ -132,6 +152,7 @@ export class WorkflowHandler { this.workflowRunId = runs[0].id as number; return this.workflowRunId; } catch (error) { + debug('Get workflow run id error', error); throw error; } @@ -152,7 +173,6 @@ export class WorkflowHandler { repo: this.repo }); const workflows = workflowsResp.data.workflows; - debug(`List Workflows`, workflows); // Locate workflow either by name or id @@ -162,7 +182,7 @@ export class WorkflowHandler { this.workflowId = workflowFind.id as number; return this.workflowId; } catch(error) { - // core.setFailed(error.message); + debug('List workflows error', error); throw error; } }