From a5c798b6b0dc05ed96da07eb9246c401808a6a06 Mon Sep 17 00:00:00 2001
From: Diemo Gebhardt <me@diemogebhardt.com>
Date: Tue, 26 Nov 2024 19:47:03 +0100
Subject: [PATCH] Refactor windows to make use of file

---
 .../ci-verify-binary-architecture.yaml         |  2 +-
 ...ase-nightly-verify-binary-architecture.yaml |  2 +-
 .../release-verify-binary-architecture.yaml    |  2 +-
 .github/workflows/run-bash.yaml                |  2 +-
 bin/verify-binary-architecture.sh              | 18 +++++++-----------
 5 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/.github/workflows/ci-verify-binary-architecture.yaml b/.github/workflows/ci-verify-binary-architecture.yaml
index 7d911280863..bcdf90d7a94 100644
--- a/.github/workflows/ci-verify-binary-architecture.yaml
+++ b/.github/workflows/ci-verify-binary-architecture.yaml
@@ -2,7 +2,7 @@ name: ci-verify-binary-architecture
 
 on:
   workflow_dispatch:
-  # push:
+  push:
 
 env:
   CARGO_TERM_COLOR: always
diff --git a/.github/workflows/release-nightly-verify-binary-architecture.yaml b/.github/workflows/release-nightly-verify-binary-architecture.yaml
index 9277593f251..1122ee0211f 100644
--- a/.github/workflows/release-nightly-verify-binary-architecture.yaml
+++ b/.github/workflows/release-nightly-verify-binary-architecture.yaml
@@ -2,7 +2,7 @@ name: release-nightly-verify-binary-architecture
 
 on:
   workflow_dispatch:
-  # push:
+  push:
 
 env:
   CARGO_TERM_COLOR: always
diff --git a/.github/workflows/release-verify-binary-architecture.yaml b/.github/workflows/release-verify-binary-architecture.yaml
index 53ed7e681c8..f7683fda956 100644
--- a/.github/workflows/release-verify-binary-architecture.yaml
+++ b/.github/workflows/release-verify-binary-architecture.yaml
@@ -2,7 +2,7 @@ name: release-verify-binary-architecture
 
 on:
   workflow_dispatch:
-  # push:
+  push:
 
 env:
   CARGO_TERM_COLOR: always
diff --git a/.github/workflows/run-bash.yaml b/.github/workflows/run-bash.yaml
index c1aae5d8db3..9ea41ef8f53 100644
--- a/.github/workflows/run-bash.yaml
+++ b/.github/workflows/run-bash.yaml
@@ -2,7 +2,7 @@ name: run-bash
 
 on:
   workflow_dispatch:
-  push:
+  # push:
 
 jobs:
   run-bash:
diff --git a/bin/verify-binary-architecture.sh b/bin/verify-binary-architecture.sh
index bea9e5bc0a5..1a159b504a4 100755
--- a/bin/verify-binary-architecture.sh
+++ b/bin/verify-binary-architecture.sh
@@ -41,17 +41,13 @@ case "${TARGET_TRIPLE}" in
         ;;
     *"windows"*)
         # Parse binary architecture
-        pe_header_output=$(powershell -Command "
-          \$bytes = [System.IO.File]::ReadAllBytes('${BINARY_PATH}');
-          \$header_offset = [System.BitConverter]::ToInt32(\$bytes, 0x3c);
-          \$machine_type = [System.BitConverter]::ToUInt16(\$bytes, \$header_offset + 4);
-          \$machine_type
-        " 2>&1) || echo "PE header extraction failed"
-        # Map binary architecture
-        case "${pe_header_output}" in
-            *"34404"*) BINARY_ARCHITECTURE="X64" ;;   # 0x8664
-            *"43620"*) BINARY_ARCHITECTURE="Arm64" ;; # 0xAA64
-            *) echo "Unknown PE machine type: '${pe_header_output}'"; exit 1 ;;
+        file_output=$(file -b "${BINARY_PATH}")
+        BINARY_ARCHITECTURE=$(echo "${file_output}" | grep -o "x86-64\|Aarch64" | head -n1 || echo "")
+        # Map expected binary architecture
+        case "${TARGET_ARCHITECTURE}" in
+            "x86_64") EXPECTED_BINARY_ARCHITECTURE="x86-64" ;;
+            "aarch64") EXPECTED_BINARY_ARCHITECTURE="Aarch64" ;;
+            *) echo "Unknown Linux architecture: '${TARGET_ARCHITECTURE}'"; exit 1 ;;
         esac
         # Map expected binary architecture
         case "${TARGET_ARCHITECTURE}" in