feat: implement basic feature working for Linux only
This commit is contained in:
26
src/install.ts
Normal file
26
src/install.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import {exec} from '@actions/exec'
|
||||
import {downloadTool} from '@actions/tool-cache'
|
||||
|
||||
export async function runCommand(command: string): Promise<string> {
|
||||
let output = ''
|
||||
const result = await exec(command, [], {
|
||||
listeners: {
|
||||
stdout: (data: Buffer) => {
|
||||
output += data.toString()
|
||||
}
|
||||
}
|
||||
})
|
||||
if (result !== 0) {
|
||||
throw new Error(`Failed to run command: ${command}`)
|
||||
}
|
||||
return output.trim()
|
||||
}
|
||||
|
||||
export async function install(version: string): Promise<string> {
|
||||
const system = runCommand('uname -s')
|
||||
const hardware = runCommand('uname -m')
|
||||
const url = `https://github.com/docker/compose/releases/download/${version}/docker-compose-${await system}-${await hardware}`
|
||||
const installerPath = await downloadTool(url)
|
||||
await exec(`chmod +x ${installerPath}`)
|
||||
return installerPath
|
||||
}
|
||||
15
src/main.ts
15
src/main.ts
@@ -1,16 +1,13 @@
|
||||
import * as core from '@actions/core'
|
||||
import {wait} from './wait'
|
||||
import {install} from './install'
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
const ms: string = core.getInput('milliseconds')
|
||||
core.debug(`Waiting ${ms} milliseconds ...`) // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true
|
||||
|
||||
core.debug(new Date().toTimeString())
|
||||
await wait(parseInt(ms, 10))
|
||||
core.debug(new Date().toTimeString())
|
||||
|
||||
core.setOutput('time', new Date().toTimeString())
|
||||
const version: string = core.getInput('verison', {
|
||||
required: true
|
||||
})
|
||||
const commandPath = await install(version)
|
||||
core.addPath(commandPath)
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user