6161 matrix : ${{ fromJson(needs.prepare.outputs.matrix_config) }}
6262 runs-on : ubuntu-latest
6363 outputs :
64- matrix : ${{ steps.create-matrix.outputs.matrix }}
64+ versions : ${{ steps.output-versions.outputs.versions }}
65+ image_tags : ${{ steps.output-versions.outputs.image_tags }}
6566 build_args : ${{ steps.args.outputs.result }}
6667 steps :
6768 - uses : actions/checkout@v3
@@ -86,65 +87,34 @@ jobs:
8687 with :
8788 cmd : yq 'to_entries | map(select(.value|type == "!!str")) | map(.key + "=" + .value) | join("\n")' 'ansible/vars.yml'
8889
89- - id : create-matrix
90+ - id : output-versions
91+ if : always()
9092 run : |
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
94-
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
102- run : |
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
110- else
111- MATRIX+=","
112- fi
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
117-
118- # Add architecture combinations for each version
119- FINAL_MATRIX="{\"include\":["
120- FIRST=true
93+ # Create output files if they don't exist
94+ mkdir -p /tmp/versions
95+ touch /tmp/versions/all_versions.txt
96+ touch /tmp/versions/all_tags.txt
12197
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
129- else
130- FINAL_MATRIX+=","
131- fi
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
98+ # Append current version and tag
99+ echo "${{ matrix.version }}" >> /tmp/versions/all_versions.txt
100+ echo "supabase/postgres:${{ steps.settings.outputs.postgres-version }}" >> /tmp/versions/all_tags.txt
137101
138- FINAL_MATRIX+="]}"
102+ # Convert to JSON arrays with unique values
103+ VERSIONS=$(sort -u /tmp/versions/all_versions.txt | jq -R . | jq -s .)
104+ TAGS=$(sort -u /tmp/versions/all_tags.txt | jq -R . | jq -s .)
139105
140- # Output the final matrix
141- echo "matrix=$FINAL_MATRIX" >> $GITHUB_OUTPUT
106+ # Set outputs
107+ echo "versions=$VERSIONS" >> $GITHUB_OUTPUT
108+ echo "image_tags=$TAGS" >> $GITHUB_OUTPUT
142109
143110 build_release_image :
144- needs : collect_versions
111+ needs : build
145112 strategy :
146- matrix : ${{ fromJson(needs.collect_versions.outputs.matrix) }}
147- runs-on : ${{ matrix.runner }}
113+ matrix :
114+ version : ${{ fromJson(needs.build.outputs.versions) }}
115+ image_tag : ${{ fromJson(needs.build.outputs.image_tags) }}
116+ arch : [amd64, arm64]
117+ runs-on : ${{ matrix.arch == 'amd64' && fromJson('["self-hosted", "X64"]') || 'arm-runner' }}
148118 timeout-minutes : 180
149119 steps :
150120 - uses : actions/checkout@v3
@@ -182,7 +152,7 @@ jobs:
182152 needs : [build, build_release_image]
183153 strategy :
184154 matrix :
185- image_tag : ${{ fromJson(needs.collect_versions .outputs.matrix ) }}
155+ image_tag : ${{ fromJson(needs.build .outputs.image_tags ) }}
186156 runs-on : ubuntu-latest
187157 steps :
188158 - uses : docker/setup-buildx-action@v3
0 commit comments