mirror of
https://github.com/actions/javascript-action.git
synced 2025-12-15 06:50:50 +00:00
Convert to ESM
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
/**
|
||||
* The entrypoint for the action.
|
||||
* The entrypoint for the action. This file simply imports and runs the action's
|
||||
* main logic.
|
||||
*/
|
||||
const { run } = require('./main')
|
||||
import { run } from './main.js'
|
||||
|
||||
/* istanbul ignore next */
|
||||
run()
|
||||
|
||||
15
src/main.js
15
src/main.js
@@ -1,13 +1,14 @@
|
||||
const core = require('@actions/core')
|
||||
const { wait } = require('./wait')
|
||||
import * as core from '@actions/core'
|
||||
import { wait } from './wait.js'
|
||||
|
||||
/**
|
||||
* The main function for the action.
|
||||
*
|
||||
* @returns {Promise<void>} Resolves when the action is complete.
|
||||
*/
|
||||
async function run() {
|
||||
export async function run() {
|
||||
try {
|
||||
const ms = core.getInput('milliseconds', { required: true })
|
||||
const ms = core.getInput('milliseconds')
|
||||
|
||||
// Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true
|
||||
core.debug(`Waiting ${ms} milliseconds ...`)
|
||||
@@ -21,10 +22,6 @@ async function run() {
|
||||
core.setOutput('time', new Date().toTimeString())
|
||||
} catch (error) {
|
||||
// Fail the workflow run if an error occurs
|
||||
core.setFailed(error.message)
|
||||
if (error instanceof Error) core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
run
|
||||
}
|
||||
|
||||
12
src/wait.js
12
src/wait.js
@@ -1,17 +1,13 @@
|
||||
/**
|
||||
* Wait for a number of milliseconds.
|
||||
* Waits 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')
|
||||
}
|
||||
export async function wait(milliseconds) {
|
||||
return new Promise((resolve) => {
|
||||
if (isNaN(milliseconds)) throw new Error('milliseconds is not a number')
|
||||
|
||||
setTimeout(() => resolve('done!'), milliseconds)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { wait }
|
||||
|
||||
Reference in New Issue
Block a user