mirror of
https://github.com/actions/container-toolkit-action.git
synced 2025-12-30 22:08:58 +08:00
Formatting and testing
This commit is contained in:
7
src/index.ts
Normal file
7
src/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* The entrypoint for the action.
|
||||
*/
|
||||
import { run } from './main'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
run()
|
||||
35
src/main.ts
35
src/main.ts
@@ -1,17 +1,30 @@
|
||||
const core = require('@actions/core');
|
||||
const github = require('@actions/github');
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import { wait } from './wait'
|
||||
|
||||
async function run() {
|
||||
/**
|
||||
* The main function for the action.
|
||||
*/
|
||||
export async function run(): Promise<void> {
|
||||
try {
|
||||
const myInput = core.getInput('myInput');
|
||||
core.debug(`Hello ${myInput} from inside a container`);
|
||||
// Get the action input(s)
|
||||
const ms: number = parseInt(core.getInput('milliseconds'), 10)
|
||||
|
||||
// Get github context data
|
||||
const context = github.context;
|
||||
console.log(`We can even get context data, like the repo: ${context.repo.repo}`)
|
||||
// Output the payload for debugging
|
||||
// Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true
|
||||
core.debug(
|
||||
`The event payload: ${JSON.stringify(github.context.payload, null, 2)}`
|
||||
)
|
||||
|
||||
// Log the current timestamp, wait, then log the new timestamp
|
||||
core.info(new Date().toTimeString())
|
||||
await wait(ms)
|
||||
core.info(new Date().toTimeString())
|
||||
|
||||
// Set outputs for other workflow steps to use
|
||||
core.setOutput('time', new Date().toTimeString())
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
// Fail the workflow run if an error occurs
|
||||
if (error instanceof Error) core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
|
||||
12
src/wait.ts
Normal file
12
src/wait.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Wait for a number of milliseconds. Resolves with 'done!' after the wait time.
|
||||
*/
|
||||
export async function wait(milliseconds: number): Promise<string> {
|
||||
return new Promise(resolve => {
|
||||
if (isNaN(milliseconds)) {
|
||||
throw new Error('milliseconds not a number')
|
||||
}
|
||||
|
||||
setTimeout(() => resolve('done!'), milliseconds)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user