Skip to content

Commit e409eef

Browse files
committed
Add GetContainerPlatforms a useful reusable workflow to get
list of supported platforms (architectures) as well as corresponding json usable for matrix.
1 parent a1bcff1 commit e409eef

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Get Container Platforms
2+
description: 'Extracts supported platforms from a Docker image manifest'
3+
inputs:
4+
image:
5+
description: 'Image name to inspect'
6+
required: true
7+
outputs:
8+
platforms:
9+
description: 'Comma-separated list of platforms'
10+
value: ${{ steps.set-env.outputs.platforms }}
11+
build-matrix:
12+
description: 'JSON array of platforms'
13+
value: ${{ steps.set-env.outputs.build-matrix }}
14+
15+
runs:
16+
using: 'composite'
17+
steps:
18+
- name: Set dynamic environment
19+
id: set-env
20+
run: |
21+
PLATFORMS="$(docker manifest inspect ${{ inputs.image }} | \
22+
jq -r '.manifests[] | "\(.platform.os)/\(.platform.architecture)\(if .platform.variant != null then "/\(.platform.variant)" else "" end)"' | \
23+
sort -u | grep -v unknown | paste -sd ',')"
24+
BUILD_MATRIX="$(echo ${PLATFORMS} | tr ',' '\n' | jq -R . | jq -s . | tr '\n' ' ')"
25+
echo "platforms=${PLATFORMS}" >> $GITHUB_OUTPUT
26+
echo "build-matrix=${BUILD_MATRIX}" >> $GITHUB_OUTPUT
27+
shell: bash

0 commit comments

Comments
 (0)