Refactor the date logic for nightly rust in CI
@@ -16,30 +16,25 @@ sudo chown -R buildkite-agent /home/buildkite-agent
# and we need to automatically fall back to a version that does include it.
# Note that we begin with 1 day ago, since nightly packages can sometimes not
# exist when this script runs if we leave it at 0.
-date_count=1
max_days=90
-while true
+for days_ago in $(seq 1 1 $max_days)
do
- date=$(date -d "$date_count days ago" +%Y-%m-%d)
+ date=$(date -d "$days_ago days ago" +%Y-%m-%d)
toolchain="nightly-$date"
echo "Installing rust $toolchain"
sudo -E $rustup toolchain install "$toolchain"
if sudo -E $rustup component add --toolchain "$toolchain" rustfmt; then
- echo "Rust $toolchain has rustfmt. Excellent!"
- break
+ cargo_fmt="$rustup run $toolchain cargo fmt --all -- --check"
+ echo "Running cargo fmt command: $cargo_fmt"
+ $cargo_fmt
+ exit
else
- date_count=$((date_count + 1))
- echo "Rust $toolchain did not include rustfmt. Let's try $date_count day(s) ago."
+ next_days=$((days_ago + 1))
+ echo "Rust $toolchain did not include rustfmt. Let's try $next_days day(s) ago."
fi
+done
- if [ "$date_count" -eq "$max_days" ]; then
echo "We couldn't find a release of nightly rust in the past $max_days days that includes rustfmt. Giving up entirely."
exit 1
- fi
-done
-
-cargo_fmt="$rustup run $toolchain cargo fmt --all -- --check"
-echo "Running cargo fmt command: $cargo_fmt"
-$cargo_fmt
