From 5d018ee3d220f595ecf68892affd8fe5bac42f58 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Wed, 17 Dec 2025 19:46:38 +0900 Subject: [PATCH] Support whitespace separated list --- .github/workflows/ci.yml | 7 ++++++- README.md | 2 +- main.sh | 18 +++++++++++++++--- tools/ci/tool-list.sh | 30 ++++++++++++++++++++++++++---- 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8bf7217d..6a8275ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -156,7 +156,12 @@ jobs: - uses: ./ with: # NB: Update alias list in tools/publish.rs and case for aliases in main.sh. - tool: nextest,taplo-cli,typos-cli,wasm-bindgen-cli,wasmtime-cli + tool: | + nextest + taplo-cli + typos-cli + wasm-bindgen-cli + wasmtime-cli env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Test bash diff --git a/README.md b/README.md index 1b0bc6b8..72a5cfed 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ GitHub Action for installing development tools (mainly from GitHub Releases). | Name | Required | Description | Type | Default | | ---- | :------: | ----------- | ---- | ------- | -| tool | **✓** | Tools to install (comma-separated list) | String | | +| tool | **✓** | Tools to install (whitespace or comma separated list) | String | | | checksum | | Whether to enable checksums | Boolean | `true` | ### Example workflow diff --git a/main.sh b/main.sh index 1645a396..8e4857a9 100755 --- a/main.sh +++ b/main.sh @@ -29,6 +29,19 @@ warn() { info() { printf >&2 'info: %s\n' "$*" } +normalize_comma_or_space_separated() { + # Normalize whitespace characters into space because it's hard to handle single input contains lines with POSIX sed alone. + local list="${1//[$'\r\n\t']/ }" + if [[ "${list}" == *","* ]]; then + # If a comma is contained, consider it is a comma-separated list. + # Drop leading and trailing whitespaces in each element. + sed -E 's/ *, */,/g; s/^.//' <<<",${list}," + else + # Otherwise, consider it is a whitespace-separated list. + # Convert whitespace characters into comma. + sed -E 's/ +/,/g; s/^.//' <<<" ${list} " + fi +} _sudo() { if type -P sudo >/dev/null; then sudo "$@" @@ -440,9 +453,8 @@ tool="${INPUT_TOOL:-}" tools=() if [[ -n "${tool}" ]]; then while read -rd,; do - t="${REPLY# *}" - tools+=("${t%* }") - done <<<"${tool}," + tools+=("${REPLY}") + done < <(normalize_comma_or_space_separated "${tool}") fi if [[ ${#tools[@]} -eq 0 ]]; then warn "no tool specified; this could be caused by a dependabot bug where @ tags on this action are replaced by @ tags" diff --git a/tools/ci/tool-list.sh b/tools/ci/tool-list.sh index 3dc3dd4b..bad58d25 100755 --- a/tools/ci/tool-list.sh +++ b/tools/ci/tool-list.sh @@ -206,7 +206,29 @@ IFS=$'\n' tools=($(LC_ALL=C sort -u <<<"${tools[*]}")) IFS=$'\n\t' -# TODO: inject random space before/after of tool name for testing https://github.com/taiki-e/install-action/issues/115. -IFS=',' -printf 'tool=%s\n' "${tools[*]}" -IFS=$'\n\t' +comma_sep=$((RANDOM % 2)) +list='' +for tool in "${tools[@]}"; do + if [[ -n "${list}" ]]; then + if [[ "${comma_sep}" == "1" ]]; then + list+=',' + else + case $((RANDOM % 2)) in + 0) list+=' ' ;; + 1) list+=$'\t' ;; + esac + fi + fi + case $((RANDOM % 3)) in + 0) ;; + 1) list+=' ' ;; + 2) list+=$' \t ' ;; + esac + list+="${tool}" + case $((RANDOM % 3)) in + 0) ;; + 1) list+=' ' ;; + 2) list+=$' \t ' ;; + esac +done +printf 'tool=%s\n' "${list}"