2023-02-24 01:44:48 +09:00
#!/usr/bin/env bash
2023-06-05 22:58:32 +09:00
# SPDX-License-Identifier: Apache-2.0 OR MIT
2023-09-29 21:03:39 +09:00
set -eEuo pipefail
2021-12-30 17:33:20 +09:00
IFS = $'\n\t'
2023-09-04 05:46:18 -07:00
rx( ) {
2021-12-30 17:33:20 +09:00
local cmd = " $1 "
shift
(
set -x
" ${ cmd } " " $@ "
)
}
retry( ) {
2023-01-15 19:55:57 +09:00
for i in { 1..10} ; do
2021-12-30 17:33:20 +09:00
if " $@ " ; then
return 0
else
sleep " ${ i } "
fi
done
" $@ "
}
bail( ) {
echo " ::error:: $* "
exit 1
}
warn( ) {
echo " ::warning:: $* "
}
info( ) {
2022-01-07 03:12:35 +09:00
echo " info: $* "
2021-12-30 17:33:20 +09:00
}
2024-04-13 21:29:09 +09:00
_sudo( ) {
if type -P sudo & >/dev/null; then
sudo " $@ "
else
" $@ "
fi
}
2022-12-24 21:49:18 +09:00
download_and_checksum( ) {
2022-07-25 19:26:13 +09:00
local url = " $1 "
2022-12-24 21:49:18 +09:00
local checksum = " $2 "
if [ [ -z " ${ enable_checksum } " ] ] ; then
checksum = ""
fi
info " downloading ${ url } "
retry curl --proto '=https' --tlsv1.2 -fsSL --retry 10 " ${ url } " -o tmp
if [ [ -n " ${ checksum } " ] ] ; then
info " verifying sha256 checksum for $( basename " ${ url } " ) "
if type -P sha256sum & >/dev/null; then
2023-10-05 20:08:38 +09:00
echo " ${ checksum } *tmp " | sha256sum -c - >/dev/null
2022-12-24 21:49:18 +09:00
elif type -P shasum & >/dev/null; then
# GitHub-hosted macOS runner does not install GNU Coreutils by default.
# https://github.com/actions/runner-images/issues/90
2023-10-05 20:08:38 +09:00
echo " ${ checksum } *tmp " | shasum -a 256 -c - >/dev/null
2022-12-24 21:49:18 +09:00
else
bail "checksum requires 'sha256sum' or 'shasum' command; consider installing one of them or setting 'checksum' input option to 'false'"
fi
fi
}
download_and_extract( ) {
local url = " $1 "
2024-03-02 15:24:02 +01:00
shift
local checksum = " $1 "
shift
local bin_dir = " $1 "
shift
local bin_in_archive = ( " $@ " ) # path to bin in archive
2023-09-16 22:26:41 +09:00
if [ [ " ${ bin_dir } " = = " ${ install_action_dir } /bin " ] ] ; then
init_install_action_bin_dir
2022-08-01 17:23:02 +09:00
fi
2023-09-04 05:46:18 -07:00
2024-03-02 15:24:02 +01:00
installed_bin = ( )
local tmp
2023-09-04 05:46:18 -07:00
case " ${ tool } " in
2024-03-02 15:24:02 +01:00
# xbuild's binary name is "x", as opposed to the usual crate name
2024-04-01 08:01:27 +08:00
xbuild) installed_bin = ( " ${ bin_dir } /x ${ exe } " ) ; ;
# editorconfig-checker's binary name is renamed below
editorconfig-checker) installed_bin = ( " ${ bin_dir } / ${ tool } ${ exe } " ) ; ;
2024-03-02 15:24:02 +01:00
*)
for tmp in " ${ bin_in_archive [@] } " ; do
installed_bin += ( " ${ bin_dir } / $( basename " ${ tmp } " ) " )
done
; ;
2023-09-04 05:46:18 -07:00
esac
2022-12-24 21:49:18 +09:00
2022-07-25 19:26:13 +09:00
local tar_args = ( )
case " ${ url } " in
2024-04-19 21:35:52 +09:00
*.tar.gz | *.tgz)
tar_args += ( "xzf" )
if ! type -P gzip & >/dev/null; then
case " ${ base_distro } " in
debian | fedora | suse | arch | alpine)
echo "::group::Install packages required for installation (gzip)"
sys_install gzip
echo "::endgroup::"
; ;
esac
fi
; ;
2022-12-14 11:24:22 +09:00
*.tar.bz2 | *.tbz2)
tar_args += ( "xjf" )
if ! type -P bzip2 & >/dev/null; then
case " ${ base_distro } " in
2024-04-19 21:35:52 +09:00
debian | fedora | suse | arch | alpine)
2023-07-31 23:09:15 +09:00
echo "::group::Install packages required for installation (bzip2)"
sys_install bzip2
echo "::endgroup::"
; ;
2022-12-14 11:24:22 +09:00
esac
fi
; ;
*.tar.xz | *.txz)
tar_args += ( "xJf" )
if ! type -P xz & >/dev/null; then
case " ${ base_distro } " in
2023-07-31 23:09:15 +09:00
debian)
echo "::group::Install packages required for installation (xz-utils)"
sys_install xz-utils
echo "::endgroup::"
; ;
2024-04-19 21:35:52 +09:00
fedora | suse | arch | alpine)
2023-07-31 23:09:15 +09:00
echo "::group::Install packages required for installation (xz)"
sys_install xz
echo "::endgroup::"
; ;
2022-12-14 11:24:22 +09:00
esac
fi
; ;
2022-07-25 19:26:13 +09:00
*.zip)
2022-12-14 11:24:22 +09:00
if ! type -P unzip & >/dev/null; then
case " ${ base_distro } " in
2024-04-19 21:35:52 +09:00
debian | fedora | suse | arch | alpine)
2023-07-31 23:09:15 +09:00
echo "::group::Install packages required for installation (unzip)"
sys_install unzip
echo "::endgroup::"
; ;
2022-12-14 11:24:22 +09:00
esac
fi
2022-07-25 19:26:13 +09:00
; ;
esac
2022-12-24 21:49:18 +09:00
mkdir -p " ${ tmp_dir } "
(
cd " ${ tmp_dir } "
download_and_checksum " ${ url } " " ${ checksum } "
if [ [ ${# tar_args [@] } -gt 0 ] ] ; then
tar_args += ( "tmp" )
2024-03-02 15:24:02 +01:00
tar " ${ tar_args [@] } "
for tmp in " ${ bin_in_archive [@] } " ; do
2024-04-01 08:01:27 +08:00
case " ${ tool } " in
editorconfig-checker) mv " ${ tmp } " " ${ bin_dir } / ${ tool } ${ exe } " ; ;
*) mv " ${ tmp } " " ${ bin_dir } / " ; ;
esac
2024-03-02 15:24:02 +01:00
done
2022-12-24 21:49:18 +09:00
else
case " ${ url } " in
*.zip)
2023-07-18 23:51:08 +09:00
unzip -q tmp " ${ bin_in_archive # \. / } "
2024-03-02 15:24:02 +01:00
for tmp in " ${ bin_in_archive [@] } " ; do
mv " ${ tmp } " " ${ bin_dir } / "
done
; ;
*)
for tmp in " ${ installed_bin [@] } " ; do
mv tmp " ${ tmp } "
done
2022-12-24 21:49:18 +09:00
; ;
esac
fi
)
rm -rf " ${ tmp_dir } "
case " ${ host_os } " in
linux | macos)
2024-03-02 15:24:02 +01:00
for tmp in " ${ installed_bin [@] } " ; do
if [ [ ! -x " ${ tmp } " ] ] ; then
chmod +x " ${ tmp } "
fi
done
2022-12-24 21:49:18 +09:00
; ;
esac
}
read_manifest( ) {
local tool = " $1 "
local version = " $2 "
local manifest
2023-09-16 22:26:41 +09:00
rust_crate = $( call_jq -r ".rust_crate" " ${ manifest_dir } / ${ tool } .json " )
manifest = $( call_jq -r " .\" ${ version } \" " " ${ manifest_dir } / ${ tool } .json " )
2022-12-27 03:04:33 +09:00
if [ [ " ${ manifest } " = = "null" ] ] ; then
2023-02-11 02:31:05 +09:00
download_info = "null"
return 0
2022-12-27 03:04:33 +09:00
fi
2023-09-16 22:26:41 +09:00
exact_version = $( call_jq <<< " ${ manifest } " -r '.version' )
2022-12-27 01:18:59 +09:00
if [ [ " ${ exact_version } " = = "null" ] ] ; then
exact_version = " ${ version } "
else
2023-09-16 22:26:41 +09:00
manifest = $( call_jq -r " .\" ${ exact_version } \" " " ${ manifest_dir } / ${ tool } .json " )
2024-06-08 17:38:41 +09:00
if [ [ " ${ rust_crate } " != "null" ] ] ; then
# TODO: don't hardcode tool name and use 'immediate_yank_reflection' field in base manifest.
case " ${ tool } " in
cargo-nextest | nextest)
crate_info = $( retry curl --proto '=https' --tlsv1.2 -fsSL --retry 10 " https://crates.io/api/v1/crates/ ${ rust_crate } " )
while true; do
yanked = $( jq <<< " ${ crate_info } " -r " .versions[] | select(.num == \" ${ exact_version } \") | .yanked " )
if [ [ " ${ yanked } " != "true" ] ] ; then
break
fi
previous_stable_version = $( jq <<< " ${ manifest } " -r '.previous_stable_version' )
if [ [ " ${ previous_stable_version } " = = "null" ] ] ; then
break
fi
info " ${ tool } @ ${ exact_version } is yanked; downgrade to ${ previous_stable_version } "
exact_version = " ${ previous_stable_version } "
manifest = $( jq -r " .\" ${ exact_version } \" " " ${ manifest_dir } / ${ tool } .json " )
done
; ;
esac
fi
2022-12-27 01:18:59 +09:00
fi
2024-06-08 17:38:41 +09:00
2022-12-24 21:49:18 +09:00
case " ${ host_os } " in
linux)
# Static-linked binaries compiled for linux-musl will also work on linux-gnu systems and are
# usually preferred over linux-gnu binaries because they can avoid glibc version issues.
# (rustc enables statically linking for linux-musl by default, except for mips.)
2022-12-27 00:21:55 +09:00
host_platform = " ${ host_arch } _linux_musl "
2023-09-16 22:26:41 +09:00
download_info = $( call_jq <<< " ${ manifest } " -r " . ${ host_platform } " )
2022-12-24 21:49:18 +09:00
if [ [ " ${ download_info } " = = "null" ] ] ; then
# Even if host_env is musl, we won't issue an error here because it seems that in
# some cases linux-gnu binaries will work on linux-musl hosts.
# https://wiki.alpinelinux.org/wiki/Running_glibc_programs
# TODO: However, a warning may make sense.
2022-12-27 00:21:55 +09:00
host_platform = " ${ host_arch } _linux_gnu "
2023-09-16 22:26:41 +09:00
download_info = $( call_jq <<< " ${ manifest } " -r " . ${ host_platform } " )
2024-06-08 17:38:41 +09:00
elif [ [ " ${ host_env } " = = "gnu" ] ] ; then
# TODO: don't hardcode tool name and use 'prefer_linux_gnu' field in base manifest.
case " ${ tool } " in
cargo-nextest | nextest)
# TODO: don't hardcode required glibc version
required_glibc_version = 2.27
higher_glibc_version = $( sort <<< " ${ required_glibc_version } " $'\n' " ${ host_glibc_version } " -Vu | tail -1)
if [ [ " ${ higher_glibc_version } " = = " ${ host_glibc_version } " ] ] ; then
# musl build of nextest is slow, so use glibc build if host_env is gnu.
# https://github.com/taiki-e/install-action/issues/13
host_platform = " ${ host_arch } _linux_gnu "
download_info = $( jq <<< " ${ manifest } " -r " . ${ host_platform } " )
fi
; ;
esac
2022-12-24 21:49:18 +09:00
fi
; ;
macos | windows)
# Binaries compiled for x86_64 macOS will usually also work on aarch64 macOS.
# Binaries compiled for x86_64 Windows will usually also work on aarch64 Windows 11+.
2022-12-27 00:21:55 +09:00
host_platform = " ${ host_arch } _ ${ host_os } "
2023-09-16 22:26:41 +09:00
download_info = $( call_jq <<< " ${ manifest } " -r " . ${ host_platform } " )
2022-12-24 21:49:18 +09:00
if [ [ " ${ download_info } " = = "null" ] ] && [ [ " ${ host_arch } " != "x86_64" ] ] ; then
2022-12-27 00:21:55 +09:00
host_platform = " x86_64_ ${ host_os } "
2023-09-16 22:26:41 +09:00
download_info = $( call_jq <<< " ${ manifest } " -r " . ${ host_platform } " )
2022-12-24 21:49:18 +09:00
fi
; ;
*) bail " unsupported OS type ' ${ host_os } ' for ${ tool } " ; ;
esac
2023-02-11 02:31:05 +09:00
}
read_download_info( ) {
local tool = " $1 "
local version = " $2 "
2022-12-24 21:49:18 +09:00
if [ [ " ${ download_info } " = = "null" ] ] ; then
bail " ${ tool } @ ${ version } for ' ${ host_os } ' is not supported "
2022-07-25 19:26:13 +09:00
fi
2023-09-16 22:26:41 +09:00
checksum = $( call_jq <<< " ${ download_info } " -r '.checksum' )
url = $( call_jq <<< " ${ download_info } " -r '.url' )
2024-03-02 15:24:02 +01:00
local tmp
bin_in_archive = ( )
2022-12-27 00:21:55 +09:00
if [ [ " ${ url } " = = "null" ] ] ; then
local template
2023-09-16 22:26:41 +09:00
template = $( call_jq -r " .template. ${ host_platform } " " ${ manifest_dir } / ${ tool } .json " )
url = $( call_jq <<< " ${ template } " -r '.url' )
2022-12-27 00:21:55 +09:00
url = " ${ url // \$ \{ version \} / ${ exact_version } } "
2024-03-02 15:24:02 +01:00
tmp = $( call_jq <<< " ${ template } " -r '.bin' | sed -E " s/\\ $\\{version\\}/ ${ exact_version } /g " )
if [ [ " ${ tmp } " = = *"[" * ] ] ; then
# shellcheck disable=SC2207
bin_in_archive = ( $( call_jq <<< " ${ template } " -r '.bin[]' | sed -E " s/\\ $\\{version\\}/ ${ exact_version } /g " ) )
fi
2022-12-27 00:21:55 +09:00
else
2024-03-02 15:24:02 +01:00
tmp = $( call_jq <<< " ${ download_info } " -r '.bin' )
if [ [ " ${ tmp } " = = *"[" * ] ] ; then
# shellcheck disable=SC2207
bin_in_archive = ( $( call_jq <<< " ${ download_info } " -r '.bin[]' ) )
fi
fi
if [ [ ${# bin_in_archive [@] } -eq 0 ] ] ; then
if [ [ " ${ tmp } " = = "null" ] ] ; then
bin_in_archive = ( " ${ tool } ${ exe } " )
else
bin_in_archive = ( " ${ tmp } " )
fi
2022-12-27 00:21:55 +09:00
fi
2023-08-04 21:58:05 +09:00
if [ [ " ${ rust_crate } " = = "null" ] ] ; then
2023-09-16 22:26:41 +09:00
if [ [ " ${ host_os } " = = "windows" ] ] || [ [ ! -e /usr/local/bin ] ] ; then
bin_dir = " ${ install_action_dir } /bin "
else
bin_dir = /usr/local/bin
fi
2023-08-04 21:58:05 +09:00
else
2022-12-24 21:49:18 +09:00
bin_dir = " ${ cargo_bin } "
fi
}
download_from_manifest( ) {
read_manifest " $@ "
2023-02-11 02:31:05 +09:00
download_from_download_info " $@ "
}
download_from_download_info( ) {
read_download_info " $@ "
2024-03-02 15:24:02 +01:00
download_and_extract " ${ url } " " ${ checksum } " " ${ bin_dir } " " ${ bin_in_archive [@] } "
2022-07-25 19:26:13 +09:00
}
2022-06-10 23:19:55 +10:00
install_cargo_binstall( ) {
2022-12-24 21:49:18 +09:00
local binstall_version
2023-09-16 22:26:41 +09:00
binstall_version = $( call_jq -r '.latest.version' " ${ manifest_dir } /cargo-binstall.json " )
2022-12-04 07:21:43 +09:00
local install_binstall = '1'
2023-09-16 22:26:41 +09:00
_binstall_version = $( " cargo-binstall ${ exe } " binstall -V 2>/dev/null || echo "" )
if [ [ -n " ${ _binstall_version } " ] ] ; then
if [ [ " ${ _binstall_version } " = = " ${ binstall_version } " ] ] ; then
2023-01-15 21:38:36 +09:00
info " cargo-binstall already installed at ${ cargo_bin } /cargo-binstall ${ exe } "
2022-09-25 17:08:12 +09:00
install_binstall = ''
else
2023-01-15 21:38:36 +09:00
info " cargo-binstall already installed at ${ cargo_bin } /cargo-binstall ${ exe } , but is not compatible version with install-action, upgrading "
2022-09-25 17:08:12 +09:00
rm " ${ cargo_bin } /cargo-binstall ${ exe } "
fi
fi
2022-09-25 17:12:29 +10:00
2022-09-25 17:08:12 +09:00
if [ [ -n " ${ install_binstall } " ] ] ; then
2023-09-16 22:26:41 +09:00
info " installing cargo-binstall@latest ( ${ binstall_version } ) "
2022-12-24 21:49:18 +09:00
download_from_manifest "cargo-binstall" "latest"
2023-09-16 22:26:41 +09:00
installed_at = $( type -P " cargo-binstall ${ exe } " || echo "" )
if [ [ -n " ${ installed_at } " ] ] ; then
info " cargo-binstall installed at ${ installed_at } "
else
warn " cargo-binstall should be installed at ${ bin_dir :- } /cargo-binstall ${ exe } ; but cargo-binstall ${ exe } not found in path "
fi
rx " cargo-binstall ${ exe } " binstall -V
2022-06-10 23:19:55 +10:00
fi
}
2022-12-11 16:22:13 +09:00
apt_update( ) {
2024-04-13 21:29:09 +09:00
retry _sudo apt-get -o Acquire::Retries= 10 -qq update
2022-12-14 11:24:22 +09:00
apt_updated = 1
2022-12-11 16:22:13 +09:00
}
apt_install( ) {
2022-12-14 11:24:22 +09:00
if [ [ -z " ${ apt_updated :- } " ] ] ; then
apt_update
fi
2024-04-13 21:29:09 +09:00
retry _sudo apt-get -o Acquire::Retries= 10 -o Dpkg::Use-Pty= 0 install -y --no-install-recommends " $@ "
2022-12-11 16:22:13 +09:00
}
apt_remove( ) {
2024-04-13 21:29:09 +09:00
_sudo apt-get -qq -o Dpkg::Use-Pty= 0 remove -y " $@ "
2022-12-11 16:22:13 +09:00
}
snap_install( ) {
2024-04-13 21:29:09 +09:00
retry _sudo snap install " $@ "
2022-12-11 16:22:13 +09:00
}
2024-04-19 21:35:52 +09:00
dnf_install( ) {
retry _sudo " ${ dnf } " install -y " $@ "
}
zypper_install( ) {
retry _sudo zypper install -y " $@ "
}
pacman_install( ) {
retry _sudo pacman -Sy --noconfirm " $@ "
}
2022-12-14 11:24:22 +09:00
apk_install( ) {
2023-10-07 02:17:05 +09:00
if type -P sudo & >/dev/null; then
sudo apk --no-cache add " $@ "
elif type -P doas & >/dev/null; then
2023-02-07 22:16:25 +09:00
doas apk --no-cache add " $@ "
2022-12-14 11:24:22 +09:00
else
2023-02-07 22:16:25 +09:00
apk --no-cache add " $@ "
2022-12-14 11:24:22 +09:00
fi
}
sys_install( ) {
case " ${ base_distro } " in
debian) apt_install " $@ " ; ;
2022-12-14 22:40:45 +09:00
fedora) dnf_install " $@ " ; ;
2024-04-19 21:35:52 +09:00
suse) zypper_install " $@ " ; ;
arch) pacman_install " $@ " ; ;
alpine) apk_install " $@ " ; ;
2022-12-14 11:24:22 +09:00
esac
}
2023-09-16 22:26:41 +09:00
init_install_action_bin_dir( ) {
if [ [ -z " ${ init_install_action_bin :- } " ] ] ; then
init_install_action_bin = 1
mkdir -p " ${ bin_dir } "
export PATH = " ${ PATH } : ${ bin_dir } "
local _bin_dir
_bin_dir = $( canonicalize_windows_path " ${ bin_dir } " )
# TODO: avoid this when already added
info " adding ' ${ _bin_dir } ' to PATH "
echo " ${ _bin_dir } " >>" ${ GITHUB_PATH } "
fi
}
2023-02-08 15:28:23 +09:00
canonicalize_windows_path( ) {
case " ${ host_os } " in
2023-09-16 22:26:41 +09:00
windows) sed <<< " $1 " 's/^\/c\//C:\\/; s/\//\\/g' ; ;
2023-02-08 15:28:23 +09:00
*) echo " $1 " ; ;
esac
}
2021-12-30 17:33:20 +09:00
2023-01-16 19:45:56 +09:00
# 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.
export CARGO_NET_RETRY = 10
export RUSTUP_MAX_RETRIES = 10
2021-12-30 17:33:20 +09:00
if [ [ $# -gt 0 ] ] ; then
bail " invalid argument ' $1 ' "
fi
export DEBIAN_FRONTEND = noninteractive
2022-12-24 21:49:18 +09:00
manifest_dir = " $( dirname " $0 " ) /manifests "
2021-12-30 17:33:20 +09:00
# Inputs
tool = " ${ INPUT_TOOL :- } "
tools = ( )
if [ [ -n " ${ tool } " ] ] ; then
2023-05-04 02:07:18 +09:00
while read -rd,; do
t = " ${ REPLY # * } "
tools += ( " ${ t %* } " )
done <<< " ${ tool } , "
2021-12-30 17:33:20 +09:00
fi
2023-01-14 00:02:02 +09:00
if [ [ ${# tools [@] } -eq 0 ] ] ; then
warn "no tool specified; this could be caused by a dependabot bug where @<tool_name> tags on this action are replaced by @<version> tags"
# Exit with 0 for backward compatibility, we want to reject it in the next major release.
exit 0
fi
2021-12-30 17:33:20 +09:00
2022-12-24 21:49:18 +09:00
enable_checksum = " ${ INPUT_CHECKSUM :- } "
case " ${ enable_checksum } " in
true ) ; ;
false ) enable_checksum = '' ; ;
*) bail " 'checksum' input option must be 'true' or 'false': ' ${ enable_checksum } ' " ; ;
esac
2022-12-15 00:16:20 +09:00
# Refs: https://github.com/rust-lang/rustup/blob/HEAD/rustup-init.sh
2022-12-14 11:24:22 +09:00
base_distro = ""
exe = ""
2022-12-24 21:49:18 +09:00
case " $( uname -s) " in
Linux)
host_os = linux
2024-06-08 17:38:41 +09:00
ldd_version = $( ldd --version 2>& 1 || true )
if grep <<< " ${ ldd_version } " -q 'musl' ; then
host_env = "musl"
else
host_env = "gnu"
host_glibc_version = $( grep <<< " ${ ldd_version } " -E "GLIBC|GNU libc" | sed "s/.* //g" )
fi
2022-12-14 11:24:22 +09:00
if grep -q '^ID_LIKE=' /etc/os-release; then
2024-04-21 03:28:30 +09:00
base_distro = $( grep '^ID_LIKE=' /etc/os-release | cut -d= -f2)
2022-12-14 22:40:45 +09:00
case " ${ base_distro } " in
*debian*) base_distro = debian ; ;
*fedora*) base_distro = fedora ; ;
2024-04-19 21:35:52 +09:00
*suse*) base_distro = suse ; ;
*arch*) base_distro = arch ; ;
*alpine*) base_distro = alpine ; ;
2022-12-14 22:40:45 +09:00
esac
2022-12-14 11:24:22 +09:00
else
2024-04-21 03:28:30 +09:00
base_distro = $( grep '^ID=' /etc/os-release | cut -d= -f2)
2022-12-14 11:24:22 +09:00
fi
2022-12-14 22:40:45 +09:00
case " ${ base_distro } " in
fedora)
dnf = dnf
if ! type -P dnf & >/dev/null; then
if type -P microdnf & >/dev/null; then
# fedora-based distributions have "minimal" images that
# use microdnf instead of dnf.
dnf = microdnf
else
# If neither dnf nor microdnf is available, it is
# probably an RHEL7-based distribution that does not
# have dnf installed by default.
2022-12-14 23:46:06 +09:00
dnf = yum
2022-12-14 22:40:45 +09:00
fi
fi
; ;
esac
2022-12-14 10:47:48 +09:00
; ;
2022-12-24 21:49:18 +09:00
Darwin) host_os = macos ; ;
MINGW* | MSYS* | CYGWIN* | Windows_NT)
host_os = windows
exe = ".exe"
; ;
*) bail " unrecognized OS type ' $( uname -s) ' " ; ;
2022-07-25 19:26:13 +09:00
esac
2023-01-15 18:38:19 +09:00
case " $( uname -m) " in
aarch64 | arm64) host_arch = "aarch64" ; ;
2024-04-19 21:35:52 +09:00
xscale | arm | armv*l)
2023-01-15 18:38:19 +09:00
# Ignore arm for now, as we need to consider the version and whether hard-float is supported.
# https://github.com/rust-lang/rustup/pull/593
# https://github.com/cross-rs/cross/pull/1018
2024-03-02 16:29:28 +09:00
# Does it seem only armv7l+ is supported?
2024-04-19 21:35:52 +09:00
# https://github.com/actions/runner/blob/v2.315.0/src/Misc/externals.sh#L189
2024-03-02 16:29:28 +09:00
# https://github.com/actions/runner/issues/688
2023-06-10 18:03:24 +09:00
bail "32-bit ARM runner is not supported yet by this action; if you need support for this platform, please submit an issue at <https://github.com/taiki-e/install-action>"
2023-01-15 18:38:19 +09:00
; ;
# GitHub Actions Runner supports Linux (x86_64, aarch64, arm), Windows (x86_64, aarch64),
# and macOS (x86_64, aarch64).
2024-04-19 21:35:52 +09:00
# https://github.com/actions/runner/blob/v2.315.0/.github/workflows/build.yml#L21
2023-01-15 18:38:19 +09:00
# https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners#supported-architectures-and-operating-systems-for-self-hosted-runners
# So we can assume x86_64 unless it is aarch64 or arm.
*) host_arch = "x86_64" ; ;
esac
2023-09-16 22:26:41 +09:00
info " host platform: ${ host_arch } _ ${ host_os } "
2022-07-25 19:26:13 +09:00
2023-09-16 22:26:41 +09:00
install_action_dir = " ${ HOME } /.install-action "
tmp_dir = " ${ install_action_dir } /tmp "
2022-08-22 21:50:17 +09:00
cargo_bin = " ${ CARGO_HOME :- " ${ HOME } /.cargo " } /bin "
2023-02-08 15:28:23 +09:00
# 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
2023-09-16 22:26:41 +09:00
# /usr/local/bin or $install_action_dir/bin.
if [ [ ! -e " ${ cargo_bin } " ] ] || [ [ " $( type -P cargo || true ) " != " ${ cargo_bin } /cargo " * ] ] ; then
if type -P cargo & >/dev/null; then
info " cargo is located at $( type -P cargo) "
fi
if [ [ " ${ host_os } " = = "windows" ] ] || [ [ ! -e /usr/local/bin ] ] ; then
cargo_bin = " ${ install_action_dir } /bin "
else
cargo_bin = /usr/local/bin
fi
2022-07-25 20:00:53 +09:00
fi
2022-07-25 19:26:13 +09:00
2023-09-16 22:26:41 +09:00
jq_use_b = ''
case " ${ host_os } " in
linux)
if ! type -P jq & >/dev/null || ! type -P curl & >/dev/null || ! type -P tar & >/dev/null; then
case " ${ base_distro } " in
2024-04-19 21:35:52 +09:00
debian | fedora | suse | arch | alpine)
2023-09-16 22:26:41 +09:00
echo "::group::Install packages required for installation (jq, curl, and/or tar)"
sys_packages = ( )
if ! type -P curl & >/dev/null; then
sys_packages += ( ca-certificates curl)
fi
if ! type -P tar & >/dev/null; then
sys_packages += ( tar)
fi
if [ [ " ${ dnf :- } " = = "yum" ] ] ; then
# On RHEL7-based distribution jq requires EPEL
if ! type -P jq & >/dev/null; then
sys_packages += ( epel-release)
sys_install " ${ sys_packages [@] } "
sys_install jq --enablerepo= epel
else
sys_install " ${ sys_packages [@] } "
fi
else
if ! type -P jq & >/dev/null; then
2024-06-09 09:49:06 +08:00
# https://github.com/taiki-e/install-action/issues/521
if [ [ " ${ base_distro } " = = "arch" ] ] ; then
sys_packages += ( glibc)
fi
2023-09-16 22:26:41 +09:00
sys_packages += ( jq)
fi
sys_install " ${ sys_packages [@] } "
fi
echo "::endgroup::"
; ;
2024-04-19 21:35:52 +09:00
*) warn "install-action requires at least jq and curl on non-Debian/Fedora/SUSE/Arch/Alpine-based Linux" ; ;
2023-09-16 22:26:41 +09:00
esac
fi
; ;
macos)
if ! type -P jq & >/dev/null || ! type -P curl & >/dev/null; then
warn "install-action requires at least jq and curl on macOS"
fi
; ;
windows)
if ! type -P curl & >/dev/null; then
warn "install-action requires at least curl on Windows"
fi
# https://github.com/jqlang/jq/issues/1854
jq_use_b = 1
jq = " ${ install_action_dir } /jq/bin/jq.exe "
if [ [ ! -f " ${ jq } " ] ] ; then
jq_version = $( jq --version || echo "" )
case " ${ jq_version } " in
jq-1.[ 7-9] * | jq-1.[ 1-9] [ 0-9] *) jq = '' ; ;
*)
2023-09-16 22:54:11 +09:00
_tmp = $( jq <<< "{}" -r .a || echo "" )
if [ [ " ${ _tmp } " = = "null" ] ] ; then
jq = ''
jq_use_b = ''
else
info " old jq ( ${ jq_version } ) has bug on Windows; downloading jq 1.7 (will not be added to PATH) "
mkdir -p " ${ install_action_dir } /jq/bin "
2023-12-24 17:21:00 +09:00
url = 'https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-windows-amd64.exe'
checksum = '7451fbbf37feffb9bf262bd97c54f0da558c63f0748e64152dd87b0a07b6d6ab'
2023-09-16 22:54:11 +09:00
(
cd " ${ install_action_dir } /jq/bin "
download_and_checksum " ${ url } " " ${ checksum } "
mv tmp jq.exe
)
echo
fi
2023-09-16 22:26:41 +09:00
; ;
esac
fi
; ;
*) bail " unsupported host OS ' ${ host_os } ' " ; ;
esac
call_jq( ) {
# https://github.com/jqlang/jq/issues/1854
if [ [ -n " ${ jq_use_b } " ] ] ; then
" ${ jq :- jq } " -b " $@ "
else
" ${ jq :- jq } " " $@ "
fi
}
2022-12-14 11:24:22 +09:00
2023-01-16 19:56:58 +09:00
unsupported_tools = ( )
2021-12-30 17:33:20 +09:00
for tool in " ${ tools [@] } " ; do
if [ [ " ${ tool } " = = *"@" * ] ] ; then
version = " ${ tool #*@ } "
2023-01-14 00:02:02 +09:00
tool = " ${ tool %@* } "
2022-12-25 00:03:44 +09:00
if [ [ ! " ${ version } " = ~ ^( [ 1-9] [ 0-9] *( \. [ 0-9] +( \. [ 0-9] +) ?) ?| 0\. [ 1-9] [ 0-9] *( \. [ 0-9] +) ?| ^0\. 0\. [ 0-9] +) $| ^latest$ ] ] ; then
2022-12-25 00:33:00 +09:00
if [ [ ! " ${ version } " = ~ ^( [ 1-9] [ 0-9] *( \. [ 0-9] +( \. [ 0-9] +) ?) ?| 0\. [ 1-9] [ 0-9] *( \. [ 0-9] +) ?| ^0\. 0\. [ 0-9] +) ( -[ 0-9A-Za-z\. -] +) ?( \+ [ 0-9A-Za-z\. -] +) ?$| ^latest$ ] ] ; then
2023-01-14 00:02:02 +09:00
bail " install-action does not support semver operators: ' ${ version } ' "
2022-12-25 00:33:00 +09:00
fi
2023-06-10 18:03:24 +09:00
bail " install-action v2 does not support semver pre-release and build-metadata: ' ${ version } '; if you need these supports again, please submit an issue at <https://github.com/taiki-e/install-action> "
2022-12-25 00:03:44 +09:00
fi
2021-12-30 17:33:20 +09:00
else
version = "latest"
fi
2024-03-02 15:24:02 +01:00
installed_bin = ( )
2021-12-30 17:33:20 +09:00
case " ${ tool } " in
2022-08-01 17:23:02 +09:00
protoc)
2023-01-16 19:56:58 +09:00
info " installing ${ tool } @ ${ version } "
2022-12-24 21:49:18 +09:00
read_manifest "protoc" " ${ version } "
2023-02-11 02:31:05 +09:00
read_download_info "protoc" " ${ version } "
2022-12-11 16:22:13 +09:00
# Copying files to /usr/local/include requires sudo, so do not use it.
2023-09-16 22:26:41 +09:00
bin_dir = " ${ install_action_dir } /bin "
include_dir = " ${ install_action_dir } /include "
init_install_action_bin_dir
if [ [ ! -e " ${ include_dir } " ] ] ; then
2022-09-10 20:47:43 +09:00
mkdir -p " ${ include_dir } "
fi
2022-12-14 11:24:22 +09:00
if ! type -P unzip & >/dev/null; then
case " ${ base_distro } " in
2024-04-19 21:35:52 +09:00
debian | fedora | suse | arch | alpine)
2023-07-31 23:09:15 +09:00
echo "::group::Install packages required for installation (unzip)"
sys_install unzip
echo "::endgroup::"
; ;
2022-12-14 11:24:22 +09:00
esac
fi
2022-12-24 21:49:18 +09:00
mkdir -p " ${ tmp_dir } "
2022-08-01 18:07:53 +09:00
(
2022-12-24 21:49:18 +09:00
cd " ${ tmp_dir } "
download_and_checksum " ${ url } " " ${ checksum } "
2023-07-18 23:51:08 +09:00
unzip -q tmp
2022-08-01 18:07:53 +09:00
mv " bin/protoc ${ exe } " " ${ bin_dir } / "
2022-08-01 19:43:41 +09:00
mkdir -p " ${ include_dir } / "
2022-09-10 20:47:43 +09:00
cp -r include/. " ${ include_dir } / "
2022-08-01 19:43:41 +09:00
if [ [ -z " ${ PROTOC :- } " ] ] ; then
2023-09-16 22:26:41 +09:00
_bin_dir = $( canonicalize_windows_path " ${ bin_dir } " )
info " setting PROTOC environment variable to ' ${ _bin_dir } /protoc ${ exe } ' "
echo " PROTOC= ${ _bin_dir } /protoc ${ exe } " >>" ${ GITHUB_ENV } "
2022-08-01 18:07:53 +09:00
fi
)
2022-12-24 21:49:18 +09:00
rm -rf " ${ tmp_dir } "
2024-03-02 15:24:02 +01:00
installed_bin = ( " ${ tool } ${ exe } " )
2021-12-30 17:33:20 +09:00
; ;
2022-01-09 18:23:50 +09:00
valgrind)
2023-01-16 19:56:58 +09:00
info " installing ${ tool } @ ${ version } "
2022-08-01 21:12:54 +09:00
case " ${ version } " in
latest) ; ;
*) warn " specifying the version of ${ tool } is not supported yet by this action " ; ;
esac
2022-12-24 21:49:18 +09:00
case " ${ host_os } " in
linux) ; ;
macos | windows) bail " ${ tool } for non-linux is not supported yet by this action " ; ;
*) bail " unsupported host OS ' ${ host_os } ' for ${ tool } " ; ;
2022-01-09 18:23:50 +09:00
esac
# libc6-dbg is needed to run Valgrind
2022-12-11 16:22:13 +09:00
apt_install libc6-dbg
2022-01-09 18:23:50 +09:00
# Use snap to install the latest Valgrind
# https://snapcraft.io/install/valgrind/ubuntu
2022-12-11 16:22:13 +09:00
snap_install valgrind --classic
2024-03-02 15:24:02 +01:00
installed_bin = ( " ${ tool } ${ exe } " )
2022-01-09 18:23:50 +09:00
; ;
2022-12-24 21:49:18 +09:00
cargo-binstall)
2022-08-01 21:12:54 +09:00
case " ${ version } " in
2022-12-24 21:49:18 +09:00
latest) ; ;
*) warn " specifying the version of ${ tool } is not supported by this action " ; ;
2022-07-25 19:26:13 +09:00
esac
2022-07-26 12:03:09 +09:00
install_cargo_binstall
2022-09-25 16:32:11 +09:00
echo
2022-07-26 12:03:09 +09:00
continue
; ;
2022-06-10 22:28:13 +09:00
*)
2022-12-24 21:49:18 +09:00
# Handle aliases
case " ${ tool } " in
cargo-nextest | nextest) tool = "cargo-nextest" ; ;
esac
# Use cargo-binstall fallback if tool is not available.
if [ [ ! -f " ${ manifest_dir } / ${ tool } .json " ] ] ; then
2023-01-16 19:56:58 +09:00
case " ${ version } " in
latest) unsupported_tools += ( " ${ tool } " ) ; ;
*) unsupported_tools += ( " ${ tool } @ ${ version } " ) ; ;
esac
2022-12-24 21:49:18 +09:00
continue
fi
2023-02-11 02:31:05 +09:00
# Use cargo-binstall fallback if tool is available but the specified version not available.
read_manifest " ${ tool } " " ${ version } "
if [ [ " ${ download_info } " = = "null" ] ] ; then
2023-08-04 21:58:05 +09:00
if [ [ " ${ rust_crate } " = = "null" ] ] ; then
bail " ${ tool } @ ${ version } for ' ${ host_os } ' is not supported "
fi
2023-02-11 02:31:05 +09:00
warn " ${ tool } @ ${ version } for ' ${ host_os } ' is not supported; fallback to cargo-binstall "
case " ${ version } " in
2023-08-04 21:58:05 +09:00
latest) unsupported_tools += ( " ${ rust_crate } " ) ; ;
*) unsupported_tools += ( " ${ rust_crate } @ ${ version } " ) ; ;
2023-02-11 02:31:05 +09:00
esac
continue
fi
2023-01-16 19:56:58 +09:00
info " installing ${ tool } @ ${ version } "
2022-12-24 21:49:18 +09:00
# Pre-install
case " ${ tool } " in
shellcheck)
case " ${ host_os } " in
linux)
if type -P shellcheck & >/dev/null; then
apt_remove -y shellcheck
fi
; ;
esac
; ;
esac
2023-02-11 02:31:05 +09:00
download_from_download_info " ${ tool } " " ${ version } "
2022-06-10 22:28:13 +09:00
; ;
esac
2024-03-02 15:24:02 +01:00
tool_bin_stems = ( )
for tool_bin in " ${ installed_bin [@] } " ; do
tool_bin = $( basename " ${ tool_bin } " )
tool_bin_stem = " ${ tool_bin %.exe } "
2023-09-16 22:26:41 +09:00
installed_at = $( type -P " ${ tool_bin } " || echo "" )
2024-03-02 15:24:02 +01:00
if [ [ -z " ${ installed_at } " ] ] ; then
tool_bin = " ${ tool_bin_stem } "
installed_at = $( type -P " ${ tool_bin } " || echo "" )
fi
if [ [ -n " ${ installed_at } " ] ] ; then
info " ${ tool_bin_stem } installed at ${ installed_at } "
else
warn " ${ tool_bin_stem } should be installed at ${ bin_dir : + " ${ bin_dir } / " } ${ tool_bin } ${ exe } ; but ${ tool_bin } ${ exe } not found in path "
fi
tool_bin_stems += ( " ${ tool_bin_stem } " )
done
for tool_bin_stem in " ${ tool_bin_stems [@] } " ; do
# cargo-udeps 0.1.30 and wasm-pack 0.12.0 do not support --version flag.
case " ${ tool_bin_stem } " in
# biome up to 1.2.2 exits with 1 on both --version and --help flags.
# cargo-machete up to 0.6.0 does not support --version flag.
2024-06-08 14:58:09 +08:00
# wait-for-them 0.4.0 exits with 1 on both --version and --help flags.
biome | cargo-machete | wait-for-them) rx " ${ tool_bin_stem } " --version || true ; ;
2024-03-02 15:24:02 +01:00
# these packages support neither --version nor --help flag.
cargo-careful | wasm-bindgen-test-runner) ; ;
# wasm2es6js does not support --version flag and --help flag doesn't contains version info.
wasm2es6js) ; ;
cargo-*)
case " ${ tool_bin_stem } " in
# cargo-valgrind 2.1.0's --version flag just calls cargo's --version flag
cargo-valgrind) rx " ${ tool_bin_stem } " " ${ tool_bin_stem #cargo- } " --help ; ;
*)
if ! rx " ${ tool_bin_stem } " " ${ tool_bin_stem #cargo- } " --version; then
rx " ${ tool_bin_stem } " " ${ tool_bin_stem #cargo- } " --help
fi
; ;
esac
; ;
*)
if ! rx " ${ tool_bin_stem } " --version; then
rx " ${ tool_bin_stem } " --help
fi
; ;
esac
done
2022-06-10 22:28:13 +09:00
echo
2021-12-30 17:33:20 +09:00
done
2023-01-16 19:56:58 +09:00
if [ [ ${# unsupported_tools [@] } -gt 0 ] ] ; then
2023-09-16 23:11:00 +09:00
IFS = ','
2023-01-16 19:56:58 +09:00
info " install-action does not support ${ unsupported_tools [*] } ; fallback to cargo-binstall "
IFS = $'\n\t'
install_cargo_binstall
# By default, cargo-binstall enforce downloads over secure transports only.
# As a result, http will be disabled, and it will also set
# min tls version to be 1.2
2024-06-02 01:08:59 +09:00
cargo-binstall binstall --force --no-confirm --locked " ${ unsupported_tools [@] } "
if ! type -P cargo >/dev/null; then
_bin_dir = $( canonicalize_windows_path " ${ HOME } /.cargo/bin " )
# TODO: avoid this when already added
info " adding ' ${ _bin_dir } ' to PATH "
echo " ${ _bin_dir } " >>" ${ GITHUB_PATH } "
fi
2023-01-16 19:56:58 +09:00
fi