Skip to content

Commit

Permalink
Use cargo-binstall fallback also if tool is available but specified v…
Browse files Browse the repository at this point in the history
…ersion not available
  • Loading branch information
taiki-e committed Feb 10, 2023
1 parent d4ce367 commit daab682
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com

- Fix install failure of Rust-related binaries when `$CARGO_HOME/bin` exists, but is not included in the `$PATH`. This failure occurred in slightly odd cases, such as multiple installations of rust in different directories.

- Use cargo-binstall fallback also if tool is available but the specified version not available. ([#68](https://github.com/taiki-e/install-action/pull/68))

## [2.3.5] - 2023-02-04

- Update `cross@latest` to 0.2.5.
Expand Down
28 changes: 23 additions & 5 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,15 @@ read_manifest() {
local manifest
manifest=$(jq -r ".\"${version}\"" "${manifest_dir}/${tool}.json")
if [[ "${manifest}" == "null" ]]; then
bail "version '${version}' for ${tool} is not supported"
download_info="null"
return 0
fi
local exact_version
exact_version=$(jq <<<"${manifest}" -r '.version')
if [[ "${exact_version}" == "null" ]]; then
exact_version="${version}"
else
manifest=$(jq -r ".\"${exact_version}\"" "${manifest_dir}/${tool}.json")
fi
local download_info
local host_platform
case "${host_os}" in
linux)
# Static-linked binaries compiled for linux-musl will also work on linux-gnu systems and are
Expand Down Expand Up @@ -191,6 +189,10 @@ read_manifest() {
;;
*) bail "unsupported OS type '${host_os}' for ${tool}" ;;
esac
}
read_download_info() {
local tool="$1"
local version="$2"
if [[ "${download_info}" == "null" ]]; then
bail "${tool}@${version} for '${host_os}' is not supported"
fi
Expand Down Expand Up @@ -218,6 +220,10 @@ read_manifest() {
}
download_from_manifest() {
read_manifest "$@"
download_from_download_info "$@"
}
download_from_download_info() {
read_download_info "$@"
download_and_extract "${url}" "${checksum}" "${bin_dir}" "${bin_in_archive}"
}
install_cargo_binstall() {
Expand Down Expand Up @@ -441,6 +447,7 @@ for tool in "${tools[@]}"; do
protoc)
info "installing ${tool}@${version}"
read_manifest "protoc" "${version}"
read_download_info "protoc" "${version}"
# Copying files to /usr/local/include requires sudo, so do not use it.
bin_dir="${HOME}/.install-action/bin"
include_dir="${HOME}/.install-action/include"
Expand Down Expand Up @@ -513,6 +520,17 @@ for tool in "${tools[@]}"; do
continue
fi

# Use cargo-binstall fallback if tool is available but the specified version not available.
read_manifest "${tool}" "${version}"
if [[ "${download_info}" == "null" ]]; then
warn "${tool}@${version} for '${host_os}' is not supported; fallback to cargo-binstall"
case "${version}" in
latest) unsupported_tools+=("${tool}") ;;
*) unsupported_tools+=("${tool}@${version}") ;;
esac
continue
fi

info "installing ${tool}@${version}"

# Pre-install
Expand All @@ -528,7 +546,7 @@ for tool in "${tools[@]}"; do
;;
esac

download_from_manifest "${tool}" "${version}"
download_from_download_info "${tool}" "${version}"
;;
esac

Expand Down

0 comments on commit daab682

Please sign in to comment.