Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Add script to update and check nightly version consistency #309

Merged
merged 2 commits into from
May 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Shellcheck
run: |
shellcheck --version
shellcheck ci/*.sh
shellcheck ci/*.sh scripts/toolchain-version

- name: Update nightly
run: |
Expand All @@ -38,3 +38,12 @@ jobs:
if rustup component add clippy rustc-dev; then
cargo clippy --all
fi

version_consistency_check:
name: Toolchain version consistency check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Toolchain version consistency check
run: scripts/toolchain-version -c

49 changes: 49 additions & 0 deletions scripts/toolchain-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

set -eu


NIGHTLY_RE="nightly-[0-9]{4}-[0-9]{2}-[0-9]{2}"

nightly_mentions() {
grep -Eo "$NIGHTLY_RE" "$1" | sort --unique
}

check_versions_match() {
readarray -t versions_readme < <(nightly_mentions README.md)
if [[ "${#versions_readme[@]}" -gt 1 ]]; then
echo "Multiple different nightly versions mentioned in README.md: ${versions_readme[*]}"
exit 1
fi

version_toolchain=$(nightly_mentions rust-toolchain)
if [[ "${versions_readme[0]}" != "${version_toolchain}" ]]; then
echo "Toolchain nightly version does not match README.md: ${version_toolchain} vs. ${versions_readme[0]}"
exit 1
fi
}

update_version_everywhere() {
if ! echo "$1" | grep -Eq "$NIGHTLY_RE"; then
echo "That doesn't look like a nightly version to me: '$1'"
exit 1
fi

sed -i -E -e "s#${NIGHTLY_RE}#$1#g" README.md rust-toolchain
}


while getopts "cu:" opt; do
case $opt in
c)
check_versions_match
;;
u)
update_version_everywhere "$OPTARG"
;;
*)
echo "Usage: $0 [-c | -u <nightly version> ]"
exit 1
;;
esac
done