Skip to content

Commit d3d8b1f

Browse files
author
Automated Publisher
committed
Automated publish: Thu Jun 8 06:14:15 UTC 2023 d0f84d4
1 parent d0f84d4 commit d3d8b1f

File tree

1 file changed

+43
-25
lines changed

1 file changed

+43
-25
lines changed

dist/index.js

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5910,7 +5910,7 @@ function run() {
59105910
return __awaiter(this, void 0, void 0, function* () {
59115911
try {
59125912
const args = utils_1.getArgs();
5913-
const workflowHandler = new workflow_handler_1.WorkflowHandler(args.token, args.workflowRef, args.owner, args.repo, args.ref);
5913+
const workflowHandler = new workflow_handler_1.WorkflowHandler(args.token, args.workflowRef, args.owner, args.repo, args.ref, args.runName);
59145914
// Trigger workflow run
59155915
yield workflowHandler.triggerWorkflow(args.inputs);
59165916
core.info(`Workflow triggered 🚀`);
@@ -6006,6 +6006,7 @@ function getArgs() {
60066006
const waitForCompletion = waitForCompletionStr && waitForCompletionStr === 'true';
60076007
const waitForCompletionTimeout = toMilliseconds(core.getInput('wait-for-completion-timeout'));
60086008
const checkStatusInterval = toMilliseconds(core.getInput('wait-for-completion-interval'));
6009+
const runName = core.getInput('run-name');
60096010
return {
60106011
token,
60116012
workflowRef,
@@ -6018,7 +6019,8 @@ function getArgs() {
60186019
displayWorkflowUrlInterval,
60196020
checkStatusInterval,
60206021
waitForCompletion,
6021-
waitForCompletionTimeout
6022+
waitForCompletionTimeout,
6023+
runName
60226024
};
60236025
}
60246026
exports.getArgs = getArgs;
@@ -6123,11 +6125,12 @@ const ofConclusion = (conclusion) => {
61236125
return WorkflowRunConclusion[key];
61246126
};
61256127
class WorkflowHandler {
6126-
constructor(token, workflowRef, owner, repo, ref) {
6128+
constructor(token, workflowRef, owner, repo, ref, runName) {
61276129
this.workflowRef = workflowRef;
61286130
this.owner = owner;
61296131
this.repo = repo;
61306132
this.ref = ref;
6133+
this.runName = runName;
61316134
this.triggerDate = 0;
61326135
// Get octokit client for making API calls
61336136
this.octokit = github.getOctokit(token);
@@ -6136,7 +6139,7 @@ class WorkflowHandler {
61366139
return __awaiter(this, void 0, void 0, function* () {
61376140
try {
61386141
const workflowId = yield this.getWorkflowId();
6139-
this.triggerDate = Date.now();
6142+
this.triggerDate = new Date().setMilliseconds(0);
61406143
const dispatchResp = yield this.octokit.actions.createWorkflowDispatch({
61416144
owner: this.owner,
61426145
repo: this.repo,
@@ -6203,28 +6206,43 @@ class WorkflowHandler {
62036206
}
62046207
try {
62056208
core.debug('Get workflow run id');
6206-
const workflowId = yield this.getWorkflowId();
6207-
const response = yield this.octokit.actions.listWorkflowRuns({
6208-
owner: this.owner,
6209-
repo: this.repo,
6210-
workflow_id: workflowId,
6211-
event: 'workflow_dispatch'
6212-
});
6213-
debug_1.debug('List Workflow Runs', response);
6214-
const runs = response.data.workflow_runs
6215-
.filter((r) => new Date(r.created_at).setMilliseconds(0) >= this.triggerDate);
6216-
debug_1.debug(`Filtered Workflow Runs (after trigger date: ${new Date(this.triggerDate).toISOString()})`, runs.map((r) => ({
6217-
id: r.id,
6218-
name: r.name,
6219-
created_at: r.creatd_at,
6220-
triggerDate: new Date(this.triggerDate).toISOString(),
6221-
created_at_ts: new Date(r.created_at).valueOf(),
6222-
triggerDateTs: this.triggerDate
6223-
})));
6224-
if (runs.length == 0) {
6225-
throw new Error('Run not found');
6209+
if (this.runName) {
6210+
const result = yield this.octokit.rest.checks.listForRef({
6211+
check_name: this.runName,
6212+
owner: this.owner,
6213+
repo: this.repo,
6214+
ref: this.ref,
6215+
filter: 'latest'
6216+
});
6217+
if (result.length == 0) {
6218+
throw new Error('Run not found');
6219+
}
6220+
this.workflowRunId = result.check_runs[0].id;
6221+
}
6222+
else {
6223+
const workflowId = yield this.getWorkflowId();
6224+
const response = yield this.octokit.actions.listWorkflowRuns({
6225+
owner: this.owner,
6226+
repo: this.repo,
6227+
workflow_id: workflowId,
6228+
event: 'workflow_dispatch'
6229+
});
6230+
debug_1.debug('List Workflow Runs', response);
6231+
const runs = response.data.workflow_runs
6232+
.filter((r) => new Date(r.created_at).setMilliseconds(0) >= this.triggerDate);
6233+
debug_1.debug(`Filtered Workflow Runs (after trigger date: ${new Date(this.triggerDate).toISOString()})`, runs.map((r) => ({
6234+
id: r.id,
6235+
name: r.name,
6236+
created_at: r.creatd_at,
6237+
triggerDate: new Date(this.triggerDate).toISOString(),
6238+
created_at_ts: new Date(r.created_at).valueOf(),
6239+
triggerDateTs: this.triggerDate
6240+
})));
6241+
if (runs.length == 0) {
6242+
throw new Error('Run not found');
6243+
}
6244+
this.workflowRunId = runs[0].id;
62266245
}
6227-
this.workflowRunId = runs[0].id;
62286246
return this.workflowRunId;
62296247
}
62306248
catch (error) {

0 commit comments

Comments
 (0)