-
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.
Merge pull request #106 from vvoland/binimg
support downloading binaries from docker images
- Loading branch information
Showing
6 changed files
with
186 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ jobs: | |
version: | ||
- pinned | ||
- latest | ||
- type=image,tag=27.3.1 | ||
steps: | ||
- | ||
name: Checkout | ||
|
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,96 @@ | ||
import * as core from '@actions/core'; | ||
import {InstallSource} from '@docker/actions-toolkit/lib/docker/install'; | ||
import {parse} from 'csv-parse/sync'; | ||
|
||
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', 'latest', 'stable', 'latest']; | ||
|
||
const fields = parse(input, { | ||
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: | ||
if (fields.length === 1) { | ||
version = parts[0]; | ||
break; | ||
} | ||
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