Răsfoiți Sursa

Wrap the grep inside an if-statement to avoid exiting script upon non-zero exitcode.

Signed-off-by: Gene Walters <[email protected]>
Gene Walters 1 an în urmă
părinte
comite
642741c98b
2 a modificat fișierele cu 57 adăugiri și 2 ștergeri
  1. 13 2
      .github/workflows/build-package.yaml
  2. 44 0
      test.sh

+ 13 - 2
.github/workflows/build-package.yaml

@@ -47,9 +47,20 @@ jobs:
               ;;
             esac
 
+            # Only get the changes that can be built
+            # Check if the diff contains the word "Scripts" to ensure we only build packages that have changed
+            # Wrap the grep inside an if-statement to avoid exiting script upon non-zero exitcode.
             DIFF=$(git diff ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} --no-ext-diff --unified=0 \
-                        --exit-code -a --no-prefix -- $FILE | egrep "^\+" | grep Scripts) # Get oly the changes that can be built
-          
+                      --exit-code -a --no-prefix -- $FILE | egrep "^\+")
+                      
+            if echo "$DIFF" | grep Scripts; then
+              DIFF=$(echo "$DIFF" | grep Scripts)
+            else
+              echo "Did not find Scripts changes in file: $FILE. Skipping."
+              continue
+            fi
+
+
             PACKAGE=$(echo $DIFF | cut -d'"' -f2)
             PACKPATH=$(echo $DIFF | egrep -o "package-system/[^ ]*")
             DOCKER=$(test -f "$PACKPATH/Dockerfile" && echo 1 || echo 0)

+ 44 - 0
test.sh

@@ -0,0 +1,44 @@
+#!/bin/sh
+CHANGED_FILES=$(git diff 7901137c1edf74d3f8c7c9fe1081e87cf29a4af2...30cfbab1672419d9f9d8dc123a5da07eb11eb0e9 --name-only)
+# Construct the package and os into a json string to be consumed by Github Actions runners
+JSON="{\"include\":["
+for FILE in $CHANGED_FILES; do
+  if [[ $FILE == package_build_list_host_* ]]; then
+    PLATFORM=$(echo $FILE | sed -n 's/package_build_list_host_\(.*\).json/\1/p')
+    case $PLATFORM in
+    linux*)
+      OS_RUNNER="ubuntu-20.04"
+      ;;
+    windows)
+      OS_RUNNER="windows-latest" # This is bundled with VS2022
+      ;;
+    darwin)
+      OS_RUNNER="macos-latest"
+      ;;
+    *)
+      OS_RUNNER="windows-latest" # default
+      ;;
+    esac
+    
+    echo "  File: $FILE"
+    DIFF=$(git diff 7901137c1edf74d3f8c7c9fe1081e87cf29a4af2...30cfbab1672419d9f9d8dc123a5da07eb11eb0e9 --no-ext-diff --unified=0 \
+                  --exit-code -a --no-prefix -- $FILE | egrep "^\+" | grep Scripts) # Get only the changes that can be built
+    
+    echo "  Diff: $DIFF"
+    PACKAGE=$(echo $DIFF | cut -d'"' -f2)
+    PACKPATH=$(echo $DIFF | egrep -o "package-system/[^ ]*")
+    DOCKER=$(test -f "$PACKPATH/Dockerfile" && echo 1 || echo 0)
+    JSONline="{\"package\": \"$PACKAGE\", \"os\": \"$OS_RUNNER\", \"dockerfile\": \"$DOCKER\"},"
+    if [[ "$JSON" != *"$JSONline"* ]]; then
+      JSON="$JSON$JSONline"
+    fi
+  fi
+done
+
+# Remove last "," and add closing brackets
+if [[ $JSON == *, ]]; then
+  JSON="${JSON%?}"
+fi
+JSON="$JSON]}"
+
+echo "Json: $JSON"