Skip to content

Commit 2addaab

Browse files
committed
chore: output single matrix for each version
1 parent 7a69907 commit 2addaab

File tree

1 file changed

+51
-40
lines changed

1 file changed

+51
-40
lines changed

.github/workflows/dockerhub-release-matrix.yml

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ jobs:
6161
matrix: ${{ fromJson(needs.prepare.outputs.matrix_config) }}
6262
runs-on: ubuntu-latest
6363
outputs:
64-
versions: ${{ steps.collect-versions.outputs.versions }}
65-
image_tags: ${{ steps.collect-versions.outputs.image_tags }}
64+
matrix: ${{ steps.create-matrix.outputs.matrix }}
65+
build_args: ${{ steps.args.outputs.result }}
6666
steps:
6767
- uses: actions/checkout@v3
6868

@@ -86,57 +86,68 @@ jobs:
8686
with:
8787
cmd: yq 'to_entries | map(select(.value|type == "!!str")) | map(.key + "=" + .value) | join("\n")' 'ansible/vars.yml'
8888

89-
# First collect all versions into a file
90-
- name: Save version info
89+
- id: create-matrix
9190
run: |
92-
mkdir -p /tmp/versions
93-
echo "${{ matrix.version }}" >> /tmp/versions/versions.txt
94-
echo "supabase/postgres:${{ steps.settings.outputs.postgres-version }}" >> /tmp/versions/image_tags.txt
91+
# Create a matrix entry for this version
92+
matrix_entry="{\"version\":\"${{ matrix.version }}\",\"image_tag\":\"supabase/postgres:${{ steps.settings.outputs.postgres-version }}\"}"
93+
echo "matrix={\"include\":[$matrix_entry]}" >> $GITHUB_OUTPUT
9594
96-
# Then at the end of the matrix, collect all versions into arrays
97-
- name: Collect all versions
98-
id: collect-versions
99-
if: ${{ always() }}
95+
collect_versions:
96+
needs: build
97+
runs-on: ubuntu-latest
98+
outputs:
99+
matrix: ${{ steps.create-final-matrix.outputs.matrix }}
100+
steps:
101+
- id: create-final-matrix
100102
run: |
101-
# Create JSON arrays
102-
versions_array="["
103-
first=true
104-
while IFS= read -r version; do
105-
if [ "$first" = true ]; then
106-
first=false
103+
# Combine all matrix configurations from build job
104+
MATRIX="{\"include\":["
105+
FIRST=true
106+
107+
for matrix_config in ${{ toJSON(needs.build.outputs.matrix) }}; do
108+
if [ "$FIRST" = true ]; then
109+
FIRST=false
107110
else
108-
versions_array+=","
111+
MATRIX+=","
109112
fi
110-
versions_array+="\"$version\""
111-
done < <(sort -u /tmp/versions/versions.txt)
112-
versions_array+="]"
113+
# Extract the include array content from each matrix config
114+
include_content=$(echo "$matrix_config" | jq -r '.include[]')
115+
MATRIX+="$include_content"
116+
done
113117
114-
image_tags_array="["
115-
first=true
116-
while IFS= read -r tag; do
117-
if [ "$first" = true ]; then
118-
first=false
118+
# Add architecture combinations for each version
119+
FINAL_MATRIX="{\"include\":["
120+
FIRST=true
121+
122+
echo "$MATRIX]}" | jq -c '.include[]' | while read -r entry; do
123+
version=$(echo "$entry" | jq -r '.version')
124+
image_tag=$(echo "$entry" | jq -r '.image_tag')
125+
126+
# Add amd64 entry
127+
if [ "$FIRST" = true ]; then
128+
FIRST=false
119129
else
120-
image_tags_array+=","
130+
FINAL_MATRIX+=","
121131
fi
122-
image_tags_array+="\"$tag\""
123-
done < <(sort -u /tmp/versions/image_tags.txt)
124-
image_tags_array+="]"
132+
FINAL_MATRIX+="{\"version\":\"$version\",\"image_tag\":\"$image_tag\",\"arch\":\"amd64\",\"runner\":[\"self-hosted\",\"X64\"]}"
133+
134+
# Add arm64 entry
135+
FINAL_MATRIX+=",{\"version\":\"$version\",\"image_tag\":\"$image_tag\",\"arch\":\"arm64\",\"runner\":\"arm-runner\"}"
136+
done
137+
138+
FINAL_MATRIX+="]}"
125139
126-
# Output as properly escaped JSON arrays
127-
echo "versions=$versions_array" >> $GITHUB_OUTPUT
128-
echo "image_tags=$image_tags_array" >> $GITHUB_OUTPUT
140+
# Output the final matrix
141+
echo "matrix=$FINAL_MATRIX" >> $GITHUB_OUTPUT
129142
130143
build_release_image:
131-
needs: build
144+
needs: collect_versions
132145
strategy:
133-
matrix:
134-
version: ${{ fromJson(needs.build.outputs.versions) }}
135-
image_tag: ${{ fromJson(needs.build.outputs.image_tags) }}
136-
arch: [amd64, arm64]
137-
runs-on: ${{ matrix.arch == 'amd64' && fromJson('["self-hosted", "X64"]') || 'arm-runner' }}
146+
matrix: ${{ fromJson(needs.collect_versions.outputs.matrix) }}
147+
runs-on: ${{ matrix.runner }}
138148
timeout-minutes: 180
139149
steps:
150+
- uses: actions/checkout@v3
140151
- run: docker context create builders
141152
- uses: docker/setup-buildx-action@v3
142153
with:
@@ -171,7 +182,7 @@ jobs:
171182
needs: [build, build_release_image]
172183
strategy:
173184
matrix:
174-
image_tag: ${{ fromJson(needs.build.outputs.image_tags) }}
185+
image_tag: ${{ fromJson(needs.collect_versions.outputs.matrix) }}
175186
runs-on: ubuntu-latest
176187
steps:
177188
- uses: docker/setup-buildx-action@v3

0 commit comments

Comments
 (0)