Skip to content

fix: handle trailing whitespace in version parsing on Windows#12

Merged
taiki-e merged 1 commit intotaiki-e:mainfrom
Xevion:main
Sep 28, 2025
Merged

fix: handle trailing whitespace in version parsing on Windows#12
taiki-e merged 1 commit intotaiki-e:mainfrom
Xevion:main

Conversation

@Xevion
Copy link
Copy Markdown
Contributor

@Xevion Xevion commented Aug 20, 2025

Problem

The cache-cargo-install-action fails on Windows when installing tools with partial version specifications (e.g., tauri-cli@2), while working correctly on other platforms.

Configuration

- name: Install Tauri CLI
  uses: taiki-e/cache-cargo-install-action@v2
  with:
    tool: tauri-cli@2
    locked: true

Expected Behavior

The action should install the latest stable version of tauri-cli that matches major version 2 (currently 2.8.0), equivalent to running:

cargo install tauri-cli --version '^2.0.0' --locked

Actual Behavior

On Windows runners, the action fails with:

Error: no stable version found for tauri-cli that match with '2.*'; if you want to install a pre-release version, please specify the full version
Workflow Failure Log
Run taiki-e/cache-cargo-install-action@v2
Run bash --noprofile --norc "${GITHUB_ACTION_PATH:?}/pre.sh"
* Host crates.io:443 was resolved.
* IPv6: (none)
* IPv4: 108.138.64.108, 108.138.64.48, 108.138.64.68, 108.138.64.83
*   Trying 108.138.64.108:443...
* schannel: disabled automatic use of client certificate
* ALPN: curl offers http/1.1
* ALPN: server accepted http/1.1
* Connected to crates.io (108.138.64.108) port 443
* using HTTP/1.x
> GET /api/v1/crates/tauri-cli HTTP/1.1
> Host: crates.io
> User-Agent: taiki-e/cache-cargo-install-action (v2)
> Accept: */*

* Request completely sent off
* schannel: remote party requests renegotiation
* schannel: renegotiating SSL/TLS connection
* schannel: SSL/TLS connection renegotiated
< HTTP/1.1 200 OK

{ [14860 bytes data]
* Connection #0 to host crates.io left intact
Error: no stable version found for tauri-cli that match with '2.*'; if you want to install a pre-release version, please specify the full version
Error: Process completed with exit code 1.
[Full Log](https://github.com/Xevion/byte-me/actions/runs/17108689008/job/48524243265)

Root Cause

The version parsing logic in pre.sh doesn't handle trailing carriage return characters (\r) that can appear in JSON responses from the crates.io API on Windows systems. This causes the regex validation to fail when matching version strings.

Solution

  • Strip trailing whitespace using bash parameter expansion (${v%%[[:space:]]}) before regex validation

Testing

No testing was added into this PR directly, but I tested it manually in my own project:

Fixes version parsing failures on Windows caused by trailing carriage
returns (\r) in JSON responses from crates.io API. This prevents
installation failures when using non-semver version specifications
like 'tool@2'.
@Xevion
Copy link
Copy Markdown
Contributor Author

Xevion commented Aug 20, 2025

Edit: It seems to have re-ran and resolved itself, so nevermind.

Unsure what's going on with the CI in this repository; it works fine in my fork (I guess that's how it goes).

CI / test (windows-2025) (push) in Xevion/cache-cargo-install-action

Copy link
Copy Markdown
Owner

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@taiki-e taiki-e merged commit 54a6f44 into taiki-e:main Sep 28, 2025
64 of 66 checks passed
@taiki-e
Copy link
Copy Markdown
Owner

taiki-e commented Sep 28, 2025

Published in 2.3.1.

TBH, I'm not sure why we need this since we're passing the -b flag to jq, but this seems to be working anyway, so it's fine for now. (If we cannot trust -b flag, then it's fine to always call tr -d '\r' for jq on Windows.)

chitoku-k added a commit to chitoku-k/cache-cargo-install-action that referenced this pull request Jan 9, 2026
chitoku-k added a commit to chitoku-k/cache-cargo-install-action that referenced this pull request Jan 9, 2026
taiki-e pushed a commit that referenced this pull request Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants