mirror of
https://github.com/docker/build-push-action.git
synced 2025-04-23 03:26:46 +00:00
Output available platforms for setup-qemu
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
674ff6ada6
commit
2f906a9cb7
5 changed files with 69 additions and 2 deletions
34
setup-qemu/src/exec.ts
Normal file
34
setup-qemu/src/exec.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import * as actionsExec from '@actions/exec';
|
||||
import {ExecOptions} from '@actions/exec';
|
||||
|
||||
export interface ExecResult {
|
||||
success: boolean;
|
||||
stdout: string;
|
||||
stderr: string;
|
||||
}
|
||||
|
||||
export const exec = async (command: string, args: string[] = [], silent: boolean): Promise<ExecResult> => {
|
||||
let stdout: string = '';
|
||||
let stderr: string = '';
|
||||
|
||||
const options: ExecOptions = {
|
||||
silent: silent,
|
||||
ignoreReturnCode: true
|
||||
};
|
||||
options.listeners = {
|
||||
stdout: (data: Buffer) => {
|
||||
stdout += data.toString();
|
||||
},
|
||||
stderr: (data: Buffer) => {
|
||||
stderr += data.toString();
|
||||
}
|
||||
};
|
||||
|
||||
const returnCode: number = await actionsExec.exec(command, args, options);
|
||||
|
||||
return {
|
||||
success: returnCode === 0,
|
||||
stdout: stdout.trim(),
|
||||
stderr: stderr.trim()
|
||||
};
|
||||
};
|
|
@ -1,6 +1,11 @@
|
|||
import * as os from 'os';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as exec from './exec';
|
||||
|
||||
interface Platforms {
|
||||
supported: string[];
|
||||
available: string[];
|
||||
}
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
|
@ -13,7 +18,15 @@ async function run(): Promise<void> {
|
|||
const platforms: string = core.getInput('platforms') || 'all';
|
||||
|
||||
core.info(`💎 Installing QEMU static binaries...`);
|
||||
await exec.exec('docker', ['run', '--rm', '--privileged', image, '--install', platforms]);
|
||||
await exec.exec(`docker`, ['run', '--rm', '--privileged', image, '--install', platforms], false).then(res => {
|
||||
if (res.stderr != '' && !res.success) {
|
||||
throw new Error(res.stderr);
|
||||
}
|
||||
|
||||
core.info('🛒 Extracting available platforms...');
|
||||
const platforms: Platforms = JSON.parse(res.stdout.trim());
|
||||
core.setOutput('platforms', platforms.supported.join(','));
|
||||
});
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue