Skip to content

Commit 881d415

Browse files
committed
Simplify cargo install error handling in tool scripts
Removed custom checks for 'already installed' errors in install-tools.ps1 and install-tools.sh. Now, any non-zero exit code from cargo install will cause the script to exit with an error, streamlining error handling. Updated deploy.yml to cache additional Cargo files for improved build performance.
1 parent fb64c63 commit 881d415

File tree

3 files changed

+8
-40
lines changed

3 files changed

+8
-40
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ jobs:
3636
~/.cargo/registry/index/
3737
~/.cargo/registry/cache/
3838
~/.cargo/git/db/
39+
~/.cargo/.crates.toml
40+
~/.cargo/.crates2.json
3941
key: ${{ runner.os }}-cargo-${{ hashFiles('versions.toml') }}
4042
restore-keys: |
4143
${{ runner.os }}-cargo-

scripts/install-tools.ps1

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,12 @@ function Get-MdbookPlugins {
5353
Write-Host "Reading versions from $VersionsFile..." -ForegroundColor Cyan
5454

5555
# Install mdBook
56-
# Note: cargo install doesn't provide separate exit codes for "already installed" vs other errors
57-
# See: https://github.com/rust-lang/cargo/issues/11513
58-
# We check the error message as a workaround until cargo provides a better solution.
5956
$MdbookVersion = Get-ToolVersion -Tool "mdbook"
6057
if ($MdbookVersion) {
6158
Write-Host "`nInstalling mdBook $MdbookVersion..." -ForegroundColor Cyan
62-
$output = cargo install mdbook --version $MdbookVersion 2>&1
59+
cargo install mdbook --version $MdbookVersion
6360
if ($LASTEXITCODE -ne 0) {
64-
# Check for "already installed" error - cargo uses different messages
65-
if ($output -match "(?i)(already exists in destination|is already installed)") {
66-
Write-Host " (already installed)" -ForegroundColor Gray
67-
} else {
68-
Write-Host $output -ForegroundColor Red
69-
exit 1
70-
}
61+
exit 1
7162
}
7263
} else {
7364
Write-Host "Error: Could not find mdbook version in versions.toml" -ForegroundColor Red
@@ -80,15 +71,9 @@ Write-Host "`nInstalling mdBook plugins..." -ForegroundColor Cyan
8071
$plugins = Get-MdbookPlugins
8172
foreach ($plugin in $plugins.GetEnumerator()) {
8273
Write-Host "Installing $($plugin.Key) $($plugin.Value)..." -ForegroundColor Cyan
83-
$output = cargo install $plugin.Key --version $plugin.Value 2>&1
74+
cargo install $plugin.Key --version $plugin.Value
8475
if ($LASTEXITCODE -ne 0) {
85-
# Check for "already installed" error - cargo uses different messages
86-
if ($output -match "(?i)(already exists in destination|is already installed)") {
87-
Write-Host " (already installed)" -ForegroundColor Gray
88-
} else {
89-
Write-Host $output -ForegroundColor Red
90-
exit 1
91-
}
76+
exit 1
9277
}
9378
}
9479

scripts/install-tools.sh

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,10 @@ get_version() {
2929
echo "Reading versions from ${VERSIONS_FILE}..."
3030

3131
# Install mdBook
32-
# Note: cargo install doesn't provide separate exit codes for "already installed" vs other errors
33-
# See: https://github.com/rust-lang/cargo/issues/11513
34-
# We check the error message as a workaround until cargo provides a better solution.
3532
MDBOOK_VERSION=$(get_version "mdbook")
3633
if [ -n "$MDBOOK_VERSION" ]; then
3734
echo "Installing mdBook ${MDBOOK_VERSION}..."
38-
if ! output=$(cargo install mdbook --version "${MDBOOK_VERSION}" 2>&1); then
39-
# Check for "already installed" error - cargo uses different messages
40-
if echo "$output" | grep -qiE "(already exists in destination|is already installed)"; then
41-
echo " (already installed)"
42-
else
43-
echo "$output" >&2
44-
exit 1
45-
fi
46-
fi
35+
cargo install mdbook --version "${MDBOOK_VERSION}"
4736
else
4837
echo "Error: Could not find mdbook version in versions.toml"
4938
exit 1
@@ -59,15 +48,7 @@ while IFS= read -r line; do
5948
plugin="${BASH_REMATCH[1]}"
6049
version="${BASH_REMATCH[2]}"
6150
echo "Installing ${plugin} ${version}..."
62-
if ! output=$(cargo install "${plugin}" --version "${version}" 2>&1); then
63-
# Check for "already installed" error - cargo uses different messages
64-
if echo "$output" | grep -qiE "(already exists in destination|is already installed)"; then
65-
echo " (already installed)"
66-
else
67-
echo "$output" >&2
68-
exit 1
69-
fi
70-
fi
51+
cargo install "${plugin}" --version "${version}"
7152
fi
7253
done < <(
7354
awk '

0 commit comments

Comments
 (0)