diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 7b2c0fb2b..09c1421de 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -43,6 +43,9 @@ jobs: - name: Install prerequisites run: bin/check/install_prerequisites.sh + - name: Check Rust version + run: bin/check/rust_version.py 7 + - name: Rustfmt run: bin/check/rustfmt.sh diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index f98500655..315fb230a 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -25,7 +25,7 @@ jobs: run: bin/install_prerequisites_ubuntu.sh - name: Install Rust - run: bin/install_rust_latest.sh + run: bin/install_rust.sh - name: Install Grcov run: bin/install_grcov.sh diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index d2b11b1b2..408c86728 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -29,7 +29,7 @@ jobs: - name: Install run: | bin/install_prerequisites_ubuntu.sh - bin/install_rust_latest.sh + bin/install_rust.sh - name: Build run: | bin/release/release.sh @@ -202,7 +202,7 @@ jobs: - name: Install run: | bin/install_prerequisites_ubuntu.sh - bin/install_rust_latest.sh + bin/install_rust.sh - name: Environment run: bin/environment.sh - name: Build @@ -239,7 +239,7 @@ jobs: with: ref: ${{ inputs.branch }} - name: Install Rust - run: bin/install_rust_latest.sh + run: bin/install_rust.sh - name: Build run: | brew install pkg-config diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 942b72a66..b4d3d2bfc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,7 +27,7 @@ jobs: - name: Install Prerequisites run: bin/install_prerequisites_ubuntu.sh - name: Install Rust - run: bin/install_rust_latest.sh + run: bin/install_rust.sh - name: Build run: | bin/release/release.sh @@ -57,7 +57,7 @@ jobs: - name: Install Prerequisites run: bin/install_prerequisites_ubuntu.sh - name: Install Rust - run: bin/install_rust_latest.sh + run: bin/install_rust.sh - name: Test Prerequisites run: bin/test/test_prerequisites.sh - name: Tests units @@ -96,7 +96,7 @@ jobs: - name: Install Prerequisites run: bin/install_prerequisites_ubuntu.sh - name: Install Rust - run: bin/install_rust_latest.sh + run: bin/install_rust.sh - name: Test Prerequisites run: bin/test/test_prerequisites.sh - name: Tests units @@ -137,7 +137,7 @@ jobs: bin/environment.sh echo "::endgroup::" echo "::group::Install Rust" - bin/install_rust_latest.sh + bin/install_rust.sh echo "::endgroup::" echo "::group::Tests" bin/test/test.sh @@ -171,7 +171,7 @@ jobs: bin/environment.sh echo "::endgroup::" echo "::group::Install Rust" - bin/install_rust_latest.sh + bin/install_rust.sh echo "::endgroup::" echo "::group::Tests" bin/test/test.sh @@ -211,7 +211,7 @@ jobs: bin/environment.sh echo "::endgroup::" echo "::group::Install Rust" - bin/install_rust_latest.sh + bin/install_rust.sh echo "::endgroup::" echo "::group::Tests" bin/test/test.sh @@ -241,7 +241,7 @@ jobs: - name: Environment run: bin/environment.sh - name: Install Rust - run: bin/install_rust_latest.sh + run: bin/install_rust.sh - name: Test Prerequisites run: bin/test/test_prerequisites.sh - name: Tests units diff --git a/bin/check/install_prerequisites.sh b/bin/check/install_prerequisites.sh index 8f8ee52e0..3654d28ee 100755 --- a/bin/check/install_prerequisites.sh +++ b/bin/check/install_prerequisites.sh @@ -1,7 +1,7 @@ #!/bin/bash set -Eeuo pipefail -bin/install_rust_latest.sh +bin/install_rust.sh pip3 install -r bin/requirements-frozen.txt sudo apt update && sudo apt install -y libxml2-utils diff --git a/bin/check/rust_version.py b/bin/check/rust_version.py new file mode 100755 index 000000000..ef84d1f34 --- /dev/null +++ b/bin/check/rust_version.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +import datetime +import json +import os +import requests +import sys + + +def get_latest_release(): + r = requests.get("https://api.github.com/repos/rust-lang/rust/releases") + releases = json.loads(r.text) + latest_release = releases[0] + version = latest_release["tag_name"] + date_str = latest_release["published_at"] + date = datetime.datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%SZ") + return version, date + + +def get_current_version(): + return os.popen("cargo --version").read().split(" ")[1] + + +def main(): + if len(sys.argv) < 2: + print("Usage: rust_version.py NUM_DAYS_BEFORE_ERROR") + sys.exit(1) + num_days_before_error = int(sys.argv[1]) + + latest_version, date = get_latest_release() + current_version = get_current_version() + if latest_version != current_version: + sys.stderr.write( + "Rust version must be updated from %s to the latest version %s\n" + % (current_version, latest_version) + ) + days_before_now = datetime.datetime.now() - date + if days_before_now > datetime.timedelta(days=num_days_before_error): + sys.exit(1) + + +if __name__ == "__main__": + main() diff --git a/bin/install_rust.sh b/bin/install_rust.sh new file mode 100755 index 000000000..3eedd6f4b --- /dev/null +++ b/bin/install_rust.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -Eeuo pipefail + +rust_version=$(grep '^rust-version' packages/hurl/Cargo.toml | cut -f2 -d'"') + +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs >/tmp/rustup.sh +sh /tmp/rustup.sh -y --default-toolchain "$rust_version" +~/.cargo/bin/rustc --version +~/.cargo/bin/cargo --version + diff --git a/bin/install_rust_latest.sh b/bin/install_rust_latest.sh deleted file mode 100755 index 5fffa55c8..000000000 --- a/bin/install_rust_latest.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -set -Eeuo pipefail - -curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh -sh rustup.sh -y -# shellcheck source=/dev/null -PATH="$HOME/.cargo/bin:$PATH" -export PATH -rustc --version -cargo --version - diff --git a/packages/hurl/Cargo.toml b/packages/hurl/Cargo.toml index 62ca968c4..0e60e6cb7 100644 --- a/packages/hurl/Cargo.toml +++ b/packages/hurl/Cargo.toml @@ -8,6 +8,7 @@ description = "Hurl, run and test HTTP requests" documentation = "https://hurl.dev" homepage = "https://hurl.dev" repository = "https://github.com/Orange-OpenSource/hurl" +rust-version = "1.68" [lib] name = "hurl"