mirror of
https://github.com/taiki-e/install-action.git
synced 2026-04-22 15:30:31 +00:00
Install packages required for installation if not installed
This commit is contained in:
2
.github/.cspell/project-dictionary.txt
vendored
2
.github/.cspell/project-dictionary.txt
vendored
@@ -1,5 +1,7 @@
|
|||||||
binstall
|
binstall
|
||||||
bytecodealliance
|
bytecodealliance
|
||||||
|
distro
|
||||||
|
doas
|
||||||
Dpkg
|
Dpkg
|
||||||
jfrimmel
|
jfrimmel
|
||||||
koalaman
|
koalaman
|
||||||
|
|||||||
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@@ -75,10 +75,10 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
set -ex
|
set -ex
|
||||||
apt-get -o Acquire::Retries=10 -qq update
|
apt-get -o Acquire::Retries=10 -qq update
|
||||||
apt-get -o Acquire::Retries=10 -qq -o Dpkg::Use-Pty=0 install -y --no-install-recommends ca-certificates cargo curl unzip xz-utils
|
apt-get -o Acquire::Retries=10 -qq -o Dpkg::Use-Pty=0 install -y --no-install-recommends cargo
|
||||||
if: startsWith(matrix.container, 'ubuntu') || startsWith(matrix.container, 'debian')
|
if: startsWith(matrix.container, 'ubuntu') || startsWith(matrix.container, 'debian')
|
||||||
- name: Install requirements (alpine)
|
- name: Install requirements (alpine)
|
||||||
run: apk add bash cargo curl tar xz
|
run: apk add bash cargo
|
||||||
shell: sh
|
shell: sh
|
||||||
if: startsWith(matrix.container, 'alpine')
|
if: startsWith(matrix.container, 'alpine')
|
||||||
- uses: ./
|
- uses: ./
|
||||||
|
|||||||
@@ -10,6 +10,12 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
- If the host environment lacks packages required for installation, such as `curl` or `tar`, install them if possible.
|
||||||
|
|
||||||
|
It is mainly intended to make the use of this action easy on containers or self-hosted runners, and currently supports Debian-based distributions (including Ubuntu) and Alpine.
|
||||||
|
|
||||||
|
The system's package manager is used for these installations. However, bash, which is an execution requirement of the action itself, and rustc, which is usually preferred for installation by rustup rather than the system's package manager, are *not* covered by these installations.
|
||||||
|
|
||||||
## [1.15.5] - 2022-12-13
|
## [1.15.5] - 2022-12-13
|
||||||
|
|
||||||
- Update `shellcheck@latest` to 0.9.0.
|
- Update `shellcheck@latest` to 0.9.0.
|
||||||
|
|||||||
65
main.sh
65
main.sh
@@ -47,9 +47,29 @@ download() {
|
|||||||
local tar_args=()
|
local tar_args=()
|
||||||
case "${url}" in
|
case "${url}" in
|
||||||
*.tar.gz | *.tgz) tar_args+=("xzf") ;;
|
*.tar.gz | *.tgz) tar_args+=("xzf") ;;
|
||||||
*.tar.bz2 | *.tbz2) tar_args+=("xjf") ;;
|
*.tar.bz2 | *.tbz2)
|
||||||
*.tar.xz | *.txz) tar_args+=("xJf") ;;
|
tar_args+=("xjf")
|
||||||
|
if ! type -P bzip2 &>/dev/null; then
|
||||||
|
case "${base_distro}" in
|
||||||
|
debian | alpine) sys_install bzip2 ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*.tar.xz | *.txz)
|
||||||
|
tar_args+=("xJf")
|
||||||
|
if ! type -P xz &>/dev/null; then
|
||||||
|
case "${base_distro}" in
|
||||||
|
debian) sys_install xz-utils ;;
|
||||||
|
alpine) sys_install xz ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
;;
|
||||||
*.zip)
|
*.zip)
|
||||||
|
if ! type -P unzip &>/dev/null; then
|
||||||
|
case "${base_distro}" in
|
||||||
|
debian | alpine) sys_install unzip ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
mkdir -p .install-action-tmp
|
mkdir -p .install-action-tmp
|
||||||
(
|
(
|
||||||
cd .install-action-tmp
|
cd .install-action-tmp
|
||||||
@@ -133,8 +153,12 @@ apt_update() {
|
|||||||
else
|
else
|
||||||
retry apt-get -o Acquire::Retries=10 -qq update
|
retry apt-get -o Acquire::Retries=10 -qq update
|
||||||
fi
|
fi
|
||||||
|
apt_updated=1
|
||||||
}
|
}
|
||||||
apt_install() {
|
apt_install() {
|
||||||
|
if [[ -z "${apt_updated:-}" ]]; then
|
||||||
|
apt_update
|
||||||
|
fi
|
||||||
if type -P sudo &>/dev/null; then
|
if type -P sudo &>/dev/null; then
|
||||||
retry sudo apt-get -o Acquire::Retries=10 -qq -o Dpkg::Use-Pty=0 install -y --no-install-recommends "$@"
|
retry sudo apt-get -o Acquire::Retries=10 -qq -o Dpkg::Use-Pty=0 install -y --no-install-recommends "$@"
|
||||||
else
|
else
|
||||||
@@ -155,6 +179,19 @@ snap_install() {
|
|||||||
retry snap install "$@"
|
retry snap install "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
apk_install() {
|
||||||
|
if type -P doas &>/dev/null; then
|
||||||
|
doas apk add "$@"
|
||||||
|
else
|
||||||
|
apk add "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
sys_install() {
|
||||||
|
case "${base_distro}" in
|
||||||
|
debian) apt_install "$@" ;;
|
||||||
|
alpine) apk_install "$@" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
if [[ $# -gt 0 ]]; then
|
if [[ $# -gt 0 ]]; then
|
||||||
bail "invalid argument '$1'"
|
bail "invalid argument '$1'"
|
||||||
@@ -169,17 +206,21 @@ if [[ -n "${tool}" ]]; then
|
|||||||
while read -rd,; do tools+=("${REPLY}"); done <<<"${tool},"
|
while read -rd,; do tools+=("${REPLY}"); done <<<"${tool},"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Refs: https://github.com/rust-lang/rustup/blob/HEAD/rustup-init.sh
|
base_distro=""
|
||||||
|
exe=""
|
||||||
case "${OSTYPE}" in
|
case "${OSTYPE}" in
|
||||||
linux*)
|
linux*)
|
||||||
host_env="gnu"
|
host_env="gnu"
|
||||||
|
# Refs: https://github.com/rust-lang/rustup/blob/HEAD/rustup-init.sh
|
||||||
if (ldd --version 2>&1 || true) | grep -q 'musl'; then
|
if (ldd --version 2>&1 || true) | grep -q 'musl'; then
|
||||||
host_env="musl"
|
host_env="musl"
|
||||||
fi
|
fi
|
||||||
|
if grep -q '^ID_LIKE=' /etc/os-release; then
|
||||||
|
base_distro="$(grep '^ID_LIKE=' /etc/os-release | sed 's/^ID_LIKE=//')"
|
||||||
|
else
|
||||||
|
base_distro="$(grep '^ID=' /etc/os-release | sed 's/^ID=//')"
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
|
||||||
exe=""
|
|
||||||
case "${OSTYPE}" in
|
|
||||||
cygwin* | msys*) exe=".exe" ;;
|
cygwin* | msys*) exe=".exe" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@@ -188,6 +229,12 @@ if [[ ! -d "${cargo_bin}" ]]; then
|
|||||||
cargo_bin=/usr/local/bin
|
cargo_bin=/usr/local/bin
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! type -P curl &>/dev/null || ! type -P tar &>/dev/null; then
|
||||||
|
case "${base_distro}" in
|
||||||
|
debian | alpine) sys_install ca-certificates curl tar ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
for tool in "${tools[@]}"; do
|
for tool in "${tools[@]}"; do
|
||||||
if [[ "${tool}" == *"@"* ]]; then
|
if [[ "${tool}" == *"@"* ]]; then
|
||||||
version="${tool#*@}"
|
version="${tool#*@}"
|
||||||
@@ -354,6 +401,11 @@ for tool in "${tools[@]}"; do
|
|||||||
cygwin* | msys*) url="${base_url}-win64.zip" ;;
|
cygwin* | msys*) url="${base_url}-win64.zip" ;;
|
||||||
*) bail "unsupported OSTYPE '${OSTYPE}' for ${tool}" ;;
|
*) bail "unsupported OSTYPE '${OSTYPE}' for ${tool}" ;;
|
||||||
esac
|
esac
|
||||||
|
if ! type -P unzip &>/dev/null; then
|
||||||
|
case "${base_distro}" in
|
||||||
|
debian | alpine) sys_install unzip ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
mkdir -p .install-action-tmp
|
mkdir -p .install-action-tmp
|
||||||
(
|
(
|
||||||
cd .install-action-tmp
|
cd .install-action-tmp
|
||||||
@@ -437,7 +489,6 @@ for tool in "${tools[@]}"; do
|
|||||||
darwin* | cygwin* | msys*) bail "${tool} for non-linux is not supported yet by this action" ;;
|
darwin* | cygwin* | msys*) bail "${tool} for non-linux is not supported yet by this action" ;;
|
||||||
*) bail "unsupported OSTYPE '${OSTYPE}' for ${tool}" ;;
|
*) bail "unsupported OSTYPE '${OSTYPE}' for ${tool}" ;;
|
||||||
esac
|
esac
|
||||||
apt_update
|
|
||||||
# libc6-dbg is needed to run Valgrind
|
# libc6-dbg is needed to run Valgrind
|
||||||
apt_install libc6-dbg
|
apt_install libc6-dbg
|
||||||
# Use snap to install the latest Valgrind
|
# Use snap to install the latest Valgrind
|
||||||
|
|||||||
Reference in New Issue
Block a user