Add fallback: cargo-install input option to use cargo install for fallback

This commit is contained in:
Taiki Endo
2025-09-08 00:22:36 +09:00
parent f6fe689680
commit 4b930c0a05
5 changed files with 65 additions and 21 deletions

View File

@@ -162,6 +162,37 @@ jobs:
run: cargo-nextest nextest --version && taplo --version run: cargo-nextest nextest --version && taplo --version
shell: sh 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: test-container:
strategy: strategy:
fail-fast: false fail-fast: false

View File

@@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
## [Unreleased] ## [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 `typos-cli` as an alias for `typos`.
- Accept `wasm-bindgen-cli` as an alias for `wasm-bindgen`. - Accept `wasm-bindgen-cli` as an alias for `wasm-bindgen`.

View File

@@ -86,8 +86,9 @@ If you want to ensure that fallback is not used, use `fallback: none`.
with: with:
tool: cargo-hack tool: cargo-hack
# Possible values: # Possible values:
# - none: disable all fallback # - none: disable all fallback options
# - cargo-binstall (default): cargo-binstall (includes quickinstall) # - cargo-binstall (default): use cargo-binstall (includes quickinstall)
# - cargo-install: use `cargo install`
fallback: none fallback: none
``` ```

View File

@@ -11,7 +11,7 @@ inputs:
required: false required: false
default: 'true' default: 'true'
fallback: fallback:
description: Whether to use fallback (none or cargo-binstall) description: Whether to use fallback (none, cargo-binstall, cargo-install)
required: false required: false
default: 'cargo-binstall' default: 'cargo-binstall'

14
main.sh
View File

@@ -459,8 +459,8 @@ esac
fallback="${INPUT_FALLBACK:-}" fallback="${INPUT_FALLBACK:-}"
case "${fallback}" in case "${fallback}" in
none | cargo-binstall) ;; none | cargo-binstall | cargo-install) ;;
*) bail "'fallback' input option must be 'none' or 'cargo-binstall': '${fallback}'" ;; *) bail "'fallback' input option must be 'none', 'cargo-binstall', or 'cargo-install': '${fallback}'" ;;
esac esac
# Refs: https://github.com/rust-lang/rustup/blob/HEAD/rustup-init.sh # Refs: https://github.com/rust-lang/rustup/blob/HEAD/rustup-init.sh
@@ -859,6 +859,8 @@ if [[ ${#unsupported_tools[@]} -gt 0 ]]; then
case "${fallback}" in case "${fallback}" in
none) bail "install-action does not support ${unsupported_tools[*]} (fallback is disabled by 'fallback: none' input option)" ;; none) bail "install-action does not support ${unsupported_tools[*]} (fallback is disabled by 'fallback: none' input option)" ;;
esac esac
case "${fallback}" in
cargo-binstall)
info "install-action does not support ${unsupported_tools[*]}; fallback to cargo-binstall" info "install-action does not support ${unsupported_tools[*]}; fallback to cargo-binstall"
IFS=$'\n\t' IFS=$'\n\t'
install_cargo_binstall install_cargo_binstall
@@ -875,4 +877,12 @@ if [[ ${#unsupported_tools[@]} -gt 0 ]]; then
info "adding '${_bin_dir}' to PATH" info "adding '${_bin_dir}' to PATH"
printf '%s\n' "${_bin_dir}" >>"${GITHUB_PATH}" printf '%s\n' "${_bin_dir}" >>"${GITHUB_PATH}"
fi 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 fi