Skip to content

Commit 91cd99c

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 91cd99c

File tree

3 files changed

+125
-8
lines changed

3 files changed

+125
-8
lines changed

.ci/common.sh

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

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