Skip to content

Commit fa6e1ad

Browse files
author
Automated Publisher
committed
Automated publish: Thu Jun 8 07:01:06 UTC 2023 928e175
1 parent 928e175 commit fa6e1ad

File tree

1 file changed

+63
-40
lines changed

1 file changed

+63
-40
lines changed

dist/index.js

Lines changed: 63 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5799,7 +5799,13 @@ const core = __importStar(__webpack_require__(186));
57995799
function debug(title, content) {
58005800
if (core.isDebug()) {
58015801
core.info(`::group::${title}`);
5802-
core.debug(JSON.stringify(content, null, 3));
5802+
try {
5803+
core.debug(JSON.stringify(content, null, 3));
5804+
}
5805+
catch (e) {
5806+
core.debug(`Failed to serialize object, trying toString. Cause: ${e}`);
5807+
core.debug(content === null || content === void 0 ? void 0 : content.toString());
5808+
}
58035809
core.info('::endgroup::');
58045810
}
58055811
}
@@ -5975,14 +5981,25 @@ var TimeUnit;
59755981
TimeUnit[TimeUnit["H"] = 3600000] = "H";
59765982
})(TimeUnit || (TimeUnit = {}));
59775983
function toMilliseconds(timeWithUnit) {
5978-
const unitStr = timeWithUnit.substr(timeWithUnit.length - 1);
5984+
const unitStr = timeWithUnit.substring(timeWithUnit.length - 1);
59795985
const unit = TimeUnit[unitStr.toUpperCase()];
59805986
if (!unit) {
59815987
throw new Error('Unknown time unit ' + unitStr);
59825988
}
59835989
const time = parseFloat(timeWithUnit);
59845990
return time * unit;
59855991
}
5992+
function parse(inputsJson) {
5993+
if (inputsJson) {
5994+
try {
5995+
return JSON.parse(inputsJson);
5996+
}
5997+
catch (e) {
5998+
throw new Error(`Failed to parse 'inputs' parameter. Muse be a valid JSON.\nCause: ${e}`);
5999+
}
6000+
}
6001+
return {};
6002+
}
59866003
function getArgs() {
59876004
// Required inputs
59886005
const token = core.getInput('token');
@@ -5993,11 +6010,7 @@ function getArgs() {
59936010
? core.getInput('repo').split('/')
59946011
: [github.context.repo.owner, github.context.repo.repo];
59956012
// Decode inputs, this MUST be a valid JSON string
5996-
let inputs = {};
5997-
const inputsJson = core.getInput('inputs');
5998-
if (inputsJson) {
5999-
inputs = JSON.parse(inputsJson);
6000-
}
6013+
let inputs = parse(core.getInput('inputs'));
60016014
const displayWorkflowUrlStr = core.getInput('display-workflow-run-url');
60026015
const displayWorkflowUrl = displayWorkflowUrlStr && displayWorkflowUrlStr === 'true';
60036016
const displayWorkflowUrlTimeout = toMilliseconds(core.getInput('display-workflow-run-url-timeout'));
@@ -6207,41 +6220,10 @@ class WorkflowHandler {
62076220
try {
62086221
core.debug('Get workflow run id');
62096222
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;
6223+
this.workflowRunId = yield this.findWorklowRunIdFromRunName(this.runName);
62216224
}
62226225
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;
6226+
this.workflowRunId = yield this.findWorkflowRunIdFromFirstRunOfSameWorkflowId();
62456227
}
62466228
return this.workflowRunId;
62476229
}
@@ -6251,6 +6233,47 @@ class WorkflowHandler {
62516233
}
62526234
});
62536235
}
6236+
findWorkflowRunIdFromFirstRunOfSameWorkflowId() {
6237+
return __awaiter(this, void 0, void 0, function* () {
6238+
const workflowId = yield this.getWorkflowId();
6239+
const response = yield this.octokit.actions.listWorkflowRuns({
6240+
owner: this.owner,
6241+
repo: this.repo,
6242+
workflow_id: workflowId,
6243+
event: 'workflow_dispatch'
6244+
});
6245+
debug_1.debug('List Workflow Runs', response);
6246+
const runs = response.data.workflow_runs
6247+
.filter((r) => new Date(r.created_at).setMilliseconds(0) >= this.triggerDate);
6248+
debug_1.debug(`Filtered Workflow Runs (after trigger date: ${new Date(this.triggerDate).toISOString()})`, runs.map((r) => ({
6249+
id: r.id,
6250+
name: r.name,
6251+
created_at: r.creatd_at,
6252+
triggerDate: new Date(this.triggerDate).toISOString(),
6253+
created_at_ts: new Date(r.created_at).valueOf(),
6254+
triggerDateTs: this.triggerDate
6255+
})));
6256+
if (runs.length == 0) {
6257+
throw new Error('Run not found');
6258+
}
6259+
return runs[0].id;
6260+
});
6261+
}
6262+
findWorklowRunIdFromRunName(runName) {
6263+
return __awaiter(this, void 0, void 0, function* () {
6264+
const result = yield this.octokit.rest.checks.listForRef({
6265+
check_name: runName,
6266+
owner: this.owner,
6267+
repo: this.repo,
6268+
ref: this.ref,
6269+
filter: 'latest'
6270+
});
6271+
if (result.length == 0) {
6272+
throw new Error('Run not found');
6273+
}
6274+
return result.check_runs[0].id;
6275+
});
6276+
}
62546277
getWorkflowId() {
62556278
return __awaiter(this, void 0, void 0, function* () {
62566279
if (this.workflowId) {

0 commit comments

Comments
 (0)