From c3aa9bbb7d5ac66a17ad3f362f2ef25e9509be97 Mon Sep 17 00:00:00 2001 From: tikrack Date: Wed, 17 Sep 2025 17:54:00 +0330 Subject: [PATCH 1/2] refactor(wait): improve validation and readability without changing behavior --- src/wait.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/wait.ts b/src/wait.ts index c79f72112..ef9ec1e8e 100644 --- a/src/wait.ts +++ b/src/wait.ts @@ -1,13 +1,15 @@ /** * Waits for a number of milliseconds. * - * @param milliseconds The number of milliseconds to wait. + * @param milliseconds Number of milliseconds to wait. * @returns Resolves with 'done!' after the wait is over. */ -export async function wait(milliseconds: number): Promise { - return new Promise((resolve) => { - if (isNaN(milliseconds)) throw new Error('milliseconds is not a number') +export function wait(milliseconds: number): Promise { + if (Number.isNaN(milliseconds)) { + throw new Error("The 'milliseconds' parameter must be a valid number.") + } + return new Promise((resolve) => { setTimeout(() => resolve('done!'), milliseconds) }) } From d494531b65a8cdfaa03e582adcd3fd82a833274d Mon Sep 17 00:00:00 2001 From: tikrack Date: Wed, 17 Sep 2025 17:55:50 +0330 Subject: [PATCH 2/2] refactor(run): validate input and improve debug logs --- src/main.ts | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main.ts b/src/main.ts index d0ee6d394..36788801a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,20 +8,30 @@ import { wait } from './wait.js' */ export async function run(): Promise { try { - const ms: string = core.getInput('milliseconds') + const msInput = core.getInput('milliseconds') + const ms = parseInt(msInput, 10) + + if (Number.isNaN(ms)) { + throw new Error("Input 'milliseconds' must be a valid number.") + } // Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true - core.debug(`Waiting ${ms} milliseconds ...`) + core.debug(`Waiting for ${ms} milliseconds...`) + + const before = new Date().toTimeString() + core.debug(`Start time: ${before}`) + + await wait(ms) - // Log the current timestamp, wait, then log the new timestamp - core.debug(new Date().toTimeString()) - await wait(parseInt(ms, 10)) - core.debug(new Date().toTimeString()) + const after = new Date().toTimeString() + core.debug(`End time: ${after}`) // Set outputs for other workflow steps to use - core.setOutput('time', new Date().toTimeString()) + core.setOutput('time', after) } catch (error) { // Fail the workflow run if an error occurs - if (error instanceof Error) core.setFailed(error.message) + if (error instanceof Error) { + core.setFailed(error.message) + } } }