#!/bin/bash
set -euxo pipefail
index=$(curl -L https://index.crates.io/li/bc/libc)
if [[ "${TARGET_REF:-}" = *"libc-0.2" ]]; then
pat="^0.2"
elif [[ "${TARGET_REF:-}" = *"main" ]]; then
pat="^1.0"
else
echo "TARGET_REF must be set and end with either 'libc-0.2' or 'main'"
exit 1
fi
version=$(
echo "$index" |
jq -er --slurp --arg pat "$pat" '
map(select(.vers | test($pat)))
| last
| debug("version:", .)
| .vers
'
)
libc_cache="${XDG_CACHE_DIR:-$HOME/.cache}/libc-ci/"
mkdir -p "$libc_cache"
curl -L "https://static.crates.io/crates/libc/libc-$version.crate" | tar xzf - -C "$libc_cache"
crate_dir="$libc_cache/libc-$version"
echo "BASELINE_CRATE_DIR=$crate_dir" >> "$GITHUB_ENV"