feat: implement basic feature working for Linux only

This commit is contained in:
Kengo TODA
2020-08-27 20:39:35 +08:00
parent 74c8587e44
commit 367ba4923b
11 changed files with 4741 additions and 77 deletions

26
src/install.ts Normal file
View 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
}