From 2f906a9cb78098c8a1f24710d006103e33c7f8af Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 12 Aug 2020 01:48:35 +0200 Subject: [PATCH] Output available platforms for setup-qemu Signed-off-by: CrazyMax --- .github/workflows/setup-qemu-ci.yml | 4 ++++ setup-qemu/README.md | 12 ++++++++++ setup-qemu/action.yml | 4 ++++ setup-qemu/src/exec.ts | 34 +++++++++++++++++++++++++++++ setup-qemu/src/main.ts | 17 +++++++++++++-- 5 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 setup-qemu/src/exec.ts diff --git a/.github/workflows/setup-qemu-ci.yml b/.github/workflows/setup-qemu-ci.yml index 17cbc8e..2f8d9c1 100644 --- a/.github/workflows/setup-qemu-ci.yml +++ b/.github/workflows/setup-qemu-ci.yml @@ -38,7 +38,11 @@ jobs: uses: actions/checkout@v2.3.1 - name: Set up QEMU + id: qemu uses: ./setup-qemu/ with: image: ${{ matrix.image }} platforms: ${{ matrix.platforms }} + - + name: Available platforms + run: echo ${{ steps.qemu.outputs.platforms }} diff --git a/setup-qemu/README.md b/setup-qemu/README.md index a4dac83..c2addea 100644 --- a/setup-qemu/README.md +++ b/setup-qemu/README.md @@ -30,10 +30,14 @@ jobs: uses: actions/checkout@v2 - name: Set up QEMU + id: qemu uses: docker/actions/setup-qemu@v1 with: image: tonistiigi/binfmt:latest platforms: all + - + name: Available platforms + run: echo ${{ steps.qemu.outputs.platforms }} ``` ## Customizing @@ -47,6 +51,14 @@ Following inputs can be used as `step.with` keys | `image` | String | `tonistiigi/binfmt:latest` | QEMU static binaries Docker image. Example: [`tonistiigi/binfmt:latest`](https://hub.docker.com/r/tonistiigi/binfmt/tags) | | `platforms` | String | `all` | Platforms to install. Example: `arm64,riscv64,arm` | +### outputs + +Following outputs are available + +| Name | Type | Description | +|---------------|---------|---------------------------------------| +| `platforms` | String | Available platforms (comma separated) | + ## Limitation This action is only available for Linux [virtual environments](https://help.github.com/en/articles/virtual-environments-for-github-actions#supported-virtual-environments-and-hardware-resources). diff --git a/setup-qemu/action.yml b/setup-qemu/action.yml index d75993a..ab728b0 100644 --- a/setup-qemu/action.yml +++ b/setup-qemu/action.yml @@ -16,6 +16,10 @@ inputs: default: 'all' required: false +outputs: + platforms: + description: 'Available platforms (comma separated)' + runs: using: 'node12' main: 'dist/index.js' diff --git a/setup-qemu/src/exec.ts b/setup-qemu/src/exec.ts new file mode 100644 index 0000000..9ae09ca --- /dev/null +++ b/setup-qemu/src/exec.ts @@ -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 => { + 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() + }; +}; diff --git a/setup-qemu/src/main.ts b/setup-qemu/src/main.ts index 7ffbc19..739944d 100644 --- a/setup-qemu/src/main.ts +++ b/setup-qemu/src/main.ts @@ -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 { try { @@ -13,7 +18,15 @@ async function run(): Promise { 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); }