mirror of
https://github.com/LukeHagar/stats-action.git
synced 2025-12-06 04:21:26 +00:00
Initial commit
This commit is contained in:
6
src/index.js
Normal file
6
src/index.js
Normal file
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* The entrypoint for the action.
|
||||
*/
|
||||
const { run } = require('./main')
|
||||
|
||||
run()
|
||||
30
src/main.js
Normal file
30
src/main.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const core = require('@actions/core')
|
||||
const { wait } = require('./wait')
|
||||
|
||||
/**
|
||||
* The main function for the action.
|
||||
* @returns {Promise<void>} Resolves when the action is complete.
|
||||
*/
|
||||
async function run() {
|
||||
try {
|
||||
const ms = core.getInput('milliseconds', { required: true })
|
||||
|
||||
// Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true
|
||||
core.debug(`Waiting ${ms} milliseconds ...`)
|
||||
|
||||
// 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())
|
||||
|
||||
// Set outputs for other workflow steps to use
|
||||
core.setOutput('time', new Date().toTimeString())
|
||||
} catch (error) {
|
||||
// Fail the workflow run if an error occurs
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
run
|
||||
}
|
||||
17
src/wait.js
Normal file
17
src/wait.js
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Wait for a number of milliseconds.
|
||||
*
|
||||
* @param {number} milliseconds The number of milliseconds to wait.
|
||||
* @returns {Promise<string>} Resolves with 'done!' after the wait is over.
|
||||
*/
|
||||
async function wait(milliseconds) {
|
||||
return new Promise(resolve => {
|
||||
if (isNaN(milliseconds)) {
|
||||
throw new Error('milliseconds not a number')
|
||||
}
|
||||
|
||||
setTimeout(() => resolve('done!'), milliseconds)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { wait }
|
||||
Reference in New Issue
Block a user