Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 194 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1931,9 +1931,202 @@ jobs:
path: test/twister-out/twister.xml

# Post test result check
test-downloader-fallback:
name: Test Downloader Fallback (${{ matrix.os }}, ${{ matrix.scenario }})
needs: [ setup, build-dist-bundle ]
runs-on: ${{ matrix.runner }}

strategy:
fail-fast: false
matrix:
include:
# Test curl fallback on Windows (remove wget)
- os: windows
runner: windows-2022
scenario: curl-only
bundle-host: windows-x86_64
bundle-archive: 7z
toolchain: arm-zephyr-eabi

# Test wget on Windows (explicit /dl wget flag)
- os: windows
runner: windows-2022
scenario: wget-explicit
bundle-host: windows-x86_64
bundle-archive: 7z
toolchain: arm-zephyr-eabi

# Test curl explicit on Windows
- os: windows
runner: windows-2022
scenario: curl-explicit
bundle-host: windows-x86_64
bundle-archive: 7z
toolchain: arm-zephyr-eabi

# Test curl fallback on macOS (no wget by default)
- os: macos
runner: macos-13
scenario: curl-fallback
bundle-host: macos-x86_64
bundle-archive: tar.xz
toolchain: arm-zephyr-eabi

# Test curl fallback on Linux (remove wget)
- os: linux
runner: ubuntu-24.04
scenario: curl-only
bundle-host: linux-x86_64
bundle-archive: tar.xz
toolchain: arm-zephyr-eabi

defaults:
run:
shell: bash

steps:
- name: Check out source code
if: ${{ github.event_name != 'pull_request_target' }}
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

- name: Check out source code (pull request)
if: ${{ github.event_name == 'pull_request_target' }}
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
persist-credentials: false

- name: Set up test environment (Windows)
if: ${{ matrix.os == 'windows' }}
run: |
# Install required packages (excluding wget for curl-only test)
if [ "${{ matrix.scenario }}" == "curl-only" ]; then
choco install cmake 7zip
echo "Testing curl-only fallback (wget not installed)"
elif [ "${{ matrix.scenario }}" == "wget-explicit" ]; then
choco install cmake 7zip wget
echo "Testing explicit wget flag"
elif [ "${{ matrix.scenario }}" == "curl-explicit" ]; then
choco install cmake 7zip
echo "Testing explicit curl flag"
fi

# Verify which tools are available
echo "=== Available download tools ==="
which wget && echo "wget: $(which wget)" || echo "wget: NOT FOUND"
which curl && echo "curl: $(which curl)" || echo "curl: NOT FOUND"
echo "================================"

- name: Set up test environment (macOS)
if: ${{ matrix.os == 'macos' }}
run: |
# macOS has curl by default but not wget
echo "Testing curl fallback on macOS (wget not installed by default)"

# Verify which tools are available
echo "=== Available download tools ==="
which wget && echo "wget: $(which wget)" || echo "wget: NOT FOUND"
which curl && echo "curl: $(which curl)" || echo "curl: NOT FOUND"
echo "================================"

- name: Set up test environment (Linux)
if: ${{ matrix.os == 'linux' }}
run: |
# Remove wget to force curl fallback
if [ "${{ matrix.scenario }}" == "curl-only" ]; then
sudo apt-get remove -y wget
echo "Testing curl-only fallback (wget removed)"
fi

# Verify which tools are available
echo "=== Available download tools ==="
which wget && echo "wget: $(which wget)" || echo "wget: NOT FOUND"
which curl && echo "curl: $(which curl)" || echo "curl: NOT FOUND"
echo "================================"

- name: Download version information
uses: actions/download-artifact@v4
with:
name: version
path: artifacts

- name: Resolve distribution bundle name
run: |
VERSION=$(<artifacts/version)
BUNDLE_NAME=${{ env.BUNDLE_PREFIX }}-${VERSION}_${{ matrix.bundle-host }}
BUNDLE_DIR=${{ env.BUNDLE_PREFIX }}-${VERSION}
echo "BUNDLE_NAME=${BUNDLE_NAME}" >> $GITHUB_ENV
echo "BUNDLE_DIR=${BUNDLE_DIR}" >> $GITHUB_ENV
echo "Testing with bundle: ${BUNDLE_NAME}"

- name: Download minimal distribution bundle
run: |
# Download minimal bundle for testing (just one toolchain)
gh run download \
-R ${GITHUB_REPOSITORY} \
${GITHUB_RUN_ID} \
-n ${BUNDLE_NAME} \
-D artifacts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Extract distribution bundle
run: |
mkdir -p tools
BUNDLE_FILE=${BUNDLE_NAME}_minimal.${{ matrix.bundle-archive }}

if [ "${{ matrix.bundle-archive }}" == "tar.xz" ]; then
tar -Jxf artifacts/${BUNDLE_FILE} -C tools || true
elif [ "${{ matrix.bundle-archive }}" == "7z" ]; then
7z x -otools artifacts/${BUNDLE_FILE} || true
fi

- name: Test setup script with scenario (${{ matrix.scenario }})
run: |
cd tools/${BUNDLE_DIR}

if [ "${{ matrix.os }}" == "windows" ]; then
# Windows batch script
if [ "${{ matrix.scenario }}" == "curl-only" ]; then
echo "Testing automatic fallback to curl..."
./setup.cmd /t ${{ matrix.toolchain }} /c || exit 1
elif [ "${{ matrix.scenario }}" == "wget-explicit" ]; then
echo "Testing explicit wget..."
./setup.cmd /t ${{ matrix.toolchain }} /c /dl wget || exit 1
elif [ "${{ matrix.scenario }}" == "curl-explicit" ]; then
echo "Testing explicit curl..."
./setup.cmd /t ${{ matrix.toolchain }} /c /dl curl || exit 1
fi
else
# POSIX shell script
if [ "${{ matrix.scenario }}" == "curl-fallback" ] || [ "${{ matrix.scenario }}" == "curl-only" ]; then
echo "Testing automatic fallback to curl..."
./setup.sh -t ${{ matrix.toolchain }} -c || exit 1
fi
fi

echo "✅ Setup script completed successfully with ${{ matrix.scenario }}"

- name: Verify toolchain installation
run: |
cd tools/${BUNDLE_DIR}

# Check that the toolchain was actually installed
if [ -d "gnu/${{ matrix.toolchain }}" ]; then
echo "✅ Toolchain ${{ matrix.toolchain }} installed successfully"
ls -la gnu/${{ matrix.toolchain }}
else
echo "❌ ERROR: Toolchain directory not found!"
exit 1
fi

test-result:
name: Test Result
needs: [ test-dist-bundle ]
needs: [ test-dist-bundle, test-downloader-fallback ]
runs-on: ubuntu-24.04

# NOTE: The 'test-result' job depends on the 'test-dist-bundle' job and
Expand Down
90 changes: 85 additions & 5 deletions scripts/template_setup_posix
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ check_command()
fi
}

# Silently check if command is available (for fallback logic)
check_command_silent()
{
which $1 &> /dev/null
return $?
}

# Check if the current installation is a full SDK with all GNU toolchains
check_full_gnu_sdk()
{
Expand All @@ -60,6 +67,31 @@ check_full_gnu_sdk()
return 0
}

# Download helper function
# Usage: download URL OUTFILE
download()
{
local url="$1"
local outfile="$2"

if [ "${dl_tool}" = "wget" ]; then
# Emulate quiet+progress+timestamping
wget -q --show-progress -N -O "${outfile}" "${url}"
return $?
else
# curl: -f fail on HTTP errors; -L follow redirects
# --remote-time preserves Last-Modified on the file
# -z OUTFILE does conditional GET (only download if newer)
# --progress-bar shows progress
if [ -f "${outfile}" ]; then
curl -fL --retry 5 --retry-delay 2 --progress-bar --remote-time -z "${outfile}" -o "${outfile}" "${url}"
else
curl -fL --retry 5 --retry-delay 2 --progress-bar --remote-time -o "${outfile}" "${url}"
fi
return $?
fi
}

# Display script usage
usage()
{
Expand All @@ -71,6 +103,7 @@ usage()
echo " -h Install host tools"
echo " -o Create symbolic links matching the old SDK layout for old Zephyr (< 4.3) bisectability"
echo " -c Register Zephyr SDK CMake package"
echo " -dl <curl|wget> Force downloader (default: wget, fallback to curl)"
echo
echo "Supported GNU Toolchains:"
echo
Expand Down Expand Up @@ -162,9 +195,20 @@ else
-c)
do_cmake_pkg="y"
;;
-dl)
shift
if [[ "$1" = "curl" ]]; then
dl_force="curl"
elif [[ "$1" = "wget" ]]; then
dl_force="wget"
else
echo "ERROR: -dl expects <curl|wget>"
exit 3
fi
;;
-o)
do_old_zephyr="y"
;;
do_old_zephyr="y"
;;
'-?')
usage
exit 0
Expand Down Expand Up @@ -213,7 +257,43 @@ echo

# Check dependencies
check_command cmake 90
check_command wget 91

# Choose downloader (default: wget; fallback to curl). Allow -dl override.
dl_tool=""

if [ "${dl_force}" = "curl" ]; then
check_command_silent curl
if [ $? -eq 0 ]; then
dl_tool="curl"
else
echo "ERROR: -dl curl requested but 'curl' not found in PATH."
exit 91
fi
elif [ "${dl_force}" = "wget" ]; then
check_command_silent wget
if [ $? -eq 0 ]; then
dl_tool="wget"
else
echo "ERROR: -dl wget requested but 'wget' not found in PATH."
exit 91
fi
else
# Default behavior: prefer wget, else curl
check_command_silent wget
if [ $? -eq 0 ]; then
dl_tool="wget"
else
check_command_silent curl
if [ $? -eq 0 ]; then
dl_tool="curl"
fi
fi
fi

if [ -z "${dl_tool}" ]; then
echo "Zephyr SDK setup requires either 'wget' or 'curl' in PATH."
exit 91
fi

# Ask for user inputs if no argument is specified
if [ "${interactive}" = "y" ]; then
Expand All @@ -238,7 +318,7 @@ if [ "${do_gnu_toolchain}" = "y" ]; then
echo "Installing '${toolchain}' GNU toolchain ..."

# Download toolchain archive
wget -q --show-progress -N -O "${toolchain_filename}" "${toolchain_uri}"
download "${toolchain_uri}" "${toolchain_filename}"
if [ $? != 0 ]; then
rm -f "${toolchain_filename}"
echo "ERROR: GNU toolchain download failed"
Expand All @@ -265,7 +345,7 @@ if [ "${do_llvm_toolchain}" = "y" ] && [ ! -d "llvm" ]; then
toolchain_uri="${dl_rel_base}/${toolchain_filename}"

# Download toolchain archive
wget -q --show-progress -N -O "${toolchain_filename}" "${toolchain_uri}"
download "${toolchain_uri}" "${toolchain_filename}"
if [ $? != 0 ]; then
rm -f "${toolchain_filename}"
echo "ERROR: LLVM toolchain download failed"
Expand Down
Loading
Loading