Use context for inputs

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax committed 2022-10-08 18:40:34 +02:00
1 parent 8c1e35a8c6
commit 25725d8d2e
5 files changed
+59 -41

No files matched your search

+1
View File
@@ -13,6 +13,7 @@ ___
* [Usage](#usage) * [Usage](#usage)
* [Customizing](#customizing) * [Customizing](#customizing)
* [inputs](#inputs) * [inputs](#inputs)
* [outputs](#outputs)
* [Contributing](#contributing) * [Contributing](#contributing)
## Usage ## Usage
Generated Vendored
+1 -1
View File
@@ -1,2 +1,2 @@
require('./sourcemap-register.js');(()=>{var e={351:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){if(n===undefined)n=r;Object.defineProperty(e,n,{enumerable:true,get:function(){return t[r]}})}:function(e,t,r,n){if(n===undefined)n=r;e[n]=t[r]});var i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:true,value:t})}:function(e,t){e["default"]=t});var o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)if(r!=="default"&&Object.hasOwnProperty.call(e,r))n(t,e,r);i(t,e);return t};Object.defineProperty(t,"__esModule",{value:true});t.issue=t.issueCommand=void 0;const s=o(r(37));const u=r(278);function issueCommand(e,t,r){const n=new Command(e,t,r);process.stdout.write(n.toString()+s.EOL)}t.issueCommand=issueCommand;function issue(e,t=""){issueCommand(e,{},t)}t.issue=issue;const a="::";class Command{constructor(e,t,r){if(!e){e="missing.command"}this.command=e;this.properties=t;this.message=r}toString(){let e=a+this.command;if(this.properties&&Object.keys(this.properties).length>0){e+=" ";let t=true;for(const r in this.properties){if(this.properties.hasOwnProperty(r)){const n=this.properties[r];if(n){if(t){t=false}else{e+=","}e+=`${r}=${escapeProperty(n)}`}}}}e+=`${a}${escapeData(this.message)}`;return e}}function escapeData(e){return u.toCommandValue(e).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function escapeProperty(e){return u.toCommandValue(e).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A").replace(/:/g,"%3A").replace(/,/g,"%2C")}},186:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){if(n===undefined)n=r;Object.defineProperty(e,n,{enumerable:true,get:function(){return t[r]}})}:function(e,t,r,n){if(n===undefined)n=r;e[n]=t[r]});var i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:true,value:t})}:function(e,t){e["default"]=t});var o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)if(r!=="default"&&Object.hasOwnProperty.call(e,r))n(t,e,r);i(t,e);return t};var s=this&&this.__awaiter||function(e,t,r,n){function adopt(e){return e instanceof r?e:new r((function(t){t(e)}))}return new(r||(r=Promise))((function(r,i){function fulfilled(e){try{step(n.next(e))}catch(e){i(e)}}function rejected(e){try{step(n["throw"](e))}catch(e){i(e)}}function step(e){e.done?r(e.value):adopt(e.value).then(fulfilled,rejected)}step((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:true});t.getIDToken=t.getState=t.saveState=t.group=t.endGroup=t.startGroup=t.info=t.notice=t.warning=t.error=t.debug=t.isDebug=t.setFailed=t.setCommandEcho=t.setOutput=t.getBooleanInput=t.getMultilineInput=t.getInput=t.addPath=t.setSecret=t.exportVariable=t.ExitCode=void 0;const u=r(351);const a=r(717);const c=r(278);const l=o(r(37));const d=o(r(17));const f=r(41);var p;(function(e){e[e["Success"]=0]="Success";e[e["Failure"]=1]="Failure"})(p=t.ExitCode||(t.ExitCode={}));function exportVariable(e,t){const r=c.toCommandValue(t);process.env[e]=r;const n=process.env["GITHUB_ENV"]||"";if(n){return a.issueFileCommand("ENV",a.prepareKeyValueMessage(e,t))}u.issueCommand("set-env",{name:e},r)}t.exportVariable=exportVariable;function setSecret(e){u.issueCommand("add-mask",{},e)}t.setSecret=setSecret;function addPath(e){const t=process.env["GITHUB_PATH"]||"";if(t){a.issueFileCommand("PATH",e)}else{u.issueCommand("add-path",{},e)}process.env["PATH"]=`${e}${d.delimiter}${process.env["PATH"]}`}t.addPath=addPath;function getInput(e,t){const r=process.env[`INPUT_${e.replace(/ /g,"_").toUpperCase()}`]||"";if(t&&t.required&&!r){throw new Error(`Input required and not supplied: ${e}`)}if(t&&t.trimWhitespace===false){return r}return r.trim()}t.getInput=getInput;function getMultilineInput(e,t){const r=getInput(e,t).split("\n").filter((e=>e!==""));if(t&&t.trimWhitespace===false){return r}return r.map((e=>e.trim()))}t.getMultilineInput=getMultilineInput;function getBooleanInput(e,t){const r=["true","True","TRUE"];const n=["false","False","FALSE"];const i=getInput(e,t);if(r.includes(i))return true;if(n.includes(i))return false;throw new TypeError(`Input does not meet YAML 1.2 "Core Schema" specification: ${e}\n`+`Support boolean input list: \`true | True | TRUE | false | False | FALSE\``)}t.getBooleanInput=getBooleanInput;function setOutput(e,t){const r=process.env["GITHUB_OUTPUT"]||"";if(r){return a.issueFileCommand("OUTPUT",a.prepareKeyValueMessage(e,t))}process.stdout.write(l.EOL);u.issueCommand("set-output",{name:e},c.toCommandValue(t))}t.setOutput=setOutput;function setCommandEcho(e){u.issue("echo",e?"on":"off")}t.setCommandEcho=setCommandEcho;function setFailed(e){process.exitCode=p.Failure;error(e)}t.setFailed=setFailed;function isDebug(){return process.env["RUNNER_DEBUG"]==="1"}t.isDebug=isDebug;function debug(e){uLine truncated require('./sourcemap-register.js');(()=>{var e={351:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){if(n===undefined)n=r;Object.defineProperty(e,n,{enumerable:true,get:function(){return t[r]}})}:function(e,t,r,n){if(n===undefined)n=r;e[n]=t[r]});var i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:true,value:t})}:function(e,t){e["default"]=t});var o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)if(r!=="default"&&Object.hasOwnProperty.call(e,r))n(t,e,r);i(t,e);return t};Object.defineProperty(t,"__esModule",{value:true});t.issue=t.issueCommand=void 0;const s=o(r(37));const u=r(278);function issueCommand(e,t,r){const n=new Command(e,t,r);process.stdout.write(n.toString()+s.EOL)}t.issueCommand=issueCommand;function issue(e,t=""){issueCommand(e,{},t)}t.issue=issue;const a="::";class Command{constructor(e,t,r){if(!e){e="missing.command"}this.command=e;this.properties=t;this.message=r}toString(){let e=a+this.command;if(this.properties&&Object.keys(this.properties).length>0){e+=" ";let t=true;for(const r in this.properties){if(this.properties.hasOwnProperty(r)){const n=this.properties[r];if(n){if(t){t=false}else{e+=","}e+=`${r}=${escapeProperty(n)}`}}}}e+=`${a}${escapeData(this.message)}`;return e}}function escapeData(e){return u.toCommandValue(e).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function escapeProperty(e){return u.toCommandValue(e).replace(/%/g,"%25").replace(/\r/g,"%0D").replace(/\n/g,"%0A").replace(/:/g,"%3A").replace(/,/g,"%2C")}},186:function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){if(n===undefined)n=r;Object.defineProperty(e,n,{enumerable:true,get:function(){return t[r]}})}:function(e,t,r,n){if(n===undefined)n=r;e[n]=t[r]});var i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:true,value:t})}:function(e,t){e["default"]=t});var o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)if(r!=="default"&&Object.hasOwnProperty.call(e,r))n(t,e,r);i(t,e);return t};var s=this&&this.__awaiter||function(e,t,r,n){function adopt(e){return e instanceof r?e:new r((function(t){t(e)}))}return new(r||(r=Promise))((function(r,i){function fulfilled(e){try{step(n.next(e))}catch(e){i(e)}}function rejected(e){try{step(n["throw"](e))}catch(e){i(e)}}function step(e){e.done?r(e.value):adopt(e.value).then(fulfilled,rejected)}step((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:true});t.getIDToken=t.getState=t.saveState=t.group=t.endGroup=t.startGroup=t.info=t.notice=t.warning=t.error=t.debug=t.isDebug=t.setFailed=t.setCommandEcho=t.setOutput=t.getBooleanInput=t.getMultilineInput=t.getInput=t.addPath=t.setSecret=t.exportVariable=t.ExitCode=void 0;const u=r(351);const a=r(717);const c=r(278);const l=o(r(37));const d=o(r(17));const f=r(41);var p;(function(e){e[e["Success"]=0]="Success";e[e["Failure"]=1]="Failure"})(p=t.ExitCode||(t.ExitCode={}));function exportVariable(e,t){const r=c.toCommandValue(t);process.env[e]=r;const n=process.env["GITHUB_ENV"]||"";if(n){return a.issueFileCommand("ENV",a.prepareKeyValueMessage(e,t))}u.issueCommand("set-env",{name:e},r)}t.exportVariable=exportVariable;function setSecret(e){u.issueCommand("add-mask",{},e)}t.setSecret=setSecret;function addPath(e){const t=process.env["GITHUB_PATH"]||"";if(t){a.issueFileCommand("PATH",e)}else{u.issueCommand("add-path",{},e)}process.env["PATH"]=`${e}${d.delimiter}${process.env["PATH"]}`}t.addPath=addPath;function getInput(e,t){const r=process.env[`INPUT_${e.replace(/ /g,"_").toUpperCase()}`]||"";if(t&&t.required&&!r){throw new Error(`Input required and not supplied: ${e}`)}if(t&&t.trimWhitespace===false){return r}return r.trim()}t.getInput=getInput;function getMultilineInput(e,t){const r=getInput(e,t).split("\n").filter((e=>e!==""));if(t&&t.trimWhitespace===false){return r}return r.map((e=>e.trim()))}t.getMultilineInput=getMultilineInput;function getBooleanInput(e,t){const r=["true","True","TRUE"];const n=["false","False","FALSE"];const i=getInput(e,t);if(r.includes(i))return true;if(n.includes(i))return false;throw new TypeError(`Input does not meet YAML 1.2 "Core Schema" specification: ${e}\n`+`Support boolean input list: \`true | True | TRUE | false | False | FALSE\``)}t.getBooleanInput=getBooleanInput;function setOutput(e,t){const r=process.env["GITHUB_OUTPUT"]||"";if(r){return a.issueFileCommand("OUTPUT",a.prepareKeyValueMessage(e,t))}process.stdout.write(l.EOL);u.issueCommand("set-output",{name:e},c.toCommandValue(t))}t.setOutput=setOutput;function setCommandEcho(e){u.issue("echo",e?"on":"off")}t.setCommandEcho=setCommandEcho;function setFailed(e){process.exitCode=p.Failure;error(e)}t.setFailed=setFailed;function isDebug(){return process.env["RUNNER_DEBUG"]==="1"}t.isDebug=isDebug;function debug(e){uLine truncated
//# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map
Generated Vendored
+1 -1
View File
@@ -1 +1 @@
{"version":3,"sources":["../webpack:/docker-setup-qemu/node_modules/@actions/core/lib/command.js","../webpack:/docker-setup-qemu/node_modules/@actions/core/lib/core.js","../webpack:/docker-setup-qemu/node_modules/@actions/core/lib/file-command.js","../webpack:/docker-setup-qemu/node_modules/@actions/core/lib/oidc-utils.js","../webpack:/docker-setup-qemu/node_modules/@actions/core/lib/path-utils.js","../webpack:/docker-setup-qemu/node_modules/@actions/core/lib/summary.js","../webpack:/docker-setup-qemu/node_modules/@actions/core/lib/utils.js","../webpack:/docker-setup-qemu/node_modules/@actions/exec/lib/exec.js","../webpack:/docker-setup-qemu/node_modules/@actions/exec/lib/toolrunner.js","../webpack:/docker-setup-qemu/node_modules/@actions/http-client/lib/auth.js","../webpack:/docker-setup-qemu/node_modules/@actions/http-client/lib/index.js","../webpack:/docker-setup-qemu/node_modules/@actions/http-client/lib/proxy.js","../webpack:/docker-setup-qemu/node_modules/@actions/io/lib/io-util.js","../webpack:/docker-setup-qemu/node_modules/@actions/io/lib/io.js","../webpack:/docker-setup-qemu/node_modules/tunnel/index.js","../webpack:/docker-setup-qemu/node_modules/tunnel/lib/tunnel.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/index.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/md5.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/nil.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/parse.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/regex.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/rng.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/sha1.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/stringify.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/v1.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/v3.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/v35.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/v4.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/v5.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/validate.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/version.js","../webpack:/docker-setup-qemu/src/main.ts","../webpack:/docker-setup-qemu/external node-commonjs \"assert\"","../webpack:/docker-setup-qemu/external node-commonjs \"child_process\"","../webpack:/docker-setup-qemu/external node-commonjs \"crypto\"","../webpack:/docker-setup-qemu/external node-commonjs \"events\"","../webpack:/docker-setup-qemu/external node-commonjs \"fs\"","../webpack:/docker-setup-qemu/external node-commonjs \"http\"","../webpack:/docker-setup-qemu/external node-commonjs \"https\"","../webpack:/docker-setup-qemu/external node-commonjs \"net\"","../webpack:/docker-setup-qemu/external node-commonjs \"os\"","../webpack:/docker-setup-qemu/external node-commonjs \"path\"","../webpack:/docker-setup-qemu/external node-commonjs \"string_decoder\"","../webpack:/docker-setup-qemu/external node-commonjs \"timers\"","../webpack:/docker-setup-qemu/external node-commonjs \"tls\"","../webpack:/docker-setup-qemu/external node-commonjs \"util\"","../webpack:/docker-setup-qemu/webpack/bootstrap","../webpack:/docker-setup-qemu/webpack/runtime/compat","../webpack:/docker-setup-qemu/webpack/startup"],"names":["__createBinding","this","Object","create","o","m","k","k2","undefined","defineProperty","enumerable","get","__setModuleDefault","v","value","__importStar","mod","__esModule","result","hasOwnProperty","call","exports","issue","issueCommand","os","__webpack_require__","utils_1","command","properties","message","cmd","Command","process","stdout","write","toString","EOL","name","CMD_STRING","constructor","cmdStr","keys","length","first","key","val","escapeProperty","escapeData","s","toCommandValue","replace","__awaiter","thisArg","_arguments","P","generator","adopt","resolve","Promise","reject","fulfilled","step","next","e","rejected","done","then","apply","getIDToken","getState","saveState","group","endGroup","startGroup","info","notice","warning","error","debug","isDebug","setFailed","setCommandEcho","setOutput","getBooleanInput","getMultilineInput","getInput","addPath","setSecret","exportVariable","ExitCode","command_1","file_command_1","path","oidc_utils_1","convertedVal","env","filePath","issueFileCommand","prepareKeyValueMessage","secret","inputPath","delimiter","options","toUpperCase","required","Error","trimWhitespace","trim","inputs","split","filter","x","map","input","trueValue","falseValue","includes","TypeError","enabled","exitCode","Failure","toCommandProperties","fn","aud","OidcClient","summary_1","summary","summary_2","markdownSummary","path_utils_1","toPosixPath","toWin32Path","toPlatformPath","fs","uuid_1","existsSync","appendFileSync","encoding","v4","convertedValue","http_client_1","auth_1","core_1","static","allowRetry","maxRetry","requestOptions","allowRetries","maxRetries","HttpClient","BearerCredentialHandler","getRequestToken","token","runtimeUrl","id_token_url","_a","httpclientLine truncated {"version":3,"sources":["../webpack:/docker-setup-qemu/node_modules/@actions/core/lib/command.js","../webpack:/docker-setup-qemu/node_modules/@actions/core/lib/core.js","../webpack:/docker-setup-qemu/node_modules/@actions/core/lib/file-command.js","../webpack:/docker-setup-qemu/node_modules/@actions/core/lib/oidc-utils.js","../webpack:/docker-setup-qemu/node_modules/@actions/core/lib/path-utils.js","../webpack:/docker-setup-qemu/node_modules/@actions/core/lib/summary.js","../webpack:/docker-setup-qemu/node_modules/@actions/core/lib/utils.js","../webpack:/docker-setup-qemu/node_modules/@actions/exec/lib/exec.js","../webpack:/docker-setup-qemu/node_modules/@actions/exec/lib/toolrunner.js","../webpack:/docker-setup-qemu/node_modules/@actions/http-client/lib/auth.js","../webpack:/docker-setup-qemu/node_modules/@actions/http-client/lib/index.js","../webpack:/docker-setup-qemu/node_modules/@actions/http-client/lib/proxy.js","../webpack:/docker-setup-qemu/node_modules/@actions/io/lib/io-util.js","../webpack:/docker-setup-qemu/node_modules/@actions/io/lib/io.js","../webpack:/docker-setup-qemu/node_modules/tunnel/index.js","../webpack:/docker-setup-qemu/node_modules/tunnel/lib/tunnel.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/index.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/md5.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/nil.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/parse.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/regex.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/rng.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/sha1.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/stringify.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/v1.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/v3.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/v35.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/v4.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/v5.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/validate.js","../webpack:/docker-setup-qemu/node_modules/uuid/dist/version.js","../webpack:/docker-setup-qemu/src/context.ts","../webpack:/docker-setup-qemu/src/main.ts","../webpack:/docker-setup-qemu/external node-commonjs \"assert\"","../webpack:/docker-setup-qemu/external node-commonjs \"child_process\"","../webpack:/docker-setup-qemu/external node-commonjs \"crypto\"","../webpack:/docker-setup-qemu/external node-commonjs \"events\"","../webpack:/docker-setup-qemu/external node-commonjs \"fs\"","../webpack:/docker-setup-qemu/external node-commonjs \"http\"","../webpack:/docker-setup-qemu/external node-commonjs \"https\"","../webpack:/docker-setup-qemu/external node-commonjs \"net\"","../webpack:/docker-setup-qemu/external node-commonjs \"os\"","../webpack:/docker-setup-qemu/external node-commonjs \"path\"","../webpack:/docker-setup-qemu/external node-commonjs \"string_decoder\"","../webpack:/docker-setup-qemu/external node-commonjs \"timers\"","../webpack:/docker-setup-qemu/external node-commonjs \"tls\"","../webpack:/docker-setup-qemu/external node-commonjs \"util\"","../webpack:/docker-setup-qemu/webpack/bootstrap","../webpack:/docker-setup-qemu/webpack/runtime/compat","../webpack:/docker-setup-qemu/webpack/startup"],"names":["__createBinding","this","Object","create","o","m","k","k2","undefined","defineProperty","enumerable","get","__setModuleDefault","v","value","__importStar","mod","__esModule","result","hasOwnProperty","call","exports","issue","issueCommand","os","__webpack_require__","utils_1","command","properties","message","cmd","Command","process","stdout","write","toString","EOL","name","CMD_STRING","constructor","cmdStr","keys","length","first","key","val","escapeProperty","escapeData","s","toCommandValue","replace","__awaiter","thisArg","_arguments","P","generator","adopt","resolve","Promise","reject","fulfilled","step","next","e","rejected","done","then","apply","getIDToken","getState","saveState","group","endGroup","startGroup","info","notice","warning","error","debug","isDebug","setFailed","setCommandEcho","setOutput","getBooleanInput","getMultilineInput","getInput","addPath","setSecret","exportVariable","ExitCode","command_1","file_command_1","path","oidc_utils_1","convertedVal","env","filePath","issueFileCommand","prepareKeyValueMessage","secret","inputPath","delimiter","options","toUpperCase","required","Error","trimWhitespace","trim","inputs","split","filter","x","map","input","trueValue","falseValue","includes","TypeError","enabled","exitCode","Failure","toCommandProperties","fn","aud","OidcClient","summary_1","summary","summary_2","markdownSummary","path_utils_1","toPosixPath","toWin32Path","toPlatformPath","fs","uuid_1","existsSync","appendFileSync","encoding","v4","convertedValue","http_client_1","auth_1","core_1","static","allowRetry","maxRetry","requestOptions","allowRetries","maxRetries","HttpClient","BearerCredentialHandler","getRequestToken","tokeLine truncated
+19
View File
@@ -0,0 +1,19 @@
import * as core from '@actions/core';
import {issueCommand} from '@actions/core/lib/command';
export interface Inputs {
image: string;
platforms: string;
}
export function getInputs(): Inputs {
return {
image: core.getInput('image') || 'tonistiigi/binfmt:latest',
platforms: core.getInput('platforms') || 'all'
};
}
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
export function setOutput(name: string, value: unknown): void {
issueCommand('set-output', {name}, value);
}
+37 -39
View File
@@ -1,6 +1,6 @@
import * as context from './context';
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
import {issueCommand} from '@actions/core/lib/command';
interface Platforms { interface Platforms {
supported: string[]; supported: string[];
@@ -9,49 +9,47 @@ interface Platforms {
async function run(): Promise<void> { async function run(): Promise<void> {
try { try {
core.startGroup(`Docker info`); const input: context.Inputs = context.getInputs();
await exec.exec('docker', ['version']);
await exec.exec('docker', ['info']);
core.endGroup();
const image: string = core.getInput('image') || 'tonistiigi/binfmt:latest'; await core.group(`Docker info`, async () => {
const platforms: string = core.getInput('platforms') || 'all'; await exec.exec('docker', ['version'], {
failOnStdErr: false
core.startGroup(`Pulling binfmt Docker image`);
await exec.exec('docker', ['pull', image]);
core.endGroup();
core.startGroup(`Image info`);
await exec.exec('docker', ['image', 'inspect', image]);
core.endGroup();
core.startGroup(`Installing QEMU static binaries`);
await exec.exec('docker', ['run', '--rm', '--privileged', image, '--install', platforms]);
core.endGroup();
core.startGroup(`Extracting available platforms`);
await exec
.getExecOutput('docker', ['run', '--rm', '--privileged', image], {
ignoreReturnCode: true,
silent: true
})
.then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr.trim());
}
const platforms: Platforms = JSON.parse(res.stdout.trim());
core.info(`${platforms.supported.join(',')}`);
setOutput('platforms', platforms.supported.join(','));
}); });
core.endGroup(); await exec.exec('docker', ['info'], {
failOnStdErr: false
});
});
await core.group(`Pulling binfmt Docker image`, async () => {
await exec.exec('docker', ['pull', input.image]);
});
await core.group(`Image info`, async () => {
await exec.exec('docker', ['image', 'inspect', input.image]);
});
await core.group(`Installing QEMU static binaries`, async () => {
await exec.exec('docker', ['run', '--rm', '--privileged', input.image, '--install', input.platforms]);
});
await core.group(`Extracting available platforms`, async () => {
await exec
.getExecOutput('docker', ['run', '--rm', '--privileged', input.image], {
ignoreReturnCode: true,
silent: true
})
.then(res => {
if (res.stderr.length > 0 && res.exitCode != 0) {
throw new Error(res.stderr.trim());
}
const platforms: Platforms = JSON.parse(res.stdout.trim());
core.info(`${platforms.supported.join(',')}`);
context.setOutput('platforms', platforms.supported.join(','));
});
});
} catch (error) { } catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
} }
} }
// FIXME: Temp fix https://github.com/actions/toolkit/issues/777
function setOutput(name: string, value: unknown): void {
issueCommand('set-output', {name}, value);
}
run(); run();