Skip to content

Commit d9c5026

Browse files
committed
CI: Introduce curl/wget compatibility commands
This adds a universal download compatibility commands that work with curl or wget. The download tool check was failing scripts that source common.sh but don't use download functions (like riscv-tests.sh). This changes to only check for curl/wget when a download function is actually called. This prevents unnecessary failures in scripts that source common.sh for other utilities like PARALLEL or check_platform().
1 parent f29a741 commit d9c5026

File tree

6 files changed

+162
-12
lines changed

6 files changed

+162
-12
lines changed

.ci/boot-linux-prepare.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env bash
22

3-
. .ci/common.sh
3+
# Get the directory of this script
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
. "${SCRIPT_DIR}/common.sh"
46

57
check_platform
68

.ci/boot-linux.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env bash
22

3-
. .ci/common.sh
3+
# Get the directory of this script
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
. "${SCRIPT_DIR}/common.sh"
46

57
check_platform
68

.ci/common.sh

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,131 @@ if [[ "${OS_TYPE}" == "Linux" ]]; then
2020
else
2121
PARALLEL=-j$(sysctl -n hw.logicalcpu)
2222
fi
23+
24+
# Universal download utility with curl/wget compatibility
25+
# Provides consistent interface regardless of which tool is available
26+
27+
# Detect available download tool (lazy initialization)
28+
detect_download_tool()
29+
{
30+
if [ -n "${DOWNLOAD_TOOL:-}" ]; then
31+
return 0
32+
fi
33+
34+
if command -v curl > /dev/null 2>&1; then
35+
DOWNLOAD_TOOL="curl"
36+
elif command -v wget > /dev/null 2>&1; then
37+
DOWNLOAD_TOOL="wget"
38+
else
39+
echo "Error: Neither curl nor wget is available" >&2
40+
return 1
41+
fi
42+
}
43+
44+
# Download to stdout
45+
# Usage: download_to_stdout <url>
46+
download_to_stdout()
47+
{
48+
detect_download_tool || return 1
49+
local url="$1"
50+
case "$DOWNLOAD_TOOL" in
51+
curl)
52+
curl -fsSL "$url"
53+
;;
54+
wget)
55+
wget -qO- "$url"
56+
;;
57+
esac
58+
}
59+
60+
# Download to file
61+
# Usage: download_to_file <url> <output_file>
62+
download_to_file()
63+
{
64+
detect_download_tool || return 1
65+
local url="$1"
66+
local output="$2"
67+
case "$DOWNLOAD_TOOL" in
68+
curl)
69+
curl -fsSL -o "$output" "$url"
70+
;;
71+
wget)
72+
wget -q -O "$output" "$url"
73+
;;
74+
esac
75+
}
76+
77+
# Download with headers (for API calls)
78+
# Usage: download_with_headers <url> <header1> <header2> ...
79+
download_with_headers()
80+
{
81+
detect_download_tool || return 1
82+
local url="$1"
83+
shift
84+
local headers=()
85+
86+
case "$DOWNLOAD_TOOL" in
87+
curl)
88+
for header in "$@"; do
89+
headers+=(-H "$header")
90+
done
91+
curl -fsSL "${headers[@]}" "$url"
92+
;;
93+
wget)
94+
for header in "$@"; do
95+
headers+=(--header="$header")
96+
done
97+
wget -qO- "${headers[@]}" "$url"
98+
;;
99+
esac
100+
}
101+
102+
# Download silently (no progress, suitable for CI)
103+
# Usage: download_silent <url>
104+
download_silent()
105+
{
106+
detect_download_tool || return 1
107+
local url="$1"
108+
case "$DOWNLOAD_TOOL" in
109+
curl)
110+
curl -fsSL "$url"
111+
;;
112+
wget)
113+
wget -qO- "$url"
114+
;;
115+
esac
116+
}
117+
118+
# Download with progress bar (for interactive use)
119+
# Usage: download_with_progress <url> <output_file>
120+
download_with_progress()
121+
{
122+
detect_download_tool || return 1
123+
local url="$1"
124+
local output="$2"
125+
case "$DOWNLOAD_TOOL" in
126+
curl)
127+
curl -fL -# -o "$output" "$url"
128+
;;
129+
wget)
130+
wget -O "$output" "$url"
131+
;;
132+
esac
133+
}
134+
135+
# Check if URL is accessible
136+
# Usage: check_url <url>
137+
# Returns: 0 if accessible, 1 otherwise
138+
check_url()
139+
{
140+
detect_download_tool || return 1
141+
local url="$1"
142+
case "$DOWNLOAD_TOOL" in
143+
curl)
144+
curl -fsSL --head "$url" > /dev/null 2>&1
145+
;;
146+
wget)
147+
wget --spider -q "$url" 2> /dev/null
148+
;;
149+
esac
150+
}

.ci/riscv-tests.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env bash
22

3-
. .ci/common.sh
3+
# Get the directory of this script
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
. "${SCRIPT_DIR}/common.sh"
46

57
set -e -u -o pipefail
68

.ci/riscv-toolchain-install.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
set -e -u -o pipefail
44

5-
. .ci/common.sh
5+
# Get the directory of this script
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
. "${SCRIPT_DIR}/common.sh"
68

79
check_platform
810
mkdir -p toolchain
@@ -30,4 +32,16 @@ else
3032
TOOLCHAIN_URL=${TOOLCHAIN_REPO}/releases/download/${GCC_VER}/riscv32-elf-ubuntu-${UBUNTU_VER}-gcc-nightly-${GCC_VER}-nightly.tar.xz
3133
fi
3234

33-
wget ${TOOLCHAIN_URL} -O- | tar -xz --strip-components=1 -C toolchain
35+
# Detect compression type and extract accordingly
36+
case "${TOOLCHAIN_URL}" in
37+
*.tar.xz)
38+
download_to_stdout "${TOOLCHAIN_URL}" | tar -xJ --strip-components=1 -C toolchain
39+
;;
40+
*.tar.gz)
41+
download_to_stdout "${TOOLCHAIN_URL}" | tar -xz --strip-components=1 -C toolchain
42+
;;
43+
*)
44+
echo "Error: Unknown archive format for ${TOOLCHAIN_URL}" >&2
45+
exit 1
46+
;;
47+
esac

.github/workflows/main.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,29 +369,31 @@ jobs:
369369
env:
370370
CC: ${{ steps.install_cc.outputs.cc }}
371371
run: |
372-
LATEST_RELEASE=$(wget --header="Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -q \
373-
https://api.github.com/repos/sysprog21/rv32emu-prebuilt/releases -O- \
372+
. .ci/common.sh
373+
LATEST_RELEASE=$(download_with_headers "https://api.github.com/repos/sysprog21/rv32emu-prebuilt/releases" \
374+
"Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
374375
| grep '"tag_name"' \
375376
| grep "ELF" \
376377
| head -n 1 \
377378
| sed -E 's/.*"tag_name": "([^"]+)".*/\1/')
378379
make LATEST_RELEASE=$LATEST_RELEASE artifact
379-
LATEST_RELEASE=$(wget --header="Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -q \
380-
https://api.github.com/repos/sysprog21/rv32emu-prebuilt/releases -O- \
380+
LATEST_RELEASE=$(download_with_headers "https://api.github.com/repos/sysprog21/rv32emu-prebuilt/releases" \
381+
"Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
381382
| grep '"tag_name"' \
382383
| grep "Linux-Image" \
383384
| head -n 1 \
384385
| sed -E 's/.*"tag_name": "([^"]+)".*/\1/')
385386
make LATEST_RELEASE=$LATEST_RELEASE ENABLE_SYSTEM=1 artifact
386-
LATEST_RELEASE=$(wget --header="Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -q \
387-
https://api.github.com/repos/sysprog21/rv32emu-prebuilt/releases -O- \
387+
LATEST_RELEASE=$(download_with_headers "https://api.github.com/repos/sysprog21/rv32emu-prebuilt/releases" \
388+
"Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
388389
| grep '"tag_name"' \
389390
| grep "sail" \
390391
| head -n 1 \
391392
| sed -E 's/.*"tag_name": "([^"]+)".*/\1/')
392393
make LATEST_RELEASE=$LATEST_RELEASE ENABLE_ARCH_TEST=1 artifact
393394
# get from rv32emu-prebuilt
394-
wget -O build/shareware_doom_iwad.zip "https://raw.githubusercontent.com/sysprog21/rv32emu-prebuilt/doom-artifact/shareware_doom_iwad.zip"
395+
download_to_file "https://raw.githubusercontent.com/sysprog21/rv32emu-prebuilt/doom-artifact/shareware_doom_iwad.zip" \
396+
"build/shareware_doom_iwad.zip"
395397
unzip -d build/ build/shareware_doom_iwad.zip
396398
if: ${{ always() }}
397399
- name: default build using emcc

0 commit comments

Comments
 (0)