Skip to content

Commit

Permalink
chore: refactor matrix handling
Browse files Browse the repository at this point in the history
  • Loading branch information
samrose committed Dec 16, 2024
1 parent 33f8ae3 commit ec1b4ac
Showing 1 changed file with 45 additions and 35 deletions.
80 changes: 45 additions & 35 deletions .github/workflows/dockerhub-release-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ jobs:
matrix: ${{ fromJson(needs.prepare.outputs.matrix_config) }}
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.output-versions.outputs.versions }}
image_tags: ${{ steps.output-versions.outputs.image_tags }}
versions: ${{ steps.combine-outputs.outputs.versions }}
image_tags: ${{ steps.combine-outputs.outputs.image_tags }}
build_args: ${{ steps.args.outputs.result }}
steps:
- uses: actions/checkout@v3
Expand All @@ -87,48 +87,58 @@ jobs:
with:
cmd: yq 'to_entries | map(select(.value|type == "!!str")) | map(.key + "=" + .value) | join("\n")' 'ansible/vars.yml'

- id: output-versions
if: always()
# Create workflow artifact with this matrix run's version info
- name: Save version info
run: |
# Create output files if they don't exist
mkdir -p /tmp/versions
touch /tmp/versions/all_versions.txt
touch /tmp/versions/all_tags.txt
# Append current version and tag
echo "${{ matrix.version }}" >> /tmp/versions/all_versions.txt
echo "supabase/postgres:${{ steps.settings.outputs.postgres-version }}" >> /tmp/versions/all_tags.txt
# Create JSON arrays with manual string construction
mkdir -p ./versions
echo "${{ matrix.version }}" > ./versions/version.txt
echo "supabase/postgres:${{ steps.settings.outputs.postgres-version }}" > ./versions/tag.txt
- uses: actions/upload-artifact@v3
with:
name: version-info-${{ matrix.version }}
path: ./versions/

# Only run in first matrix job to combine all outputs
- if: matrix.version == fromJson(needs.prepare.outputs.matrix_config).include[0].version
id: combine-outputs
run: |
# Wait for other matrix jobs to complete by sleeping briefly
sleep 15
# Create arrays to hold all versions and tags
versions_array="["
first=true
while IFS= read -r version; do
if [ "$first" = true ]; then
first=false
else
versions_array+=","
fi
versions_array+="\"$version\""
done < <(sort -u /tmp/versions/all_versions.txt)
versions_array+="]"
tags_array="["
first=true
while IFS= read -r tag; do
# For each version in the matrix config
for row in $(echo '${{ needs.prepare.outputs.matrix_config }}' | jq -c '.include[]'); do
version=$(echo $row | jq -r '.version')
if [ "$first" = true ]; then
first=false
else
versions_array+=","
tags_array+=","
fi
# Download and read artifacts
mkdir -p ./download
echo "Processing version $version"
tag=$(cat ../version-info-${version}/tag.txt)
versions_array+="\"$version\""
tags_array+="\"$tag\""
done < <(sort -u /tmp/versions/all_tags.txt)
done
versions_array+="]"
tags_array+="]"
# Set outputs with proper delimiter
{
echo "versions=${versions_array}"
echo "image_tags=${tags_array}"
} >> $GITHUB_OUTPUT
# Set outputs
echo "versions=$versions_array" >> $GITHUB_OUTPUT
echo "image_tags=$tags_array" >> $GITHUB_OUTPUT
build_release_image:
needs: build
strategy:
Expand Down Expand Up @@ -197,12 +207,12 @@ jobs:
SLACK_MESSAGE: "Building Postgres image failed for version ${{ matrix.version }}"
SLACK_FOOTER: ""

publish:
publish:
needs: [build, merge_manifest]
strategy:
matrix:
version: ${{ fromJson(needs.build.outputs.versions) }}
uses: ./.github/workflows/mirror.yml
with:
version: ${{ matrix.version }}
secrets: inherit
secrets: inherit

0 comments on commit ec1b4ac

Please sign in to comment.