init
This commit is contained in:
parent
35f6329d75
commit
67b1e31166
7 changed files with 49 additions and 54 deletions
|
@ -1,29 +1,14 @@
|
||||||
import {wait} from '../src/wait'
|
|
||||||
import * as process from 'process'
|
import * as process from 'process'
|
||||||
import * as cp from 'child_process'
|
import * as cp from 'child_process'
|
||||||
import * as path from 'path'
|
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 () => {
|
jest.mock('@actions/exec')
|
||||||
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)
|
|
||||||
})
|
|
||||||
|
|
||||||
// shows how the runner will run a javascript action with env / stdout protocol
|
// shows how the runner will run a javascript action with env / stdout protocol
|
||||||
test('test runs', () => {
|
test('install', async () => {
|
||||||
process.env['INPUT_MILLISECONDS'] = '500'
|
await run()
|
||||||
const np = process.execPath
|
expect(exec).toBeCalledWith('rtx', ['install'])
|
||||||
const ip = path.join(__dirname, '..', 'lib', 'main.js')
|
|
||||||
const options: cp.ExecFileSyncOptions = {
|
|
||||||
env: process.env
|
|
||||||
}
|
|
||||||
console.log(cp.execFileSync(np, [ip], options).toString())
|
|
||||||
})
|
})
|
||||||
|
|
17
action.yml
17
action.yml
|
@ -1,11 +1,10 @@
|
||||||
name: 'Your name here'
|
name: rtx install
|
||||||
description: 'Provide a description here'
|
description: Actions for working with rtx runtime manager
|
||||||
author: 'Your name or organization here'
|
author: Jeff Dickey (@jdxcode)
|
||||||
inputs:
|
inputs:
|
||||||
milliseconds: # change this
|
tool_versions:
|
||||||
required: true
|
required: false
|
||||||
description: 'input description here'
|
description: If present, this value will be written to the .tool-versions file
|
||||||
default: 'default value if applicable'
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node16'
|
using: node16
|
||||||
main: 'dist/index.js'
|
main: dist/index.js
|
||||||
|
|
6
dist/index.js
generated
vendored
6
dist/index.js
generated
vendored
|
@ -8,7 +8,11 @@ require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
|
||||||
|
|
||||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||||
if (k2 === undefined) k2 = k;
|
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) {
|
}) : (function(o, m, k, k2) {
|
||||||
if (k2 === undefined) k2 = k;
|
if (k2 === undefined) k2 = k;
|
||||||
o[k2] = m[k];
|
o[k2] = m[k];
|
||||||
|
|
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
|
@ -25,7 +25,8 @@
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0"
|
"@actions/core": "^1.10.0",
|
||||||
|
"@actions/exec": "^1.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^18.11.0",
|
"@types/node": "^18.11.0",
|
||||||
|
|
37
src/main.ts
37
src/main.ts
|
@ -1,19 +1,34 @@
|
||||||
import * as core from '@actions/core'
|
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> {
|
async function run(): Promise<void> {
|
||||||
try {
|
await setupRTX()
|
||||||
const ms: string = core.getInput('milliseconds')
|
await setToolVersions()
|
||||||
core.debug(`Waiting ${ms} milliseconds ...`) // debug is only output if you set the secret `ACTIONS_STEP_DEBUG` to true
|
await exec.exec('rtx', ['install'])
|
||||||
|
}
|
||||||
|
|
||||||
core.debug(new Date().toTimeString())
|
async function setupRTX(): Promise<void> {
|
||||||
await wait(parseInt(ms, 10))
|
console.error("TODO: SETUPRTX");
|
||||||
core.debug(new Date().toTimeString())
|
}
|
||||||
|
|
||||||
core.setOutput('time', new Date().toTimeString())
|
async function setToolVersions(): Promise<void> {
|
||||||
} catch (error) {
|
let toolVersions = core.getInput("tool_versions", { required: false });
|
||||||
if (error instanceof Error) core.setFailed(error.message)
|
if (toolVersions) {
|
||||||
|
await fs.promises.writeFile(".tool-versions", toolVersions, {
|
||||||
|
encoding: "utf8",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run()
|
if (require.main === module) {
|
||||||
|
try {
|
||||||
|
run()
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof Error) {
|
||||||
|
core.setFailed(err.message)
|
||||||
|
} else throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { run }
|
||||||
|
|
|
@ -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)
|
|
||||||
})
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue