From 9b9ab56bcc2c7c75c4c25eff883c6a3cb7ae37ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Fr=C3=A9con?= Date: Fri, 9 Feb 2024 19:38:35 +0100 Subject: [PATCH] Make platforms an input --- .github/workflows/_build.yml | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/.github/workflows/_build.yml b/.github/workflows/_build.yml index e5fa463..be6862d 100644 --- a/.github/workflows/_build.yml +++ b/.github/workflows/_build.yml @@ -22,6 +22,11 @@ on: required: false type: string default: 'ubuntu-latest' + platforms: + description: 'Platforms to build for, comma separated list of arch/os pairs' + required: false + type: string + default: 'linux/amd64,linux/arm64' secrets: username: description: 'username at registry' @@ -34,20 +39,33 @@ env: REGISTRY_IMAGE: ${{ inputs.image }} jobs: + convert: + runs-on: ${{ inputs.runs-on }} + outputs: + platforms: ${{ steps.convert.outputs.platforms }} + steps: + - + name: Convert Platforms + id: convert + run: | + platforms=${{ inputs.platforms }} + inside=$(printf %s\\n "$platforms" | sed -E -e 's/,/\", \"/g' -e 's/\" +/\"/g' -e 's/ +\"/\"/g') + printf 'platforms=["%s"]' "$inside" >> $GITHUB_OUTPUT + build: runs-on: ${{ inputs.runs-on }} + needs: + - convert strategy: fail-fast: false matrix: - platform: - - linux/amd64 - - linux/arm64 + platform: ${{ needs.convert.outputs.platforms }} steps: - name: Prepare id: platform run: | - platform=${{ matrix.platform }} + platform=${{ needs.convert.outputs.platforms }} echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV - name: Checkout @@ -77,7 +95,7 @@ jobs: uses: docker/build-push-action@v5 with: context: . - platforms: ${{ matrix.platform }} + platforms: ${{ needs.convert.outputs.platforms }} labels: ${{ steps.meta.outputs.labels }} outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true file: ${{ inputs.file }}