Skip to content

Commit f9c2619

Browse files
committed
CI: Introduce curl/wget compatibility layer
This adds a universal download compatibility layer that works with curl or wget, along with download utility functions to .ci/common.sh script.
1 parent f29a741 commit f9c2619

File tree

3 files changed

+119
-8
lines changed

3 files changed

+119
-8
lines changed

.ci/common.sh

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,112 @@ 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
28+
if command -v curl >/dev/null 2>&1; then
29+
DOWNLOAD_TOOL="curl"
30+
elif command -v wget >/dev/null 2>&1; then
31+
DOWNLOAD_TOOL="wget"
32+
else
33+
echo "Error: Neither curl nor wget is available" >&2
34+
exit 1
35+
fi
36+
37+
# Download to stdout
38+
# Usage: download_to_stdout <url>
39+
download_to_stdout() {
40+
local url="$1"
41+
case "$DOWNLOAD_TOOL" in
42+
curl)
43+
curl -fsSL "$url"
44+
;;
45+
wget)
46+
wget -qO- "$url"
47+
;;
48+
esac
49+
}
50+
51+
# Download to file
52+
# Usage: download_to_file <url> <output_file>
53+
download_to_file() {
54+
local url="$1"
55+
local output="$2"
56+
case "$DOWNLOAD_TOOL" in
57+
curl)
58+
curl -fsSL -o "$output" "$url"
59+
;;
60+
wget)
61+
wget -q -O "$output" "$url"
62+
;;
63+
esac
64+
}
65+
66+
# Download with headers (for API calls)
67+
# Usage: download_with_headers <url> <header1> <header2> ...
68+
download_with_headers() {
69+
local url="$1"
70+
shift
71+
local headers=()
72+
73+
case "$DOWNLOAD_TOOL" in
74+
curl)
75+
for header in "$@"; do
76+
headers+=(-H "$header")
77+
done
78+
curl -fsSL "${headers[@]}" "$url"
79+
;;
80+
wget)
81+
for header in "$@"; do
82+
headers+=(--header="$header")
83+
done
84+
wget -qO- "${headers[@]}" "$url"
85+
;;
86+
esac
87+
}
88+
89+
# Download silently (no progress, suitable for CI)
90+
# Usage: download_silent <url>
91+
download_silent() {
92+
local url="$1"
93+
case "$DOWNLOAD_TOOL" in
94+
curl)
95+
curl -sL "$url"
96+
;;
97+
wget)
98+
wget -qO- "$url"
99+
;;
100+
esac
101+
}
102+
103+
# Download with progress bar (for interactive use)
104+
# Usage: download_with_progress <url> <output_file>
105+
download_with_progress() {
106+
local url="$1"
107+
local output="$2"
108+
case "$DOWNLOAD_TOOL" in
109+
curl)
110+
curl -L -# -o "$output" "$url"
111+
;;
112+
wget)
113+
wget -O "$output" "$url"
114+
;;
115+
esac
116+
}
117+
118+
# Check if URL is accessible
119+
# Usage: check_url <url>
120+
# Returns: 0 if accessible, 1 otherwise
121+
check_url() {
122+
local url="$1"
123+
case "$DOWNLOAD_TOOL" in
124+
curl)
125+
curl -fsSL --head "$url" >/dev/null 2>&1
126+
;;
127+
wget)
128+
wget --spider -q "$url" 2>/dev/null
129+
;;
130+
esac
131+
}

.ci/riscv-toolchain-install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ else
3030
TOOLCHAIN_URL=${TOOLCHAIN_REPO}/releases/download/${GCC_VER}/riscv32-elf-ubuntu-${UBUNTU_VER}-gcc-nightly-${GCC_VER}-nightly.tar.xz
3131
fi
3232

33-
wget ${TOOLCHAIN_URL} -O- | tar -xz --strip-components=1 -C toolchain
33+
download_to_stdout "${TOOLCHAIN_URL}" | tar -xz --strip-components=1 -C toolchain

.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)