This commit is contained in:
Jeff Dickey 2023-01-14 08:36:43 -06:00
parent 35f6329d75
commit 67b1e31166
7 changed files with 49 additions and 54 deletions

View file

@ -1,29 +1,14 @@
import {wait} from '../src/wait'
import * as process from 'process'
import * as cp from 'child_process'
import * as path from 'path'
import {expect, test} from '@jest/globals'
import {expect, test, jest} from '@jest/globals'
import {run} from '../src/main'
import {exec} from '@actions/exec'
test('throws invalid number', async () => {
const input = parseInt('foo', 10)
await expect(wait(input)).rejects.toThrow('milliseconds not a number')
})
test('wait 500 ms', async () => {
const start = new Date()
await wait(500)
const end = new Date()
var delta = Math.abs(end.getTime() - start.getTime())
expect(delta).toBeGreaterThan(450)
})
jest.mock('@actions/exec')
// shows how the runner will run a javascript action with env / stdout protocol
test('test runs', () => {
process.env['INPUT_MILLISECONDS'] = '500'
const np = process.execPath
const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecFileSyncOptions = {
env: process.env
}
console.log(cp.execFileSync(np, [ip], options).toString())
test('install', async () => {
await run()
expect(exec).toBeCalledWith('rtx', ['install'])
})

View file

@ -1,11 +1,10 @@
name: 'Your name here'
description: 'Provide a description here'
author: 'Your name or organization here'
name: rtx install
description: Actions for working with rtx runtime manager
author: Jeff Dickey (@jdxcode)
inputs:
milliseconds: # change this
required: true
description: 'input description here'
default: 'default value if applicable'
tool_versions:
required: false
description: If present, this value will be written to the .tool-versions file
runs:
using: 'node16'
main: 'dist/index.js'
using: node16
main: dist/index.js

6
dist/index.js generated vendored
View file

@ -8,7 +8,11 @@ require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -25,7 +25,8 @@
"author": "",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.10.0"
"@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1"
},
"devDependencies": {
"@types/node": "^18.11.0",

View file

@ -1,19 +1,34 @@
import * as core from '@actions/core'
import {wait} from './wait'
import * as exec from '@actions/exec'
import * as fs from 'fs'
async function run(): Promise<void> {
await setupRTX()
await setToolVersions()
await exec.exec('rtx', ['install'])
}
async function setupRTX(): Promise<void> {
console.error("TODO: SETUPRTX");
}
async function setToolVersions(): Promise<void> {
let toolVersions = core.getInput("tool_versions", { required: false });
if (toolVersions) {
await fs.promises.writeFile(".tool-versions", toolVersions, {
encoding: "utf8",
});
}
}
if (require.main === module) {
try {
const ms: string = core.getInput('milliseconds')
core.debug(`Waiting ${ms} milliseconds ...`) // debug is only output if you set the secret `ACTIONS_STEP_DEBUG` to true
core.debug(new Date().toTimeString())
await wait(parseInt(ms, 10))
core.debug(new Date().toTimeString())
core.setOutput('time', new Date().toTimeString())
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)
}
}
run()
} catch (err) {
if (err instanceof Error) {
core.setFailed(err.message)
} else throw err
}
}
export { run }

View file

@ -1,9 +0,0 @@
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)
})
}