Skip to content

Commit 5c8c636

Browse files
committed
fix: resolve latest before cache check to avoid stale cargo-rail reuse
1 parent 21dfd81 commit 5c8c636

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
4343
| Input | Default | Description |
4444
|---|---|---|
45-
| `version` | `latest` | `cargo-rail` version to install |
45+
| `version` | `latest` | `cargo-rail` version to install (`latest` resolves to the newest GitHub release tag each run) |
4646
| `checksum` | `required` | `required`, `if-available`, or `off` |
4747
| `since` | auto | Git ref for planner comparison |
4848
| `args` | `""` | Extra planner args (see below) |
@@ -135,7 +135,7 @@ The action tries installation methods in this order:
135135

136136
1. **Cached binary** (fastest) — uses GitHub Actions cache (`actions/cache`)
137137
- Why: Subsequent runs on same runner are instant (no download)
138-
- Cache key includes version + platform, auto-invalidates on version change
138+
- Cache reuse requires exact version match; when `version: latest`, the action resolves latest first, then compares
139139

140140
2. **Release binary** (fast) — downloads from GitHub Releases
141141
- Why: Pre-built binaries for all supported platforms, verified against `SHA256SUMS`

action.yaml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,22 @@ runs:
160160
run: |
161161
set -euo pipefail
162162
163-
# Check if already installed and meets version requirement
163+
# Resolve version (latest -> actual version number)
164+
VERSION="$REQUESTED_VERSION"
165+
if [[ "$VERSION" == "latest" ]]; then
166+
RESOLVED_VERSION=$(gh api repos/loadingalias/cargo-rail/releases/latest --jq '.tag_name' 2>/dev/null | sed 's/^v//' || true)
167+
if [[ -n "$RESOLVED_VERSION" ]]; then
168+
VERSION="$RESOLVED_VERSION"
169+
else
170+
echo "::warning::Could not determine latest version from GitHub API"
171+
VERSION="latest"
172+
fi
173+
fi
174+
175+
# Check if already installed and matches resolved version requirement
164176
if command -v cargo-rail &>/dev/null; then
165177
INSTALLED_VERSION=$(cargo-rail rail --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || echo "unknown")
166-
if [[ "$REQUESTED_VERSION" == "latest" || "$INSTALLED_VERSION" == "$REQUESTED_VERSION" ]]; then
178+
if [[ "$VERSION" != "latest" && "$INSTALLED_VERSION" == "$VERSION" ]]; then
167179
echo "cargo-rail $INSTALLED_VERSION already installed"
168180
echo "method=cached" >> "$GITHUB_OUTPUT"
169181
echo "version=$INSTALLED_VERSION" >> "$GITHUB_OUTPUT"
@@ -188,15 +200,6 @@ runs:
188200
;;
189201
esac
190202
191-
# Resolve version (latest -> actual version number)
192-
VERSION="$REQUESTED_VERSION"
193-
if [[ "$VERSION" == "latest" ]]; then
194-
VERSION=$(gh api repos/loadingalias/cargo-rail/releases/latest --jq '.tag_name' 2>/dev/null | sed 's/^v//' || echo "")
195-
if [[ -z "$VERSION" ]]; then
196-
echo "::warning::Could not determine latest version from GitHub API"
197-
fi
198-
fi
199-
200203
# Fast path: Pre-built binary download
201204
if [[ -n "$TARGET" && -n "$VERSION" ]]; then
202205
echo "Attempting binary download: cargo-rail v$VERSION for $TARGET"

0 commit comments

Comments
 (0)