Files
actions-setup-docker-compose/src/install.ts
Sergeev Alexander e1d8c7b2f9 fix: version prefix 'v' is missing for docker-compose v2
* System naming for docker-compose >= 2.0 fixed

As you might notice they started naming releases using not capitalized system name starting from `docker-compose` v2.0.0 ([ref](https://github.com/docker/compose/releases/tag/v2.0.0)).
This commit adds version check and fixes system name (returned by `uname -s`).

* Update src/install.ts

Co-authored-by: Kengo TODA <skypencil+github@gmail.com>

* Version

Naming for later versions updated

* Parsing instead of lexicographical order applied

* Update src/install.ts

Co-authored-by: Kengo TODA <skypencil+github@gmail.com>

* Tests for new release naming added

* Integration test for versions  > 2.0.0 added

* Version tag for releases >= 2.0.0 fixed

* Indentation restored

* js files compiled

* auto-appending 'v' added

Co-authored-by: Kengo TODA <skypencil+github@gmail.com>
2022-04-18 11:40:59 +08:00

45 lines
1.3 KiB
TypeScript

import {cacheFile, downloadTool} from '@actions/tool-cache'
import {exec} from '@actions/exec'
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()
}
async function installOnLinux(version: string): Promise<string> {
const system = runCommand('uname -s')
const hardware = runCommand('uname -m')
if (!version.startsWith('v') && parseInt(version.split('.')[0], 10) >= 2) {
version = `v${version}`
}
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}`)
const cachedPath = await cacheFile(
installerPath,
'docker-compose',
'docker-compose',
version
)
return cachedPath
}
export async function install(version: string): Promise<string> {
switch (process.platform) {
case 'linux':
return installOnLinux(version)
default:
throw new Error(`Unsupported platform: ${process.platform}`)
}
}