From c7779f9f6d7b2c09028660ec12dd40f4e60db325 Mon Sep 17 00:00:00 2001 From: louisloechel <57091589+louisloechel@users.noreply.github.com> Date: Mon, 30 Oct 2023 10:43:27 +0100 Subject: [PATCH] Add category extraction job --- ...geo_extraction.yml => tilt_extraction.yml} | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) rename .github/workflows/{tilt_geo_extraction.yml => tilt_extraction.yml} (59%) diff --git a/.github/workflows/tilt_geo_extraction.yml b/.github/workflows/tilt_extraction.yml similarity index 59% rename from .github/workflows/tilt_geo_extraction.yml rename to .github/workflows/tilt_extraction.yml index a569efb..b1e1fdc 100644 --- a/.github/workflows/tilt_geo_extraction.yml +++ b/.github/workflows/tilt_extraction.yml @@ -1,4 +1,4 @@ -name: Tilt Geo Extraction +name: Tilt Extraction on: push: @@ -44,17 +44,37 @@ jobs: done fi + - name: Extract category and update deployment.yaml + run: | + # Extract category from tilt.json + CATEGORIES=$(jq -r '.dataDisclosed[]?.recipients[]?.category | select(.!=null)' tilt.json) + + # Print the extracted categories + echo "Extracted Countries: $CATEGORIES" + + # Check if there are any categories extracted + if [ -n "$CATEGORIES" ]; then + # Update deployment.yaml for each category + for CATEGORY in $CATEGORIES; do + LABEL="cat-$CATEGORY: \"true\"" + # Check and append the label with correct indentation under metadata/labels. Only does this at the first instance of labels and not for subsequent instances. + # IMPORTANT: This assumes that the labels are indented with 4 spaces. If the indentation is different, this will not work. + # ALSO: This assumes that the labels are the first entry under metadata. If the labels are under some other section or not the first entry, this will not work. + awk -v label="$LABEL" 'BEGIN {append=0} /metadata:/ {print; getline; if ($1 == "labels:" && append == 0) {print; print " " label; append=1; next}}1' dev/deployment.yaml > dev/deployment_temp.yaml && mv dev/deployment_temp.yaml dev/deployment.yaml + done + fi + - name: Commit and push if changed run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" - # Add all three potentially modified deployment.yaml files + # Add every potentially modified deployment.yaml file git add apps/catalogue/deployment.yaml git add apps/orders/deployment.yaml git add apps/payment/deployment.yaml git add apps/shipping/deployment.yaml # Commit and push if there are any changes - git diff-index --quiet HEAD || git commit -m "Update deployment.yaml files with geo label from tilt.json" - git push + git diff-index --quiet HEAD || git commit -m "Add tilt-labels to deployment files" + git push \ No newline at end of file