From 9ef09e3d3cad6a6745dc65a38e1e4cfd37b7b492 Mon Sep 17 00:00:00 2001
From: Martin Medler <martis42.dev@gmail.com>
Date: Sun, 28 Jan 2024 11:44:37 +0100
Subject: [PATCH] Move buuildozer setup into action

Windows support is work in progress
---
 .github/actions/prepare_buildozer/action.yml | 33 ++++++++++++++++++++
 .github/workflows/ci.yaml                    | 16 ++--------
 2 files changed, 36 insertions(+), 13 deletions(-)
 create mode 100644 .github/actions/prepare_buildozer/action.yml

diff --git a/.github/actions/prepare_buildozer/action.yml b/.github/actions/prepare_buildozer/action.yml
new file mode 100644
index 00000000..60c6e019
--- /dev/null
+++ b/.github/actions/prepare_buildozer/action.yml
@@ -0,0 +1,33 @@
+name: 'Prepare Buildozer'
+description: 'Download buildozer and make it available on PATH'
+inputs:
+  version:
+    description: 'Buildozer version'
+    required: true
+runs:
+  using: "composite"
+  steps:
+    - run: |
+        # Determine buildozer URL
+        BASE_URL="https://github.com/bazelbuild/buildtools/releases/download/v${{ inputs.version }}"
+        if [[ "${RUNNER_OS}" == "Linux" ]]; then
+          BUILDOZER_URL="${BASE_URL}/buildozer-linux-amd64"
+        elif [ "${RUNNER_OS}" == "macOS" ]; then
+          BUILDOZER_URL="${BASE_URL}/buildozer-darwin-amd64"
+        elif [ "${RUNNER_OS}" == "Windows" ]; then
+          BUILDOZER_URL="${BASE_URL}/buildozer-windows-amd64.exe"
+        else
+          echo "'${RUNNER_OS}' is not supported"
+          exit 1
+        fi
+
+        # Download buildozer
+        BUILDOZER_DIR="/tmp/bin"
+        BUILDOZER_PATH="${BUILDOZER_DIR}/buildozer"
+        mkdir -p "${BUILDOZER_DIR}"
+        wget --no-verbose "${BUILDOZER_URL}" -O "${BUILDOZER_PATH}"
+
+        # Make buildozer available on PATH for subsequent actions
+        chmod +x "${BUILDOZER_PATH}"
+        echo "${BUILDOZER_DIR}" >> $GITHUB_PATH
+      shell: bash
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 4e4f2cde..07c17cb2 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -67,22 +67,12 @@ jobs:
     runs-on: ${{ matrix.os }}
     needs: [ fast-tests ]
     steps:
-      - name: Prepare buildozer
-        if: runner.os == 'Linux'
-        run: |
-          mkdir --parents /tmp/bin
-          wget --no-verbose https://github.com/bazelbuild/buildtools/releases/download/v6.4.0/buildozer-linux-amd64 -O /tmp/bin/buildozer
-          chmod +x /tmp/bin/buildozer
-      - name: Prepare buildozer
-        if: runner.os == 'macOS'
-        run: |
-          mkdir -p /tmp/bin
-          wget --no-verbose https://github.com/bazelbuild/buildtools/releases/download/v6.4.0/buildozer-darwin-amd64 -O /tmp/bin/buildozer
-          chmod +x /tmp/bin/buildozer
       - uses: actions/checkout@v4
+      - uses: ./.github/actions/prepare_buildozer
+        with:
+          version: '6.4.0'
       - name: Integration tests - Applying fixes
         run: |
-          export PATH=/tmp/bin:$PATH
           python test/apply_fixes/execute_tests.py
 
   integration-tests-examples: