Fix install failures in edge cases

This commit is contained in:
Taiki Endo
2023-02-08 15:28:23 +09:00
parent 0340abb8d7
commit 9e1de916ab
5 changed files with 53 additions and 10 deletions

View File

@@ -18,6 +18,7 @@ nextest
protobuf
protoc
protocolbuffers
pwsh
quickinstall
rockylinux
rustwasm

View File

@@ -64,6 +64,21 @@ jobs:
- uses: ./
with:
tool: ${{ matrix.tool }}
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell
- name: Test bash
run: just --version; shfmt --version; protoc --version
shell: bash
- name: Test sh
run: just --version; shfmt --version; protoc --version
shell: sh
if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macos')
- name: Test pwsh
run: just --version; shfmt --version; protoc --version
shell: pwsh
- name: Test powershell
run: just --version; shfmt --version; protoc --version
shell: powershell
if: startsWith(matrix.os, 'windows')
# We use the version output to check the version of binstall, but they
# several times change the version output format in the past so we need to
# check it with CI. (e.g., 0.14.0->0.16.0 update change it

View File

@@ -10,6 +10,14 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
## [Unreleased]
- Support `cargo-tarpaulin`. ([#65](https://github.com/taiki-e/install-action/pull/65), thanks @orhun)
- Allow installing cargo subcommands without `cargo`.
- Fix issue where installed non-Rust related binaries cannot be found from PowerShell on Windows. Rust-related binaries, Unix shells such as bash, and non-Windows OS are not affected by this issue.
- 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.
## [2.3.5] - 2023-02-04
- Update `cross@latest` to 0.2.5.

View File

@@ -124,7 +124,7 @@ This action has been tested for GitHub-hosted runners (Ubuntu, macOS, Windows) a
To use this action in self-hosted runners or in containers, at least the following tools are required:
- bash
- cargo (if you install cargo subcommands or use cargo-binstall fallback)
- cargo (if you use cargo-binstall fallback)
## Related Projects

37
main.sh
View File

@@ -62,7 +62,7 @@ download_and_extract() {
bin_dir="${HOME}/.install-action/bin"
if [[ ! -d "${bin_dir}" ]]; then
mkdir -p "${bin_dir}"
echo "${bin_dir}" >>"${GITHUB_PATH}"
canonicalize_windows_path "${bin_dir}" >>"${GITHUB_PATH}"
export PATH="${PATH}:${bin_dir}"
fi
fi
@@ -294,6 +294,12 @@ sys_install() {
fedora) dnf_install "$@" ;;
esac
}
canonicalize_windows_path() {
case "${host_os}" in
windows) sed <<<"$1" 's/^\/c\//C:\\/' ;;
*) echo "$1" ;;
esac
}
# cargo-binstall may call `cargo install` on their fallback: https://github.com/taiki-e/install-action/pull/54#issuecomment-1383140833
# cross calls rustup on `cross --version` if the current directly is cargo workspace.
@@ -395,7 +401,10 @@ esac
tmp_dir="${HOME}/.install-action/tmp"
cargo_bin="${CARGO_HOME:-"${HOME}/.cargo"}/bin"
if [[ ! -d "${cargo_bin}" ]]; then
# If $CARGO_HOME does not exist, or cargo installed outside of $CARGO_HOME/bin
# is used ($CARGO_HOME/bin is most likely not included in the PATH), fallback to
# /usr/local/bin or $HOME/.install-action/bin.
if [[ ! -d "${cargo_bin}" ]] || [[ "${host_os}" != "windows" ]] && [[ "$(type -P cargo || true)" != "${cargo_bin}/cargo${exe}" ]]; then
cargo_bin=/usr/local/bin
fi
@@ -438,7 +447,7 @@ for tool in "${tools[@]}"; do
if [[ ! -d "${bin_dir}" ]]; then
mkdir -p "${bin_dir}"
mkdir -p "${include_dir}"
echo "${bin_dir}" >>"${GITHUB_PATH}"
canonicalize_windows_path "${bin_dir}" >>"${GITHUB_PATH}"
export PATH="${PATH}:${bin_dir}"
fi
if ! type -P unzip &>/dev/null; then
@@ -454,9 +463,7 @@ for tool in "${tools[@]}"; do
mv "bin/protoc${exe}" "${bin_dir}/"
mkdir -p "${include_dir}/"
cp -r include/. "${include_dir}/"
case "${host_os}" in
windows) bin_dir=$(sed <<<"${bin_dir}" 's/^\/c\//C:\\/') ;;
esac
bin_dir=$(canonicalize_windows_path "${bin_dir}")
if [[ -z "${PROTOC:-}" ]]; then
info "setting PROTOC environment variable"
echo "PROTOC=${bin_dir}/protoc${exe}" >>"${GITHUB_ENV}"
@@ -527,9 +534,21 @@ for tool in "${tools[@]}"; do
info "${tool} installed at $(type -P "${tool}${exe}")"
case "${tool}" in
cargo-udeps) x cargo udeps --help | head -1 ;; # cargo-udeps v0.1.30 does not support --version option
cargo-valgrind) x cargo valgrind --help ;; # cargo-valgrind v2.1.0 does not support --version option
cargo-*) x cargo "${tool#cargo-}" --version ;;
cargo-*)
if type -P cargo &>/dev/null; then
case "${tool}" in
cargo-udeps) x cargo udeps --help | head -1 ;; # cargo-udeps v0.1.30 does not support --version option
cargo-valgrind) x cargo valgrind --help ;; # cargo-valgrind v2.1.0 does not support --version option
*) x cargo "${tool#cargo-}" --version ;;
esac
else
case "${tool}" in
cargo-udeps) x "${tool}" udeps --help | head -1 ;; # cargo-udeps v0.1.30 does not support --version option
cargo-valgrind) x "${tool}" valgrind --help ;; # cargo-valgrind v2.1.0 does not support --version option
*) x "${tool}" "${tool#cargo-}" --version ;;
esac
fi
;;
*) x "${tool}" --version ;;
esac
echo