From 4b930c0a0520e9f837610565442af3afbce79689 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Mon, 8 Sep 2025 00:22:36 +0900 Subject: [PATCH] Add `fallback: cargo-install` input option to use `cargo install` for fallback --- .github/workflows/ci.yml | 31 +++++++++++++++++++++++++++ CHANGELOG.md | 2 ++ README.md | 5 +++-- action.yml | 2 +- main.sh | 46 ++++++++++++++++++++++++---------------- 5 files changed, 65 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b120fe42..1c13ccaf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -162,6 +162,37 @@ jobs: run: cargo-nextest nextest --version && taplo --version shell: sh + test-fallback: + strategy: + fail-fast: false + matrix: + fallback: + - none + - cargo-install + runs-on: ubuntu-24.04-arm + timeout-minutes: 60 + steps: + - uses: taiki-e/checkout-action@v1 + # cross attempts to install rust-src when Cargo.toml is available even if `cross --version` + - run: rm -- Cargo.toml + - run: env + - uses: ./ + id: install + continue-on-error: ${{ matrix.fallback == 'none' }} + with: + tool: parse-changelog@0.4.6 + fallback: ${{ matrix.fallback }} + - run: exit 1 + if: matrix.fallback == 'none' && steps.install.outcome != 'failure' + - name: Test bash + run: parse-changelog --version + shell: bash + if: matrix.fallback != 'none' + - name: Test sh + run: parse-changelog --version + shell: sh + if: matrix.fallback != 'none' + test-container: strategy: fail-fast: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 9957a832..92365cf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com ## [Unreleased] +- Add `fallback: cargo-install` input option to use `cargo install` instead of `cargo-binstall` for fallback. + - Accept `typos-cli` as an alias for `typos`. - Accept `wasm-bindgen-cli` as an alias for `wasm-bindgen`. diff --git a/README.md b/README.md index 5fc0a18e..36a1788b 100644 --- a/README.md +++ b/README.md @@ -86,8 +86,9 @@ If you want to ensure that fallback is not used, use `fallback: none`. with: tool: cargo-hack # Possible values: - # - none: disable all fallback - # - cargo-binstall (default): cargo-binstall (includes quickinstall) + # - none: disable all fallback options + # - cargo-binstall (default): use cargo-binstall (includes quickinstall) + # - cargo-install: use `cargo install` fallback: none ``` diff --git a/action.yml b/action.yml index 1961a958..98cadc33 100644 --- a/action.yml +++ b/action.yml @@ -11,7 +11,7 @@ inputs: required: false default: 'true' fallback: - description: Whether to use fallback (none or cargo-binstall) + description: Whether to use fallback (none, cargo-binstall, cargo-install) required: false default: 'cargo-binstall' diff --git a/main.sh b/main.sh index 9ceeb68d..abaa6ee3 100755 --- a/main.sh +++ b/main.sh @@ -459,8 +459,8 @@ esac fallback="${INPUT_FALLBACK:-}" case "${fallback}" in - none | cargo-binstall) ;; - *) bail "'fallback' input option must be 'none' or 'cargo-binstall': '${fallback}'" ;; + none | cargo-binstall | cargo-install) ;; + *) bail "'fallback' input option must be 'none', 'cargo-binstall', or 'cargo-install': '${fallback}'" ;; esac # Refs: https://github.com/rust-lang/rustup/blob/HEAD/rustup-init.sh @@ -859,20 +859,30 @@ if [[ ${#unsupported_tools[@]} -gt 0 ]]; then case "${fallback}" in none) bail "install-action does not support ${unsupported_tools[*]} (fallback is disabled by 'fallback: none' input option)" ;; esac - info "install-action does not support ${unsupported_tools[*]}; fallback to cargo-binstall" - IFS=$'\n\t' - install_cargo_binstall - if [[ -z "${GITHUB_TOKEN:-}" ]] && [[ -n "${DEFAULT_GITHUB_TOKEN:-}" ]]; then - export GITHUB_TOKEN="${DEFAULT_GITHUB_TOKEN}" - fi - # 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 - 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" - printf '%s\n' "${_bin_dir}" >>"${GITHUB_PATH}" - fi + case "${fallback}" in + cargo-binstall) + info "install-action does not support ${unsupported_tools[*]}; fallback to cargo-binstall" + IFS=$'\n\t' + install_cargo_binstall + if [[ -z "${GITHUB_TOKEN:-}" ]] && [[ -n "${DEFAULT_GITHUB_TOKEN:-}" ]]; then + export GITHUB_TOKEN="${DEFAULT_GITHUB_TOKEN}" + fi + # 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 + 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" + printf '%s\n' "${_bin_dir}" >>"${GITHUB_PATH}" + fi + ;; + cargo-install) + info "install-action does not support ${unsupported_tools[*]}; fallback to cargo-install" + IFS=$'\n\t' + cargo install --locked "${unsupported_tools[@]}" + ;; + *) bail "unhandled fallback ${fallback}" ;; + esac fi