From ed49c0cad68dcc870f6e7fb89d66b7eac3e79a1c Mon Sep 17 00:00:00 2001 From: VictoriaBeilstenEdmands Date: Fri, 8 May 2026 15:15:48 +0100 Subject: [PATCH] fix(ci): preserve subscriptions when updating supergraph-config --- action.yaml | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/action.yaml b/action.yaml index 63f42a9..39e6bb5 100644 --- a/action.yaml +++ b/action.yaml @@ -120,24 +120,48 @@ runs: SUB_URL: ${{ inputs.subscription-url }} SUB_PROTO: ${{ inputs.subscription-protocol }} run: | + set -e + + # Ensure subgraphs array exists yq -i '.subgraphs = (.subgraphs // [])' supergraph-config.yaml - yq -i ' - .subgraphs = (.subgraphs | map(select(.name != "'"$NAME"'"))) - ' supergraph-config.yaml - yq -i ' - .subgraphs += [{ - "name": "'"$NAME"'", - "routing_url": "'"$ROUTING_URL"'", - "schema": { "file": "schema/'"$NAME"'.graphql" } - }] - ' supergraph-config.yaml + + # Check if subgraph already exists + if yq e '.subgraphs[].name' supergraph-config.yaml | grep -qx "$NAME"; then + echo "Updating existing subgraph: $NAME" + + # If exists, update schema & routing URL + yq -i ' + (.subgraphs[] | select(.name == "'"$NAME"'")).routing_url = "'"$ROUTING_URL"'" + ' supergraph-config.yaml + + yq -i ' + (.subgraphs[] | select(.name == "'"$NAME"'")).schema.file = "schema/'"$NAME"'.graphql" + ' supergraph-config.yaml + # Add subgraph if it does not already exist + else + echo "Adding new subgraph: $NAME" + + yq -i ' + .subgraphs += [{ + "name": "'"$NAME"'", + "routing_url": "'"$ROUTING_URL"'", + "schema": { "file": "schema/'"$NAME"'.graphql" } + }] + ' supergraph-config.yaml + fi + + # Update subscription-url if provided (optional) if [ -n "$SUB_URL" ]; then + echo "Updating subscription config for $NAME" + yq -i ' - .subgraphs[-1].subscription = { + (.subgraphs[] | select(.name == "'"$NAME"'")).subscription = { "url": "'"$SUB_URL"'", "protocol": "'"$SUB_PROTO"'" } ' supergraph-config.yaml + else + echo "No subscription-url provided; no subscription config updates applied" fi echo "Updated Cosmo config:"