Compare commits

...

1 Commits

Author SHA1 Message Date
Taiki Endo
eab2c9a639 dev
TODO:

```
/__w/install-action/install-action/.//main.sh: line 81: syntax error: unexpected "(" (expecting "}")
```
2026-02-14 19:24:16 +09:00
5 changed files with 62 additions and 56 deletions

View File

@@ -2,6 +2,7 @@ almalinux
archlinux archlinux
binstall binstall
callgrind callgrind
Ceuo
coreutils coreutils
cyclonedx cyclonedx
cygdrive cygdrive

View File

@@ -10,6 +10,7 @@ on:
- main - main
- dev - dev
- ci-* - ci-*
- busybox
schedule: schedule:
- cron: '0 0 * * *' - cron: '0 0 * * *'
workflow_dispatch: workflow_dispatch:
@@ -231,17 +232,17 @@ jobs:
- opensuse/leap:latest # glibc 2.38 (as of leap 15.6) - opensuse/leap:latest # glibc 2.38 (as of leap 15.6)
- opensuse/tumbleweed:latest # glibc 2.39 (as of 2024-07-19) - opensuse/tumbleweed:latest # glibc 2.39 (as of 2024-07-19)
- archlinux:latest # glibc 2.39 (as of 2024-07-19) - archlinux:latest # glibc 2.39 (as of 2024-07-19)
- alpine:3.2 # musl 1.1.11 - alpine:3.2 # musl 1.1.11, busybox 1.23.2
- alpine:3.14 # musl 1.2.2 - alpine:3.14 # musl 1.2.2, busybox 1.33.1
- alpine:3.15 # musl 1.2.2 - alpine:3.15 # musl 1.2.2, busybox 1.34.1
- alpine:3.16 # musl 1.2.3 - alpine:3.16 # musl 1.2.3, busybox 1.35.0
- alpine:3.17 # musl 1.2.3 - alpine:3.17 # musl 1.2.3, busybox 1.35.0
- alpine:3.18 # musl 1.2.4 - alpine:3.18 # musl 1.2.4, busybox 1.36.1
- alpine:3.19 # musl 1.2.4 - alpine:3.19 # musl 1.2.4, busybox 1.36.1
- alpine:3.20 # musl 1.2.5 - alpine:3.20 # musl 1.2.5, busybox 1.36.1
- alpine:3.21 # musl 1.2.5 - alpine:3.21 # musl 1.2.5, busybox 1.37.0
- alpine:3.22 # musl 1.2.5 - alpine:3.22 # musl 1.2.5, busybox 1.37.0
- alpine:3.23 # musl 1.2.5 - alpine:3.23 # musl 1.2.5, busybox 1.37.0
# - openwrt/rootfs:x86-64-openwrt-24.10 # musl 1.2.5 # - openwrt/rootfs:x86-64-openwrt-24.10 # musl 1.2.5
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 60 timeout-minutes: 60
@@ -292,6 +293,9 @@ jobs:
tool: ${{ steps.tool-list.outputs.tool }} tool: ${{ steps.tool-list.outputs.tool }}
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: apk --no-cache add bash
shell: sh
if: startsWith(matrix.container, 'alpine')
- name: Test bash - name: Test bash
run: just --version && shfmt --version run: just --version && shfmt --version
shell: bash shell: bash

View File

@@ -118,7 +118,7 @@ On Linux, if any required tools are missing, this action will attempt to install
On other platforms, at least the following tools are required: On other platforms, at least the following tools are required:
- bash 3.2+ - bash 3.2+ (or busybox on Linux)
- jq 1.3+ (only on non-Windows platforms) - jq 1.3+ (only on non-Windows platforms)
- curl 7.34+ (or RHEL7/CentOS7's patched curl 7.29) - curl 7.34+ (or RHEL7/CentOS7's patched curl 7.29)

View File

@@ -21,32 +21,32 @@ inputs:
runs: runs:
using: composite using: composite
steps: steps:
- run: | - name: Prepare
id: prepare
run: |
set -eu set -eu
if ! command -v bash >/dev/null; then if ! command -v bash >/dev/null; then
if grep -Eq '^ID=alpine' /etc/os-release; then if command -v busybox >/dev/null; then
printf '::group::Install packages required for install-action (bash)\n' if test -n "${GITHUB_OUTPUT:-}"; then
# NB: sync with apk_install in main.sh printf 'shell=busybox sh -e {0}\n' >>"${GITHUB_OUTPUT}"
if command -v sudo >/dev/null; then exit
sudo apk --no-cache add bash
elif command -v doas >/dev/null; then
doas apk --no-cache add bash
else
apk --no-cache add bash
fi fi
printf '::endgroup::\n'
else
printf '::error::install-action requires bash\n'
exit 1
fi fi
printf '::error::install-action requires bash or busybox\n'
exit 1
fi fi
shell: sh shell: sh
if: runner.os == 'Linux' if: runner.os == 'Linux'
- run: bash --noprofile --norc "${GITHUB_ACTION_PATH:?}/main.sh" - run: |
shell: bash case "${CURRENT_SHELL}" in
busybox*) busybox sh "${GITHUB_ACTION_PATH:?}/main.sh" ;;
*) bash --noprofile --norc "${GITHUB_ACTION_PATH:?}/main.sh" ;;
esac
shell: ${{ steps.prepare.outputs.shell || 'bash' }}
env: env:
INPUT_TOOL: ${{ inputs.tool }} INPUT_TOOL: ${{ inputs.tool }}
INPUT_CHECKSUM: ${{ inputs.checksum }} INPUT_CHECKSUM: ${{ inputs.checksum }}
INPUT_FALLBACK: ${{ inputs.fallback }} INPUT_FALLBACK: ${{ inputs.fallback }}
DEFAULT_GITHUB_TOKEN: ${{ github.token }} DEFAULT_GITHUB_TOKEN: ${{ github.token }}
ACTION_USER_AGENT: ${{ github.action_repository }} (${{ github.action_ref }}) ACTION_USER_AGENT: ${{ github.action_repository }} (${{ github.action_ref }})
CURRENT_SHELL: ${{ steps.prepare.outputs.shell }}

57
main.sh
View File

@@ -1,6 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# SPDX-License-Identifier: Apache-2.0 OR MIT # SPDX-License-Identifier: Apache-2.0 OR MIT
set -CeEuo pipefail # Do not set -E as busybox 3.15 and older don't support it.
set -Ceuo pipefail
IFS=$'\n\t' IFS=$'\n\t'
rx() { rx() {
@@ -35,11 +36,11 @@ normalize_comma_or_space_separated() {
if [[ "${list}" == *","* ]]; then if [[ "${list}" == *","* ]]; then
# If a comma is contained, consider it is a comma-separated list. # If a comma is contained, consider it is a comma-separated list.
# Drop leading and trailing whitespaces in each element. # Drop leading and trailing whitespaces in each element.
sed -E 's/ *, */,/g; s/^.//' <<<",${list}," printf '%s\n' ",${list}," | sed -E 's/ *, */,/g; s/^.//'
else else
# Otherwise, consider it is a whitespace-separated list. # Otherwise, consider it is a whitespace-separated list.
# Convert whitespace characters into comma. # Convert whitespace characters into comma.
sed -E 's/ +/,/g; s/^.//' <<<" ${list} " printf '%s\n' " ${list} " | sed -E 's/ +/,/g; s/^.//'
fi fi
} }
_sudo() { _sudo() {
@@ -60,11 +61,11 @@ download_and_checksum() {
if [[ -n "${checksum}" ]]; then if [[ -n "${checksum}" ]]; then
info "verifying sha256 checksum for $(basename -- "${url}")" info "verifying sha256 checksum for $(basename -- "${url}")"
if type -P sha256sum >/dev/null; then if type -P sha256sum >/dev/null; then
sha256sum -c - >/dev/null <<<"${checksum} *tmp" printf '%s\n' "${checksum} *tmp" | sha256sum -c - >/dev/null
elif type -P shasum >/dev/null; then elif type -P shasum >/dev/null; then
# GitHub-hosted macOS runner does not install GNU Coreutils by default. # GitHub-hosted macOS runner does not install GNU Coreutils by default.
# https://github.com/actions/runner-images/issues/90 # https://github.com/actions/runner-images/issues/90
shasum -a 256 -c - >/dev/null <<<"${checksum} *tmp" printf '%s\n' "${checksum} *tmp" | shasum -a 256 -c - >/dev/null
else else
bail "checksum requires 'sha256sum' or 'shasum' command; consider installing one of them or setting 'checksum' input option to 'false'" bail "checksum requires 'sha256sum' or 'shasum' command; consider installing one of them or setting 'checksum' input option to 'false'"
fi fi
@@ -224,7 +225,7 @@ read_manifest() {
download_info="null" download_info="null"
return 0 return 0
fi fi
exact_version=$(jq -r '.version' <<<"${manifest}") exact_version=$(printf '%s\n' "${manifest}" | jq -r '.version')
if [[ "${exact_version}" == "null" ]]; then if [[ "${exact_version}" == "null" ]]; then
exact_version="${version}" exact_version="${version}"
else else
@@ -236,11 +237,11 @@ read_manifest() {
crate_info=$(curl -v --user-agent "${ACTION_USER_AGENT}" --proto '=https' --tlsv1.2 -fsSL --retry 10 "https://crates.io/api/v1/crates/${rust_crate}" || true) crate_info=$(curl -v --user-agent "${ACTION_USER_AGENT}" --proto '=https' --tlsv1.2 -fsSL --retry 10 "https://crates.io/api/v1/crates/${rust_crate}" || true)
if [[ -n "${crate_info}" ]]; then if [[ -n "${crate_info}" ]]; then
while true; do while true; do
yanked=$(jq -r ".versions[] | select(.num == \"${exact_version}\") | .yanked" <<<"${crate_info}") yanked=$(printf '%s\n' "${crate_info}" | jq -r ".versions[] | select(.num == \"${exact_version}\") | .yanked")
if [[ "${yanked}" != "true" ]]; then if [[ "${yanked}" != "true" ]]; then
break break
fi fi
previous_stable_version=$(jq -r '.previous_stable_version' <<<"${manifest}") previous_stable_version=$(printf '%s\n' "${manifest}" | jq -r '.previous_stable_version')
if [[ "${previous_stable_version}" == "null" ]]; then if [[ "${previous_stable_version}" == "null" ]]; then
break break
fi fi
@@ -260,26 +261,26 @@ read_manifest() {
# usually preferred over linux-gnu binaries because they can avoid glibc version issues. # 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.) # (rustc enables statically linking for linux-musl by default, except for mips.)
host_platform="${host_arch}_linux_musl" host_platform="${host_arch}_linux_musl"
download_info=$(jq -r ".${host_platform}" <<<"${manifest}") download_info=$(printf '%s\n' "${manifest}" | jq -r ".${host_platform}")
if [[ "${download_info}" == "null" ]]; then if [[ "${download_info}" == "null" ]]; then
# Even if host_env is musl, we won't issue an error here because it seems that in # 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. # some cases linux-gnu binaries will work on linux-musl hosts.
# https://wiki.alpinelinux.org/wiki/Running_glibc_programs # https://wiki.alpinelinux.org/wiki/Running_glibc_programs
# TODO: However, a warning may make sense. # TODO: However, a warning may make sense.
host_platform="${host_arch}_linux_gnu" host_platform="${host_arch}_linux_gnu"
download_info=$(jq -r ".${host_platform}" <<<"${manifest}") download_info=$(printf '%s\n' "${manifest}" | jq -r ".${host_platform}")
elif [[ "${host_env}" == "gnu" ]]; then elif [[ "${host_env}" == "gnu" ]]; then
# TODO: don't hardcode tool name and use 'prefer_linux_gnu' field in base manifest. # TODO: don't hardcode tool name and use 'prefer_linux_gnu' field in base manifest.
case "${tool}" in case "${tool}" in
cargo-nextest) cargo-nextest)
# TODO: don't hardcode required glibc version # TODO: don't hardcode required glibc version
required_glibc_version=2.27 required_glibc_version=2.27
higher_glibc_version=$(LC_ALL=C sort -Vu <<<"${required_glibc_version}"$'\n'"${host_glibc_version}" | tail -1) higher_glibc_version=$(printf '%s\n%s\n' "${required_glibc_version}" "${host_glibc_version}" | LC_ALL=C sort -Vu | tail -1)
if [[ "${higher_glibc_version}" == "${host_glibc_version}" ]]; then if [[ "${higher_glibc_version}" == "${host_glibc_version}" ]]; then
# musl build of nextest is slow, so use glibc build if host_env is gnu. # musl build of nextest is slow, so use glibc build if host_env is gnu.
# https://github.com/taiki-e/install-action/issues/13 # https://github.com/taiki-e/install-action/issues/13
host_platform="${host_arch}_linux_gnu" host_platform="${host_arch}_linux_gnu"
download_info=$(jq -r ".${host_platform}" <<<"${manifest}") download_info=$(printf '%s\n' "${manifest}" | jq -r ".${host_platform}")
fi fi
;; ;;
esac esac
@@ -289,10 +290,10 @@ read_manifest() {
# Binaries compiled for x86_64 macOS will usually also work on AArch64 macOS. # 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+. # Binaries compiled for x86_64 Windows will usually also work on AArch64 Windows 11+.
host_platform="${host_arch}_${host_os}" host_platform="${host_arch}_${host_os}"
download_info=$(jq -r ".${host_platform}" <<<"${manifest}") download_info=$(printf '%s\n' "${manifest}" | jq -r ".${host_platform}")
if [[ "${download_info}" == "null" ]] && [[ "${host_arch}" != "x86_64" ]]; then if [[ "${download_info}" == "null" ]] && [[ "${host_arch}" != "x86_64" ]]; then
host_platform="x86_64_${host_os}" host_platform="x86_64_${host_os}"
download_info=$(jq -r ".${host_platform}" <<<"${manifest}") download_info=$(printf '%s\n' "${manifest}" | jq -r ".${host_platform}")
fi fi
;; ;;
*) bail "unsupported OS type '${host_os}' for ${tool}" ;; *) bail "unsupported OS type '${host_os}' for ${tool}" ;;
@@ -304,25 +305,25 @@ read_download_info() {
if [[ "${download_info}" == "null" ]]; then if [[ "${download_info}" == "null" ]]; then
bail "${tool}@${version} for '${host_os}' is not supported" bail "${tool}@${version} for '${host_os}' is not supported"
fi fi
checksum=$(jq -r '.checksum' <<<"${download_info}") checksum=$(printf '%s\n' "${download_info}" | jq -r '.checksum')
url=$(jq -r '.url' <<<"${download_info}") url=$(printf '%s\n' "${download_info}" | jq -r '.url')
local tmp local tmp
bin_in_archive=() bin_in_archive=()
if [[ "${url}" == "null" ]]; then if [[ "${url}" == "null" ]]; then
local template local template
template=$(jq -c ".template.${host_platform}" "${manifest_dir}/${tool}.json") template=$(jq -c ".template.${host_platform}" "${manifest_dir}/${tool}.json")
template="${template//\$\{version\}/${exact_version}}" template="${template//\$\{version\}/${exact_version}}"
url=$(jq -r '.url' <<<"${template}") url=$(printf '%s\n' "${template}" | jq -r '.url')
tmp=$(jq -r '.bin' <<<"${template}") tmp=$(printf '%s\n' "${template}" | jq -r '.bin')
if [[ "${tmp}" == *"["* ]]; then if [[ "${tmp}" == *"["* ]]; then
# shellcheck disable=SC2207 # shellcheck disable=SC2207
bin_in_archive=($(jq -r '.bin[]' <<<"${template}")) bin_in_archive=($(printf '%s\n' "${template}" | jq -r '.bin[]'))
fi fi
else else
tmp=$(jq -r '.bin' <<<"${download_info}") tmp=$(printf '%s\n' "${download_info}" | jq -r '.bin')
if [[ "${tmp}" == *"["* ]]; then if [[ "${tmp}" == *"["* ]]; then
# shellcheck disable=SC2207 # shellcheck disable=SC2207
bin_in_archive=($(jq -r '.bin[]' <<<"${download_info}")) bin_in_archive=($(printf '%s\n' "${download_info}" | jq -r '.bin[]'))
fi fi
fi fi
if [[ ${#bin_in_archive[@]} -eq 0 ]]; then if [[ ${#bin_in_archive[@]} -eq 0 ]]; then
@@ -431,7 +432,7 @@ init_install_action_bin_dir() {
} }
canonicalize_windows_path() { canonicalize_windows_path() {
case "${host_os}" in case "${host_os}" in
windows) sed -E 's/^\/cygdrive\//\//; s/^\/c\//C:\\/; s/\//\\/g' <<<"$1" ;; windows) printf '%s\n' "$1" | sed -E 's/^\/cygdrive\//\//; s/^\/c\//C:\\/; s/\//\\/g' ;;
*) printf '%s\n' "$1" ;; *) printf '%s\n' "$1" ;;
esac esac
} }
@@ -483,11 +484,11 @@ case "$(uname -s)" in
Linux) Linux)
host_os=linux host_os=linux
ldd_version=$(ldd --version 2>&1 || true) ldd_version=$(ldd --version 2>&1 || true)
if grep -Fq musl <<<"${ldd_version}"; then if printf '%s\n' "${ldd_version}" | grep -Fq musl; then
host_env=musl host_env=musl
else else
host_env=gnu host_env=gnu
host_glibc_version=$(grep -E "GLIBC|GNU libc" <<<"${ldd_version}" | sed -E "s/.* //g") host_glibc_version=$(printf '%s\n' "${ldd_version}" | grep -E "GLIBC|GNU libc" | sed -E "s/.* //g")
fi fi
if [[ -e /etc/os-release ]]; then if [[ -e /etc/os-release ]]; then
if grep -Eq '^ID_LIKE=' /etc/os-release; then if grep -Eq '^ID_LIKE=' /etc/os-release; then
@@ -654,9 +655,9 @@ case "${host_os}" in
jq() { "${install_action_dir}/jq/bin/jq.exe" -b "$@"; } jq() { "${install_action_dir}/jq/bin/jq.exe" -b "$@"; }
elif type -P jq >/dev/null; then elif type -P jq >/dev/null; then
# https://github.com/jqlang/jq/issues/1854 # https://github.com/jqlang/jq/issues/1854
_tmp=$(jq -r .a <<<'{}' | wc -c) _tmp=$(printf '{}\n' | jq -r .a | wc -c)
if [[ "${_tmp}" != 5 ]]; then if [[ "${_tmp}" != 5 ]]; then
_tmp=$({ jq -b -r .a 2>/dev/null <<<'{}' || true; } | wc -c) _tmp=$({ printf '{}\n' | jq -b -r .a 2>/dev/null || true; } | wc -c)
if [[ "${_tmp}" == 5 ]]; then if [[ "${_tmp}" == 5 ]]; then
jq() { command jq -b "$@"; } jq() { command jq -b "$@"; }
else else
@@ -685,8 +686,8 @@ for tool in "${tools[@]}"; do
if [[ "${tool}" == *"@"* ]]; then if [[ "${tool}" == *"@"* ]]; then
version="${tool#*@}" version="${tool#*@}"
tool="${tool%@*}" tool="${tool%@*}"
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\.-]+)?$|^latest$ ]]; then if ! printf '%s\n' "${version}" | grep -Eq '^([1-9][0-9]*(\.[0-9]+(\.[0-9]+)?)?|0\.[1-9][0-9]*(\.[0-9]+)?|^0\.0\.[0-9]+)(-[0-9A-Za-z\.-]+)?$|^latest$'; then
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 if ! printf '%s\n' "${version}" | grep -Eq '^([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
bail "install-action does not support semver operators: '${version}'" bail "install-action does not support semver operators: '${version}'"
fi fi
bail "install-action v2 does not support semver build-metadata: '${version}'; if you need these supports again, please submit an issue at <https://github.com/taiki-e/install-action>" bail "install-action v2 does not support semver build-metadata: '${version}'; if you need these supports again, please submit an issue at <https://github.com/taiki-e/install-action>"