Skip to content

Commit 9d73672

Browse files
committed
Fix: Update GitHub Actions workflows to handle Cargo.lock version 4 compatibility
1 parent 9e79c4e commit 9d73672

File tree

4 files changed

+112
-7
lines changed

4 files changed

+112
-7
lines changed

.github/workflows/README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,20 @@ If you encounter Cargo lock file version compatibility issues:
130130
1. The workflow now explicitly updates Cargo to the latest stable version
131131
2. We've added a specific step that runs `rustup update stable` and `rustup default stable`
132132
3. Cargo version is explicitly checked and logged for troubleshooting
133-
4. The workflow automatically regenerates the Cargo.lock file to ensure it uses a format compatible with the current Cargo version
134-
5. This ensures compatibility with Cargo.lock version 4 format (used in newer Rust versions)
135-
6. Any existing Cargo.lock is deleted and freshly regenerated to avoid format conflicts
133+
4. The workflow now intelligently checks if the installed Cargo version is compatible with Cargo.lock version 4:
134+
```bash
135+
CARGO_VERSION=$(cargo --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
136+
MAJOR=$(echo "$CARGO_VERSION" | cut -d'.' -f1)
137+
MINOR=$(echo "$CARGO_VERSION" | cut -d'.' -f2)
138+
if [ "$MAJOR" -lt 1 ] || ([ "$MAJOR" -eq 1 ] && [ "$MINOR" -lt 70 ]); then
139+
# If Cargo is too old, upgrade it again
140+
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable --profile minimal
141+
fi
142+
```
143+
5. The workflow automatically regenerates the Cargo.lock file to ensure it uses a format compatible with the current Cargo version
144+
6. After regeneration, it explicitly verifies the lock file format with `grep -q 'version = 4' Cargo.lock`
145+
7. Any existing Cargo.lock is deleted and freshly regenerated to avoid format conflicts
146+
8. Detailed debugging output is provided if the Cargo.lock generation fails
136147

137148
#### Build Command Not Found
138149

.github/workflows/build.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,27 @@ jobs:
2929

3030
- name: Update Cargo to latest stable
3131
run: |
32+
# Update to the latest stable Rust toolchain
3233
rustup update stable
3334
rustup default stable
3435
# Check Cargo version explicitly
3536
cargo --version
3637
echo "Using Cargo from: $(which cargo)"
3738
# Ensure we can handle Cargo.lock version 4
38-
echo "Cargo can handle lock version: $(cargo --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')"
39+
CARGO_VERSION=$(cargo --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
40+
echo "Cargo version: $CARGO_VERSION"
41+
# Check if Cargo version is new enough for lock file version 4
42+
MAJOR=$(echo "$CARGO_VERSION" | cut -d'.' -f1)
43+
MINOR=$(echo "$CARGO_VERSION" | cut -d'.' -f2)
44+
if [ "$MAJOR" -lt 1 ] || ([ "$MAJOR" -eq 1 ] && [ "$MINOR" -lt 70 ]); then
45+
echo "Warning: Cargo version $CARGO_VERSION may not fully support Cargo.lock version 4 format"
46+
echo "Attempting to update Cargo again"
47+
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable --profile minimal
48+
source "$HOME/.cargo/env"
49+
cargo --version
50+
else
51+
echo "Cargo $CARGO_VERSION supports Cargo.lock version 4 format"
52+
fi
3953
4054
- name: Regenerate Cargo.lock
4155
run: |
@@ -48,6 +62,22 @@ jobs:
4862
echo "Regenerating Cargo.lock"
4963
cargo generate-lockfile
5064
echo "Cargo.lock regenerated successfully"
65+
66+
# Verify the Cargo.lock format
67+
if [ -f Cargo.lock ]; then
68+
echo "Checking Cargo.lock format..."
69+
# Quick check to see if it's a version 4 format (contains version = 4)
70+
if grep -q 'version = 4' Cargo.lock; then
71+
echo "Confirmed: Cargo.lock is using version 4 format"
72+
else
73+
echo "Warning: Cargo.lock may not be using version 4 format"
74+
# For debugging purposes, show the first few lines
75+
head -5 Cargo.lock
76+
fi
77+
else
78+
echo "Error: Cargo.lock was not generated!"
79+
exit 1
80+
fi
5181
5282
- name: Install Solana CLI
5383
run: |

.github/workflows/tornado_testnet_transaction.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,27 @@ jobs:
7070

7171
- name: Update Cargo to latest stable
7272
run: |
73+
# Update to the latest stable Rust toolchain
7374
rustup update stable
7475
rustup default stable
7576
# Check Cargo version explicitly
7677
cargo --version
7778
echo "Using Cargo from: $(which cargo)"
7879
# Ensure we can handle Cargo.lock version 4
79-
echo "Cargo can handle lock version: $(cargo --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')"
80+
CARGO_VERSION=$(cargo --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
81+
echo "Cargo version: $CARGO_VERSION"
82+
# Check if Cargo version is new enough for lock file version 4
83+
MAJOR=$(echo "$CARGO_VERSION" | cut -d'.' -f1)
84+
MINOR=$(echo "$CARGO_VERSION" | cut -d'.' -f2)
85+
if [ "$MAJOR" -lt 1 ] || ([ "$MAJOR" -eq 1 ] && [ "$MINOR" -lt 70 ]); then
86+
echo "Warning: Cargo version $CARGO_VERSION may not fully support Cargo.lock version 4 format"
87+
echo "Attempting to update Cargo again"
88+
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable --profile minimal
89+
source "$HOME/.cargo/env"
90+
cargo --version
91+
else
92+
echo "Cargo $CARGO_VERSION supports Cargo.lock version 4 format"
93+
fi
8094
8195
- name: Regenerate Cargo.lock
8296
run: |
@@ -89,6 +103,22 @@ jobs:
89103
echo "Regenerating Cargo.lock"
90104
cargo generate-lockfile
91105
echo "Cargo.lock regenerated successfully"
106+
107+
# Verify the Cargo.lock format
108+
if [ -f Cargo.lock ]; then
109+
echo "Checking Cargo.lock format..."
110+
# Quick check to see if it's a version 4 format (contains version = 4)
111+
if grep -q 'version = 4' Cargo.lock; then
112+
echo "Confirmed: Cargo.lock is using version 4 format"
113+
else
114+
echo "Warning: Cargo.lock may not be using version 4 format"
115+
# For debugging purposes, show the first few lines
116+
head -5 Cargo.lock
117+
fi
118+
else
119+
echo "Error: Cargo.lock was not generated!"
120+
exit 1
121+
fi
92122
93123
- name: Setup metrics directory
94124
run: |

docs/github_actions.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,20 @@ If your workflow fails with errors about Cargo.lock version compatibility:
164164
echo "Using Cargo from: $(which cargo)"
165165
```
166166

167-
3. **Automatic regeneration:** The workflow automatically regenerates the Cargo.lock file with the correct format:
167+
3. **Intelligent version checking:** The workflow now determines if the Cargo version is compatible with version 4 lock files:
168+
```bash
169+
CARGO_VERSION=$(cargo --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
170+
MAJOR=$(echo "$CARGO_VERSION" | cut -d'.' -f1)
171+
MINOR=$(echo "$CARGO_VERSION" | cut -d'.' -f2)
172+
if [ "$MAJOR" -lt 1 ] || ([ "$MAJOR" -eq 1 ] && [ "$MINOR" -lt 70 ]); then
173+
# If Cargo is too old, upgrade it again
174+
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable --profile minimal
175+
source "$HOME/.cargo/env"
176+
cargo --version
177+
fi
178+
```
179+
180+
4. **Automatic regeneration:** The workflow automatically regenerates the Cargo.lock file with the correct format:
168181
```bash
169182
# Remove any existing Cargo.lock
170183
if [ -f Cargo.lock ]; then
@@ -174,7 +187,28 @@ If your workflow fails with errors about Cargo.lock version compatibility:
174187
cargo generate-lockfile
175188
```
176189

177-
4. **Compatibility:** These steps ensure compatibility with Cargo.lock version 4 format (used in newer Rust versions)
190+
5. **Format verification:** The workflow now explicitly verifies the generated Cargo.lock format:
191+
```bash
192+
# Verify the Cargo.lock format
193+
if [ -f Cargo.lock ]; then
194+
echo "Checking Cargo.lock format..."
195+
# Quick check to see if it's a version 4 format (contains version = 4)
196+
if grep -q 'version = 4' Cargo.lock; then
197+
echo "Confirmed: Cargo.lock is using version 4 format"
198+
else
199+
echo "Warning: Cargo.lock may not be using version 4 format"
200+
# For debugging purposes, show the first few lines
201+
head -5 Cargo.lock
202+
fi
203+
else
204+
echo "Error: Cargo.lock was not generated!"
205+
exit 1
206+
fi
207+
```
208+
209+
6. **Compatibility:** These steps ensure compatibility with Cargo.lock version 4 format (used in newer Rust versions, typically Cargo ≥ 1.70.0)
210+
211+
7. **Detailed error reporting:** The workflow provides comprehensive diagnostics about the Cargo version and lock file status
178212

179213
#### Solana Build Command Not Found
180214

0 commit comments

Comments
 (0)