-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support downloading binaries from docker images
Signed-off-by: Paweł Gronowski <[email protected]>
- Loading branch information
Showing
3 changed files
with
179 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,92 @@ | ||
import * as core from '@actions/core'; | ||
import {InstallSource} from '@docker/actions-toolkit/lib/docker/install'; | ||
import { parse } from 'csv-parse'; | ||
|
||
export interface Inputs { | ||
version: string; | ||
channel: string; | ||
source: InstallSource; | ||
daemonConfig?: string; | ||
context: string; | ||
setHost: boolean; | ||
} | ||
|
||
export function getInputs(): Inputs { | ||
const rawVersion = core.getInput('version') || 'latest'; | ||
const source = parseSource(rawVersion); | ||
const channel = core.getInput('channel'); | ||
if (channel && source.type === 'archive') { | ||
source.channel = channel; | ||
} | ||
|
||
return { | ||
version: core.getInput('version') || 'latest', | ||
channel: core.getInput('channel'), | ||
source: source, | ||
daemonConfig: core.getInput('daemon-config'), | ||
context: core.getInput('context'), | ||
setHost: core.getBooleanInput('set-host') | ||
}; | ||
} | ||
|
||
function parseSource(input: string): InstallSource { | ||
let [type, version, channel, tag] = ['archive', input, 'stable', 'latest']; | ||
|
||
const fields = parse(version, { | ||
relaxColumnCount: true, | ||
skipEmptyLines: true | ||
})[0]; | ||
for (const field of fields) { | ||
const parts = field | ||
.toString() | ||
.split(/(?<=^[^=]+?)=/) | ||
.map(item => item.trim()); | ||
|
||
switch (parts[0]) { | ||
case 'type': | ||
type = parts[1]; | ||
break; | ||
case 'version': | ||
version = parts[1]; | ||
break; | ||
case 'channel': | ||
channel = parts[1]; | ||
break; | ||
case 'tag': | ||
tag = parts[1]; | ||
break; | ||
default: | ||
throw new Error(`Invalid field: ${parts[0]}`); | ||
} | ||
} | ||
|
||
if (!type) { | ||
throw new Error(`Invalid type: ${type}`); | ||
} | ||
if (!channel) { | ||
throw new Error(`Invalid channel: ${channel}`); | ||
} | ||
if (!version) { | ||
throw new Error(`Invalid version: ${version}`); | ||
} | ||
if (!tag) { | ||
throw new Error(`Invalid tag: ${tag}`); | ||
} | ||
|
||
let src: InstallSource; | ||
switch (type) { | ||
case 'archive': | ||
src = { | ||
type: 'archive', | ||
version: version, | ||
channel: channel | ||
}; | ||
break; | ||
case 'image': | ||
src = { | ||
type: 'image', | ||
tag: tag | ||
}; | ||
break; | ||
default: | ||
throw new Error(`Invalid version: ${input}`); | ||
} | ||
|
||
return src; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters