@@ -75,53 +75,42 @@ jobs:
7575 echo "SUCCESS - sha256 matches for $zip_path"
7676 done < changed_zips.txt
7777
78- - name : Step 2 - Verify ZIP top-level directories are allowed
78+ - name : Step 2 - Unzip and verify root children are allowed
7979 shell : bash
8080 run : |
8181 set -euo pipefail
82+ allowed=("impex" "app-configuration" "storefront-next" "cartridges")
8283
83- allowed_dirs=("impex" "app-configuration" "storefront-next" "cartridges")
84-
85- # If step 1 found no zips, it exited 0 and step 2 still runs unless we guard.
86- # So guard here too.
87- if [[ ! -s changed_zips.txt ]]; then
88- echo "No .zip files changed in this PR. Nothing to verify."
89- exit 0
90- fi
84+ [[ -s changed_zips.txt ]] || exit 0
9185
9286 while IFS= read -r zip_path; do
93- if [[ ! -f "$zip_path" ]]; then
94- echo "Skipping (not present in PR head): $zip_path"
95- continue
96- fi
87+ [[ -f "$zip_path" ]] || continue
9788
98- # List entries, take the first path segment for entries that have '/'
99- mapfile -t top_dirs < <(
100- unzip -Z1 "$zip_path" \
101- | awk -F'/' 'NF>1 {print $1}' \
102- | sed '/^$/d' \
103- | sort -u
104- )
89+ tmpdir="$(mktemp -d)"
90+ unzip -q "$zip_path" -d "$tmpdir"
10591
106- if [[ ${#top_dirs[@]} -eq 0 ]]; then
107- echo "::error file=$zip_path::ZIP contains no top-level directories. Allowed: ${allowed_dirs[*]}"
92+ # Root should be exactly one directory (the wrapper folder)
93+ mapfile -t roots < <(find "$tmpdir" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | grep -v '^__MACOSX$' | sort -u)
94+ if [[ ${#roots[@]} -ne 1 ]]; then
95+ echo "::error file=$zip_path::Expected exactly 1 root directory after unzip, found ${#roots[@]}: ${roots[*]}"
96+ rm -rf "$tmpdir"
10897 exit 1
10998 fi
99+ root="$tmpdir/${roots[0]}"
110100
111- echo "ZIP: $zip_path"
112- echo "Top-level dirs found:"
113- printf ' - %s\n' "${top_dirs[@]}"
114-
115- for td in "${top_dirs[@]}"; do
101+ # Check immediate child directories of root are allowed
102+ mapfile -t children < <(find "$root" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | grep -v '^__MACOSX$' | sort -u)
103+ for c in "${children[@]}"; do
116104 ok=false
117- for ad in "${allowed_dirs [@]}"; do
118- if [[ "$td " == "$ad " ]]; then ok=true; break; fi
105+ for a in "${allowed [@]}"; do
106+ [[ "$c " == "$a " ]] && ok=true && break
119107 done
120108 if [[ "$ok" == "false" ]]; then
121- echo "::error file=$zip_path::Disallowed top-level directory \"$td\". Allowed: ${allowed_dirs[*]}"
109+ echo "::error file=$zip_path::Disallowed directory under root: \"$c\". Allowed: ${allowed[*]}"
110+ rm -rf "$tmpdir"
122111 exit 1
123112 fi
124113 done
125114
126- echo "SUCESS - structure ok for $zip_path "
115+ rm -rf "$tmpdir "
127116 done < changed_zips.txt
0 commit comments