Skip to content

Commit f010a58

Browse files
committed
Always downgrade the registry protocol to supported versions
Not all version support the new sparse protocol. While old versions ignore the value, 1.66 and other fail due to unstable features. If such a version is detected, always downgrade to the git protocol. This fixes running the action twice with different toolchains. Even if the first install uses something which supports "sparse", the second run can still downgrade it to "git". Closes #12
1 parent 9fa7c33 commit f010a58

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

action.yml

+10-9
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ runs:
8585
if [[ ! -v CARGO_UNSTABLE_SPARSE_REGISTRY ]]; then
8686
echo "CARGO_UNSTABLE_SPARSE_REGISTRY=true" >> $GITHUB_ENV
8787
fi
88+
if [[ ! -v CARGO_REGISTRIES_CRATES_IO_PROTOCOL ]]; then
89+
echo "CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse" >> $GITHUB_ENV
90+
fi
8891
shell: bash
8992
- name: "Install Rust Problem Matcher"
9093
run: echo "::add-matcher::${{ github.action_path }}/rust.json"
@@ -126,17 +129,15 @@ runs:
126129
echo "cachekey=$(echo $DATE$HASH | head -c12)" >> $GITHUB_OUTPUT
127130
shell: bash
128131

129-
# Copied from dtolnay/rust-toolchain and adapted
130-
# https://github.com/dtolnay/rust-toolchain/blob/25dc93b901a87e864900a8aec6c12e9aa794c0c3/action.yml#L100-L108
131-
- name: "Enable cargo sparse registry on stable"
132+
- name: "Downgrade registry access protocol when needed"
132133
run: |
133-
# except on 1.66 and 1.67, on which it is unstable
134-
# Not all 1.68.0-nightly versions support it either
134+
# Not all versions support setting CARGO_REGISTRIES_CRATES_IO_PROTOCOL
135+
# On versions 1.66, 1.67, and 1.68.0-nightly the value "sparse" is still unstable.
135136
# https://github.com/dtolnay/rust-toolchain/pull/69#discussion_r1107268108
136-
if [[ ! -v CARGO_REGISTRIES_CRATES_IO_PROTOCOL ]]; then
137-
if echo "${{steps.versions.outputs.rustc-version}}" | grep --invert --quiet '^rustc \(1\.6[67]\.\|1\.68\.0-nightly\)'; then
138-
echo "CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse" >> $GITHUB_ENV
139-
fi
137+
# If we detect an incompatible value, set it to "git" which is always supported.
138+
if [[ "${{steps.versions.outputs.rustc-version}}" =~ ^rustc\ (1\.6[67]\.|1\.68\.0-nightly) && "${CARGO_REGISTRIES_CRATES_IO_PROTOCOL}" == "sparse" ]]; then
139+
echo "Downgrade cargo registry protocol to git"
140+
echo "CARGO_REGISTRIES_CRATES_IO_PROTOCOL=git" >> $GITHUB_ENV
140141
fi
141142
shell: bash
142143

0 commit comments

Comments
 (0)