Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cargo-binstall fallback also if tool is available but specified version not available #68

Merged
merged 2 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 1 addition & 17 deletions manifests/mdbook.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 0 additions & 84 deletions manifests/shfmt.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions manifests/wasmtime.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tools/codegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fn main() -> Result<()> {
.join("manifests")
.join(format!("{package}.json"));
let download_cache_dir = &workspace_root.join("tools/codegen/tmp/cache").join(package);
fs::create_dir_all(manifest_path.parent().unwrap())?;
fs::create_dir_all(download_cache_dir)?;

let base_info: BaseManifest = serde_json::from_slice(&fs::read(
Expand Down Expand Up @@ -59,6 +60,9 @@ fn main() -> Result<()> {
let releases: BTreeMap<_, _> = releases
.iter()
.filter_map(|release| {
if release.prerelease {
return None;
}
let version = release.tag_name.strip_prefix(&base_info.tag_prefix)?;
let mut semver_version = version.parse::<semver::Version>();
if semver_version.is_err() {
Expand Down