From 2ddad4401e17fa807e8a3c4bd289ccdd993f0868 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Wed, 27 May 2026 17:01:22 +0200 Subject: [PATCH] uninstall current emulators Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- .github/workflows/ci.yml | 20 ++++++++++++++++++++ README.md | 1 + __tests__/context.test.ts | 6 ++++++ action.yml | 4 ++++ src/context.ts | 2 ++ src/main.ts | 12 ++++++++++++ 6 files changed, 45 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cdde4bd..46c043a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -125,3 +125,23 @@ jobs: uses: ./ with: image: ${{ matrix.image }} + + reset: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - + name: Install multiarch/qemu-user-static + run: | + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes -c yes + - + name: Set up QEMU + id: qemu + uses: ./ + with: + reset: true + - + name: Available platforms + run: echo ${{ steps.qemu.outputs.platforms }} diff --git a/README.md b/README.md index 07613b5..4c7d47e 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ The following inputs can be used as `step.with` keys: |---------------|--------|-------------------------------------------------------------------------------|----------------------------------------------------| | `image` | String | [`tonistiigi/binfmt:latest`](https://hub.docker.com/r/tonistiigi/binfmt/tags) | QEMU static binaries Docker image | | `platforms` | String | `all` | Platforms to install (e.g., `arm64,riscv64,arm`) | +| `reset` | Bool | `false` | Uninstall current emulators before installation | | `cache-image` | Bool | `true` | Cache binfmt image to GitHub Actions cache backend | ### outputs diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index b00addf..994aefe 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -17,11 +17,13 @@ describe('getInputs', () => { [ 0, new Map([ + ['reset', 'false'], ['cache-image', 'true'], ]), { image: 'docker.io/tonistiigi/binfmt:latest', platforms: 'all', + reset: false, cacheImage: true, } ], @@ -30,11 +32,13 @@ describe('getInputs', () => { new Map([ ['image', 'docker/binfmt:latest'], ['platforms', 'arm64,riscv64,arm'], + ['reset', 'false'], ['cache-image', 'false'], ]), { image: 'docker/binfmt:latest', platforms: 'arm64,riscv64,arm', + reset: false, cacheImage: false, } ], @@ -42,11 +46,13 @@ describe('getInputs', () => { 2, new Map([ ['platforms', 'arm64, riscv64, arm '], + ['reset', 'false'], ['cache-image', 'true'], ]), { image: 'docker.io/tonistiigi/binfmt:latest', platforms: 'arm64,riscv64,arm', + reset: false, cacheImage: true, } ] diff --git a/action.yml b/action.yml index 137a741..c338686 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,10 @@ inputs: description: 'Platforms to install (e.g. arm64,riscv64,arm)' default: 'all' required: false + reset: + description: 'Uninstall current emulators before installation' + default: 'false' + required: false cache-image: description: 'Cache binfmt image to GitHub Actions cache backend' default: 'true' diff --git a/src/context.ts b/src/context.ts index 45a56e2..97e5178 100644 --- a/src/context.ts +++ b/src/context.ts @@ -4,6 +4,7 @@ import {Util} from '@docker/actions-toolkit/lib/util.js'; export interface Inputs { image: string; platforms: string; + reset: boolean; cacheImage: boolean; } @@ -11,6 +12,7 @@ export function getInputs(): Inputs { return { image: core.getInput('image') || 'docker.io/tonistiigi/binfmt:latest', platforms: Util.getInputList('platforms').join(',') || 'all', + reset: core.getBooleanInput('reset'), cacheImage: core.getBooleanInput('cache-image') }; } diff --git a/src/main.ts b/src/main.ts index 5802fb9..bac0626 100644 --- a/src/main.ts +++ b/src/main.ts @@ -44,6 +44,18 @@ actionsToolkit.run( }); }); + if (input.reset) { + await core.group(`Uninstalling current emulators`, async () => { + await Docker.getExecOutput(['run', '--rm', '--privileged', input.image, '--uninstall', 'qemu-*'], { + ignoreReturnCode: true + }).then(res => { + if (res.stderr.length > 0 && res.exitCode != 0) { + throw new Error(res.stderr.match(/(.*)\s*$/)?.[0]?.trim() ?? 'unknown error'); + } + }); + }); + } + await core.group(`Installing QEMU static binaries`, async () => { await Docker.getExecOutput(['run', '--rm', '--privileged', input.image, '--install', input.platforms], { ignoreReturnCode: true